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

35 lines
912 B
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),
)
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(calculateGameSummary(outcomes), expectedSummary)
}
}
}