rock-paper-scissors/src/test/kotlin/rps/GameTest.kt

46 lines
1.3 KiB
Kotlin
Raw Normal View History

package rps
import rps.Move.*
import rps.Outcome.*
import kotlin.test.Test
import kotlin.test.assertEquals
class GameTest {
@Test
fun testOutcomeCalculation() {
val games = listOf(
2020-10-22 19:52:33 +02:00
Triple(PAPER, ROCK, WIN),
Triple(ROCK, PAPER, LOSS),
Triple(PAPER, SCISSORS, LOSS),
Triple(ROCK, ROCK, DRAW),
2020-10-29 16:41:24 +01:00
Triple(ROCK, LIZARD, WIN),
Triple(LIZARD, SPOCK, WIN),
Triple(SPOCK, PAPER, LOSS),
)
for ((first, second, expected) in games) {
assertEquals(determineOutcome(first, second), expected)
}
}
2020-10-22 19:41:03 +02:00
@Test
fun `game summary should count outcomes`() {
val gameLists = listOf(
2020-10-22 19:52:33 +02:00
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),
2020-10-22 19:41:03 +02:00
)
for ((outcomes, expectedSummary) in gameLists) {
2020-10-22 19:52:33 +02:00
assertEquals(outcomes.calculateGameSummary(), expectedSummary)
2020-10-22 19:41:03 +02:00
}
}
2020-10-22 19:52:33 +02:00
// 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)
}
}