rock-paper-scissors/src/test/kotlin/rps/GameTest.kt
2020-10-29 16:41:24 +01:00

46 lines
1.3 KiB
Kotlin

package rps
import rps.Move.*
import rps.Outcome.*
import kotlin.test.Test
import kotlin.test.assertEquals
class GameTest {
@Test
fun testOutcomeCalculation() {
val games = listOf(
Triple(PAPER, ROCK, WIN),
Triple(ROCK, PAPER, LOSS),
Triple(PAPER, SCISSORS, LOSS),
Triple(ROCK, ROCK, DRAW),
Triple(ROCK, LIZARD, WIN),
Triple(LIZARD, SPOCK, WIN),
Triple(SPOCK, PAPER, LOSS),
)
for ((first, second, expected) in games) {
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(outcomes.calculateGameSummary(), expectedSummary)
}
}
// We can’t test the outcome because it’s random,
// but at least we can verify that the total number is correct.
@Test
fun `game summary should have correct number of outcomes`() {
val summary = playGame(50)
assertEquals(summary.wins + summary.draws + summary.losses, 50)
}
}