Add test for outcome summary
This commit is contained in:
parent
8aa7d991d2
commit
c9e331a24e
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user