Add test for outcome summary

This commit is contained in:
kageru 2020-10-22 19:41:03 +02:00
parent 8aa7d991d2
commit c9e331a24e
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
2 changed files with 19 additions and 1 deletions

View File

@ -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
}
}
fun calculateGameSummary(turns: List<Outcome>): GameSummary = TODO()

View File

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