Skip to content

Commit

Permalink
bowling: Correct PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
vmichalak committed Jan 23, 2024
1 parent a9063d9 commit 0913623
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 48 deletions.
11 changes: 11 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,17 @@
"difficulty": 5,
"topics": ["arrays", "generics", "recursion", "searching"]
},
{
"slug": "bowling",
"name": "Bowling",
"uuid": "ae084405-48d7-43ea-9bc5-6c4ebae4c1ef",
"practices": [],
"prerequisites": [
"for-loops",
"arrays"
],
"difficulty": 6
},
{
"slug": "etl",
"name": "ETL",
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/bowling/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"authors": [],
"contributors": [
"authors": [
"vmichalak"
],
"contributors": [],
"files": {
"solution": [
"src/main/kotlin/BowlingGame.kt"
Expand Down
129 changes: 83 additions & 46 deletions exercises/practice/bowling/src/test/kotlin/BowlingGameTest.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import org.junit.jupiter.api.assertThrows
import org.junit.Ignore
import org.junit.Rule
import org.junit.rules.ExpectedException
import kotlin.test.Test
import kotlin.test.assertEquals

class BowlingGameTest {

@Rule
@JvmField
var expectedException: ExpectedException = ExpectedException.none()

private fun playGame(rolls: IntArray): BowlingGame {
val game = BowlingGame()
rolls.forEach {
Expand All @@ -18,197 +25,227 @@ class BowlingGameTest {
}

@Test
@Ignore
fun `should be able to score a game with no strike or spares`() {
val game = playGame(intArrayOf(3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6, 3, 6))
assertEquals(90, game.score())
}

@Test
@Ignore
fun `a spare followed by zeros is worth ten points`() {
val game = playGame(intArrayOf(6, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
assertEquals(10, game.score())
}

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

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

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

@Test
@Ignore
fun `a strike earns ten points in frame with a single roll`() {
val game = playGame(intArrayOf(10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
assertEquals(10, game.score())
}

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

@Test
@Ignore
fun `consecutive strikes each get the two roll bonus`() {
val game = playGame(intArrayOf(10, 10, 10, 5, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
assertEquals(81, game.score())
}

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

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

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

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

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

@Test
@Ignore
fun `all strikes is a perfect game`() {
val game = playGame(intArrayOf(10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10))
assertEquals(300, game.score())
}

@Test
@Ignore
fun `rolls can not score negative points`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}

@Test
@Ignore
fun `a roll can not score more than 10 points`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}

@Test
@Ignore
fun `two rolls in a frame can not score more than 10 points`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}

@Test
@Ignore
fun `bonus roll after a strike in the last frame can not score more than 10 points`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 0))
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 11, 0))
}

@Test
@Ignore
fun `two bonus rolls after a strike in the last frame can not score more than 10 points`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5, 6))
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 5, 6))
}

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

@Test
@Ignore
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`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 6, 10))
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 6, 10))
}

@Test
@Ignore
fun `second bonus roll after a strike in the last frame can not score more than 10 points`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 11))
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 11))
}

@Test
@Ignore
fun `an unstarted game can not be scored`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf()).score()
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf()).score()
}

@Test
@Ignore
fun `an incomplete game can not be scored`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(0, 0, 1)).score()
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(0, 0, 1)).score()
}

@Test
@Ignore
fun `can not roll if game already has ten frames`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
}

@Test
@Ignore
fun `bonus rolls for a strike in the last frame must be rolled before score can be calculated`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10)).score()
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10)).score()
}

@Test
@Ignore
fun `both bonus rolls for a strike in the last frame must be rolled before score can be calculated`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10)).score()
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10)).score()
}

@Test
@Ignore
fun `bonus roll for a spare in the last frame must be rolled before score can be calculated`() {
assertThrows<IllegalStateException> {
playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3)).score()
}
expectedException.expect(IllegalStateException::class.java)

playGame(intArrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 3)).score()
}

@Test
@Ignore
fun `can not roll after bonus roll for spare`() {
assertThrows<IllegalStateException> {
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()
}
expectedException.expect(IllegalStateException::class.java)

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()
}

@Test
@Ignore
fun `can not roll after bonus roll for strike`() {
assertThrows<IllegalStateException> {
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()
}
expectedException.expect(IllegalStateException::class.java)

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()
}
}

0 comments on commit 0913623

Please sign in to comment.