From 8e08a53d30fa3c74f3074d5b26b9b9d7a3dcb64b Mon Sep 17 00:00:00 2001 From: Jeena Date: Mon, 9 Mar 2026 07:49:59 +0000 Subject: [PATCH] test(US-04): add failing tests for BPM interval calculation and volume clamping --- .../net/jeena/pacer/BpmCalculatorTest.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 app/src/test/kotlin/net/jeena/pacer/BpmCalculatorTest.kt diff --git a/app/src/test/kotlin/net/jeena/pacer/BpmCalculatorTest.kt b/app/src/test/kotlin/net/jeena/pacer/BpmCalculatorTest.kt new file mode 100644 index 0000000..89ececb --- /dev/null +++ b/app/src/test/kotlin/net/jeena/pacer/BpmCalculatorTest.kt @@ -0,0 +1,42 @@ +package net.jeena.pacer + +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +class BpmCalculatorTest { + + @Test + fun `intervalMs returns 1000ms for 60 BPM`() { + assertEquals(1000L, BpmCalculator.intervalMs(60)) + } + + @Test + fun `intervalMs returns 500ms for 120 BPM`() { + assertEquals(500L, BpmCalculator.intervalMs(120)) + } + + @Test + fun `intervalMs returns correct value for 130 BPM`() { + // 60000 / 130 = 461ms + assertEquals(461L, BpmCalculator.intervalMs(130)) + } + + @Test + fun `intervalMs returns correct value for 80 BPM`() { + assertEquals(750L, BpmCalculator.intervalMs(80)) + } + + @Test + fun `clampVolume keeps value within 0 to 1`() { + assertEquals(0f, BpmCalculator.clampVolume(-0.5f)) + assertEquals(1f, BpmCalculator.clampVolume(1.5f)) + assertEquals(0.7f, BpmCalculator.clampVolume(0.7f)) + } + + @Test + fun `intervalMs decreases as BPM increases`() { + assertTrue(BpmCalculator.intervalMs(60) > BpmCalculator.intervalMs(120)) + assertTrue(BpmCalculator.intervalMs(120) > BpmCalculator.intervalMs(180)) + } +}