package coffee.liz.rookery import coffee.liz.rookery.model.Penalty import coffee.liz.rookery.timer.TimerMachine import coffee.liz.rookery.timer.TimerMachine.State import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertIs class TimerTest { @Test fun inspectionFlowWithPlusTwo() { val t = TimerMachine(inspection = true) var result: Pair? = null t.onFinish = { ms, p -> result = ms to p } t.press(0); t.tick(500); t.release(600) assertIs(t.state) t.press(15_500); t.tick(15_700) assertIs(t.state) t.tick(15_850) assertIs(t.state) t.release(16_000) assertEquals(State.Running(16_000, Penalty.PLUS2), t.state) t.press(26_000) assertEquals(10_000L to Penalty.PLUS2, result) t.press(26_100) // still holding the stop key: nothing happens assertIs(t.state) t.release(26_200); t.press(27_000) assertIs(t.state) } @Test fun releasingEarlyDoesNotStart() { val t = TimerMachine(inspection = false) t.press(0); t.tick(100); t.release(150) assertEquals(State.Idle, t.state) t.press(200); t.tick(600); t.release(700) assertIs(t.state) } @Test fun overInspectionIsDnf() { val t = TimerMachine(inspection = true) var p: Penalty? = null t.onFinish = { _, pen -> p = pen } t.press(0); t.release(10); t.tick(17_100) assertEquals(Penalty.DNF, p) } }