blob: 2ee24213f5bbf94d2becafd40bb39bd29de6e6a1 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
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<Long, Penalty>? = null
t.onFinish = { ms, p -> result = ms to p }
t.press(0); t.tick(500); t.release(600)
assertIs<State.Inspecting>(t.state)
t.press(15_500); t.tick(15_700)
assertIs<State.Holding>(t.state)
t.tick(15_850)
assertIs<State.Ready>(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<State.Stopped>(t.state)
t.release(26_200); t.press(27_000)
assertIs<State.Holding>(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<State.Running>(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)
}
}
|