diff --git a/src/main/kotlin/rps/Game.kt b/src/main/kotlin/rps/Game.kt index a9e23f1..9fff147 100644 --- a/src/main/kotlin/rps/Game.kt +++ b/src/main/kotlin/rps/Game.kt @@ -24,9 +24,14 @@ enum class Outcome { LOSS } +// Named Triple for readability +data class GameSummary(val wins: Int, val draws: Int, val losses: Int) + /** Determine the [Outcome] of [first] vs [second] from the perspective of [first]. */ fun determineOutcome(first: Move, second: Move): Outcome = when { first.strongAgainst() == second -> Outcome.WIN first == second -> Outcome.DRAW else -> Outcome.LOSS -} \ No newline at end of file +} + +fun calculateGameSummary(turns: List): GameSummary = TODO() diff --git a/src/test/kotlin/rps/GameTest.kt b/src/test/kotlin/rps/GameTest.kt index 34ebe0e..94ecd98 100644 --- a/src/test/kotlin/rps/GameTest.kt +++ b/src/test/kotlin/rps/GameTest.kt @@ -18,4 +18,17 @@ class GameTest { assertEquals(determineOutcome(first, second), expected) } } + + @Test + fun `game summary should count outcomes`() { + val gameLists = listOf( + listOf(WIN, WIN, WIN) to GameSummary(3, 0, 0), + listOf(WIN, DRAW, LOSS) to GameSummary(1, 1, 1), + listOf(WIN, LOSS, WIN) to GameSummary(2, 0, 1), + listOf(WIN, DRAW, DRAW, DRAW) to GameSummary(1, 3, 0), + ) + for ((outcomes, expectedSummary) in gameLists) { + assertEquals(calculateGameSummary(outcomes), expectedSummary) + } + } }