Skip to content

Commit 0913623

Browse files
committed
bowling: Correct PR review
1 parent a9063d9 commit 0913623

File tree

3 files changed

+96
-48
lines changed

3 files changed

+96
-48
lines changed

config.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,17 @@
820820
"difficulty": 5,
821821
"topics": ["arrays", "generics", "recursion", "searching"]
822822
},
823+
{
824+
"slug": "bowling",
825+
"name": "Bowling",
826+
"uuid": "ae084405-48d7-43ea-9bc5-6c4ebae4c1ef",
827+
"practices": [],
828+
"prerequisites": [
829+
"for-loops",
830+
"arrays"
831+
],
832+
"difficulty": 6
833+
},
823834
{
824835
"slug": "etl",
825836
"name": "ETL",

exercises/practice/bowling/.meta/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"authors": [],
3-
"contributors": [
2+
"authors": [
43
"vmichalak"
54
],
5+
"contributors": [],
66
"files": {
77
"solution": [
88
"src/main/kotlin/BowlingGame.kt"
Lines changed: 83 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import org.junit.jupiter.api.assertThrows
1+
import org.junit.Ignore
2+
import org.junit.Rule
3+
import org.junit.rules.ExpectedException
24
import kotlin.test.Test
35
import kotlin.test.assertEquals
46

57
class BowlingGameTest {
8+
9+
@Rule
10+
@JvmField
11+
var expectedException: ExpectedException = ExpectedException.none()
12+
613
private fun playGame(rolls: IntArray): BowlingGame {
714
val game = BowlingGame()
815
rolls.forEach {
@@ -18,197 +25,227 @@ class BowlingGameTest {
1825
}
1926

2027
@Test
28+
@Ignore
2129
fun `should be able to score a game with no strike or spares`() {
2230
val game = playGame(intArrayOf(3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6))
2331
assertEquals(90, game.score())
2432
}
2533

2634
@Test
35+
@Ignore
2736
fun `a spare followed by zeros is worth ten points`() {
2837
val game = playGame(intArrayOf(6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
2938
assertEquals(10, game.score())
3039
}
3140

3241
@Test
42+
@Ignore
3343
fun `points scored in the roll after a spare are counted twice`() {
3444
val game = playGame(intArrayOf(6, 4, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
3545
assertEquals(16, game.score())
3646
}
3747

3848
@Test
49+
@Ignore
3950
fun `consecutive spares each get a one roll bonus`() {
4051
val game = playGame(intArrayOf(5, 5, 3, 7, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
4152
assertEquals(31, game.score())
4253
}
4354

4455
@Test
56+
@Ignore
4557
fun `a spare in the last frame gets a one roll bonus that is counted once`() {
4658
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))
4759
assertEquals(17, game.score())
4860
}
4961

5062
@Test
63+
@Ignore
5164
fun `a strike earns ten points in frame with a single roll`() {
5265
val game = playGame(intArrayOf(10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
5366
assertEquals(10, game.score())
5467
}
5568

5669
@Test
70+
@Ignore
5771
fun `points scored in the two rolls after a strike are counted twice as a bonus`() {
5872
val game = playGame(intArrayOf(10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
5973
assertEquals(26, game.score())
6074
}
6175

6276
@Test
77+
@Ignore
6378
fun `consecutive strikes each get the two roll bonus`() {
6479
val game = playGame(intArrayOf(10, 10, 10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
6580
assertEquals(81, game.score())
6681
}
6782

6883
@Test
84+
@Ignore
6985
fun `a strike in the last frame gets a two roll bonus that is counted once`() {
7086
val game = playGame(intArrayOf(10, 10, 10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
7187
assertEquals(81, game.score())
7288
}
7389

7490
@Test
91+
@Ignore
7592
fun `rolling a spare with the two roll bonus does not get a bonus roll`() {
7693
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))
7794
assertEquals(20, game.score())
7895
}
7996

8097
@Test
98+
@Ignore
8199
fun `strikes with the two roll bonus do not get bonus rolls`() {
82100
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))
83101
assertEquals(30, game.score())
84102
}
85103

86104
@Test
105+
@Ignore
87106
fun `last two strikes followed by only last bonus with non strike points`() {
88107
val game = playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 0, 1))
89108
assertEquals(31, game.score())
90109
}
91110

92111
@Test
112+
@Ignore
93113
fun `a strike with the one roll bonus after a spare in the last frame does not get a bonus`() {
94114
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))
95115
assertEquals(20, game.score())
96116
}
97117

98118
@Test
119+
@Ignore
99120
fun `all strikes is a perfect game`() {
100121
val game = playGame(intArrayOf(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10))
101122
assertEquals(300, game.score())
102123
}
103124

104125
@Test
126+
@Ignore
105127
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))
109131
}
110132

111133
@Test
134+
@Ignore
112135
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))
116139
}
117140

118141
@Test
142+
@Ignore
119143
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))
123147
}
124148

125149
@Test
150+
@Ignore
126151
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))
130155
}
131156

132157
@Test
158+
@Ignore
133159
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))
137163
}
138164

139165
@Test
166+
@Ignore
140167
fun `two bonus rolls after a strike in the last frame can score more than 10 points if one is a strike`() {
141168
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))
142169
assertEquals(26, game.score())
143170
}
144171

145172
@Test
173+
@Ignore
146174
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))
150178
}
151179

152180
@Test
181+
@Ignore
153182
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))
157186
}
158187

159188
@Test
189+
@Ignore
160190
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()
164194
}
165195

166196
@Test
197+
@Ignore
167198
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()
171202
}
172203

173204
@Test
205+
@Ignore
174206
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))
178210
}
179211

180212
@Test
213+
@Ignore
181214
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()
185218
}
186219

187220
@Test
221+
@Ignore
188222
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()
192226
}
193227

194228
@Test
229+
@Ignore
195230
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()
199234
}
200235

201236
@Test
237+
@Ignore
202238
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()
206242
}
207243

208244
@Test
245+
@Ignore
209246
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()
213250
}
214251
}

0 commit comments

Comments
 (0)