-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameTest.kt
90 lines (72 loc) · 1.79 KB
/
GameTest.kt
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.example.bowlingkatagame
import org.junit.Assert
import org.junit.Before
import org.junit.Test
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class GameTest {
private lateinit var game: Game
@Before
fun setUp(){
game = Game()
}
@Test
fun `Test gutter game`(){
rollMultiplesBall(20, 0)
Assert.assertEquals(0, 0)
}
@Test
fun `getScore return the score`() {
rollMultiplesBall(20, 1)
Assert.assertEquals(20, game.getScore())
}
@Test
fun `test that spare is counted`() {
rollSpare()
game.rollBall(4)
rollMultiplesBall(17, 0)
Assert.assertEquals(18, game.getScore())
}
@Test
fun `test that strike is counted`() {
rollStrike()
game.rollBall(6)
game.rollBall(2)
rollMultiplesBall(17, 0)
Assert.assertEquals(26, game.getScore())
}
@Test
fun `test perfect game`() {
rollMultiplesBall(20, 10)
Assert.assertEquals(300, game.getScore())
}
@Test
fun `test strike in last frame`() {
rollMultiplesBall(18, 1)
rollStrike()
game.rollBall(6)
Assert.assertEquals(34, game.getScore())
}
@Test
fun `test spare in last frame`() {
rollMultiplesBall(18, 1)
rollSpare()
game.rollBall(6)
Assert.assertEquals(34, game.getScore())
}
private fun rollMultiplesBall(times: Int, pins: Int ) {
for( index in 0 until times) {
game.rollBall(pins)
}
}
private fun rollSpare() {
game.rollBall(7)
game.rollBall(3)
}
private fun rollStrike() {
game.rollBall(10)
}
}