1
- import org.junit.jupiter.api.assertThrows
1
+ import org.junit.Ignore
2
+ import org.junit.Rule
3
+ import org.junit.rules.ExpectedException
2
4
import kotlin.test.Test
3
5
import kotlin.test.assertEquals
4
6
5
7
class BowlingGameTest {
8
+
9
+ @Rule
10
+ @JvmField
11
+ var expectedException: ExpectedException = ExpectedException .none()
12
+
6
13
private fun playGame (rolls : IntArray ): BowlingGame {
7
14
val game = BowlingGame ()
8
15
rolls.forEach {
@@ -18,197 +25,227 @@ class BowlingGameTest {
18
25
}
19
26
20
27
@Test
28
+ @Ignore
21
29
fun `should be able to score a game with no strike or spares` () {
22
30
val game = playGame(intArrayOf(3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 , 3 , 6 ))
23
31
assertEquals(90 , game.score())
24
32
}
25
33
26
34
@Test
35
+ @Ignore
27
36
fun `a spare followed by zeros is worth ten points` () {
28
37
val game = playGame(intArrayOf(6 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
29
38
assertEquals(10 , game.score())
30
39
}
31
40
32
41
@Test
42
+ @Ignore
33
43
fun `points scored in the roll after a spare are counted twice` () {
34
44
val game = playGame(intArrayOf(6 , 4 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
35
45
assertEquals(16 , game.score())
36
46
}
37
47
38
48
@Test
49
+ @Ignore
39
50
fun `consecutive spares each get a one roll bonus` () {
40
51
val game = playGame(intArrayOf(5 , 5 , 3 , 7 , 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
41
52
assertEquals(31 , game.score())
42
53
}
43
54
44
55
@Test
56
+ @Ignore
45
57
fun `a spare in the last frame gets a one roll bonus that is counted once` () {
46
58
val game = playGame(intArrayOf(0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 3 , 7 ))
47
59
assertEquals(17 , game.score())
48
60
}
49
61
50
62
@Test
63
+ @Ignore
51
64
fun `a strike earns ten points in frame with a single roll` () {
52
65
val game = playGame(intArrayOf(10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
53
66
assertEquals(10 , game.score())
54
67
}
55
68
56
69
@Test
70
+ @Ignore
57
71
fun `points scored in the two rolls after a strike are counted twice as a bonus` () {
58
72
val game = playGame(intArrayOf(10 , 5 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
59
73
assertEquals(26 , game.score())
60
74
}
61
75
62
76
@Test
77
+ @Ignore
63
78
fun `consecutive strikes each get the two roll bonus` () {
64
79
val game = playGame(intArrayOf(10 , 10 , 10 , 5 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
65
80
assertEquals(81 , game.score())
66
81
}
67
82
68
83
@Test
84
+ @Ignore
69
85
fun `a strike in the last frame gets a two roll bonus that is counted once` () {
70
86
val game = playGame(intArrayOf(10 , 10 , 10 , 5 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
71
87
assertEquals(81 , game.score())
72
88
}
73
89
74
90
@Test
91
+ @Ignore
75
92
fun `rolling a spare with the two roll bonus does not get a bonus roll` () {
76
93
val game = playGame(intArrayOf(0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 7 , 3 ))
77
94
assertEquals(20 , game.score())
78
95
}
79
96
80
97
@Test
98
+ @Ignore
81
99
fun `strikes with the two roll bonus do not get bonus rolls` () {
82
100
val game = playGame(intArrayOf(0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 10 , 10 ))
83
101
assertEquals(30 , game.score())
84
102
}
85
103
86
104
@Test
105
+ @Ignore
87
106
fun `last two strikes followed by only last bonus with non strike points` () {
88
107
val game = playGame(intArrayOf(0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 10 , 0 , 1 ))
89
108
assertEquals(31 , game.score())
90
109
}
91
110
92
111
@Test
112
+ @Ignore
93
113
fun `a strike with the one roll bonus after a spare in the last frame does not get a bonus` () {
94
114
val game = playGame(intArrayOf(0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 3 , 10 ))
95
115
assertEquals(20 , game.score())
96
116
}
97
117
98
118
@Test
119
+ @Ignore
99
120
fun `all strikes is a perfect game` () {
100
121
val game = playGame(intArrayOf(10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 , 10 ))
101
122
assertEquals(300 , game.score())
102
123
}
103
124
104
125
@Test
126
+ @Ignore
105
127
fun `rolls can not score negative points` () {
106
- assertThrows< IllegalStateException > {
107
- playGame(intArrayOf( - 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
108
- }
128
+ expectedException.expect( IllegalStateException :: class .java)
129
+
130
+ playGame(intArrayOf( - 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
109
131
}
110
132
111
133
@Test
134
+ @Ignore
112
135
fun `a roll can not score more than 10 points` () {
113
- assertThrows< IllegalStateException > {
114
- playGame(intArrayOf( 11 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
115
- }
136
+ expectedException.expect( IllegalStateException :: class .java)
137
+
138
+ playGame(intArrayOf( 11 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
116
139
}
117
140
118
141
@Test
142
+ @Ignore
119
143
fun `two rolls in a frame can not score more than 10 points` () {
120
- assertThrows< IllegalStateException > {
121
- playGame(intArrayOf( 5 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
122
- }
144
+ expectedException.expect( IllegalStateException :: class .java)
145
+
146
+ playGame(intArrayOf( 5 , 6 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
123
147
}
124
148
125
149
@Test
150
+ @Ignore
126
151
fun `bonus roll after a strike in the last frame can not score more than 10 points` () {
127
- assertThrows< IllegalStateException > {
128
- playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 11 , 0 ))
129
- }
152
+ expectedException.expect( IllegalStateException :: class .java)
153
+
154
+ playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 11 , 0 ))
130
155
}
131
156
132
157
@Test
158
+ @Ignore
133
159
fun `two bonus rolls after a strike in the last frame can not score more than 10 points` () {
134
- assertThrows< IllegalStateException > {
135
- playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 5 , 6 ))
136
- }
160
+ expectedException.expect( IllegalStateException :: class .java)
161
+
162
+ playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 5 , 6 ))
137
163
}
138
164
139
165
@Test
166
+ @Ignore
140
167
fun `two bonus rolls after a strike in the last frame can score more than 10 points if one is a strike` () {
141
168
val game = playGame(intArrayOf(0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 10 , 6 ))
142
169
assertEquals(26 , game.score())
143
170
}
144
171
145
172
@Test
173
+ @Ignore
146
174
fun `the second bonus rolls after a strike in the last frame can not be a strike if the first one is not a strike` () {
147
- assertThrows< IllegalStateException > {
148
- playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 6 , 10 ))
149
- }
175
+ expectedException.expect( IllegalStateException :: class .java)
176
+
177
+ playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 6 , 10 ))
150
178
}
151
179
152
180
@Test
181
+ @Ignore
153
182
fun `second bonus roll after a strike in the last frame can not score more than 10 points` () {
154
- assertThrows< IllegalStateException > {
155
- playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 10 , 11 ))
156
- }
183
+ expectedException.expect( IllegalStateException :: class .java)
184
+
185
+ playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 10 , 11 ))
157
186
}
158
187
159
188
@Test
189
+ @Ignore
160
190
fun `an unstarted game can not be scored` () {
161
- assertThrows< IllegalStateException > {
162
- playGame(intArrayOf()).score()
163
- }
191
+ expectedException.expect( IllegalStateException :: class .java)
192
+
193
+ playGame(intArrayOf()).score()
164
194
}
165
195
166
196
@Test
197
+ @Ignore
167
198
fun `an incomplete game can not be scored` () {
168
- assertThrows< IllegalStateException > {
169
- playGame(intArrayOf( 0 , 0 , 1 )).score()
170
- }
199
+ expectedException.expect( IllegalStateException :: class .java)
200
+
201
+ playGame(intArrayOf( 0 , 0 , 1 )).score()
171
202
}
172
203
173
204
@Test
205
+ @Ignore
174
206
fun `can not roll if game already has ten frames` () {
175
- assertThrows< IllegalStateException > {
176
- playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
177
- }
207
+ expectedException.expect( IllegalStateException :: class .java)
208
+
209
+ playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ))
178
210
}
179
211
180
212
@Test
213
+ @Ignore
181
214
fun `bonus rolls for a strike in the last frame must be rolled before score can be calculated` () {
182
- assertThrows< IllegalStateException > {
183
- playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 )).score()
184
- }
215
+ expectedException.expect( IllegalStateException :: class .java)
216
+
217
+ playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 )).score()
185
218
}
186
219
187
220
@Test
221
+ @Ignore
188
222
fun `both bonus rolls for a strike in the last frame must be rolled before score can be calculated` () {
189
- assertThrows< IllegalStateException > {
190
- playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 10 )).score()
191
- }
223
+ expectedException.expect( IllegalStateException :: class .java)
224
+
225
+ playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 10 )).score()
192
226
}
193
227
194
228
@Test
229
+ @Ignore
195
230
fun `bonus roll for a spare in the last frame must be rolled before score can be calculated` () {
196
- assertThrows< IllegalStateException > {
197
- playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 3 )).score()
198
- }
231
+ expectedException.expect( IllegalStateException :: class .java)
232
+
233
+ playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 3 )).score()
199
234
}
200
235
201
236
@Test
237
+ @Ignore
202
238
fun `can not roll after bonus roll for spare` () {
203
- assertThrows< IllegalStateException > {
204
- playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 3 , 2 , 2 )).score()
205
- }
239
+ expectedException.expect( IllegalStateException :: class .java)
240
+
241
+ playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 7 , 3 , 2 , 2 )).score()
206
242
}
207
243
208
244
@Test
245
+ @Ignore
209
246
fun `can not roll after bonus roll for strike` () {
210
- assertThrows< IllegalStateException > {
211
- playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 3 , 2 , 2 )).score()
212
- }
247
+ expectedException.expect( IllegalStateException :: class .java)
248
+
249
+ playGame(intArrayOf( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 10 , 3 , 2 , 2 )).score()
213
250
}
214
251
}
0 commit comments