whiskers.git / android / app / src / test / kotlin / app / whiskers / ParentGateTest.kt
ParentGateTest.kt32 lines · 864 B · raw
1package app.whiskers
2
3import kotlin.random.Random
4import org.junit.Assert.assertEquals
5import org.junit.Assert.assertFalse
6import org.junit.Assert.assertTrue
7import org.junit.Test
8
9class ParentGateTest {
10    @Test fun theRightAnswerOpensAndOnlyThat() {
11        val q = GateQuestion(14, 6)
12        assertTrue(q.accepts("84"))
13        assertFalse(q.accepts("48"))
14        assertFalse(q.accepts(""))
15        assertFalse(q.accepts("84x"))
16    }
17
18    @Test fun everyQuestionIsBeyondASixYearOldsTimesTables() {
19        val r = Random(1)
20        repeat(500) {
21            val q = GateQuestion.random(r)
22            assertTrue(q.a in 12..19 && q.b in 6..9)
23            assertTrue(q.answer >= 72)
24        }
25    }
26
27    @Test fun typingStopsAtFourDigits() {
28        var typed = ""
29        repeat(6) { typed = typeDigit(typed, 7) }
30        assertEquals("7777", typed)
31    }
32}