Add game enums and outcome calculation test

This commit is contained in:
kageru 2020-10-22 19:23:09 +02:00
parent 580b279122
commit 9a4f8f6043
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
4 changed files with 43 additions and 19 deletions

View File

@ -1,5 +0,0 @@
package rps
fun main() {
println("Hello, world")
}

View File

@ -0,0 +1,22 @@
package rps
fun main() {
println("Hello, world")
}
/** A possible move in a game of rock-paper-scissors. */
enum class Move {
ROCK,
PAPER,
SCISSORS
}
// purposely not calling this Result to avoid confusion with kotlin.Result and similar
enum class Outcome {
WIN,
DRAW,
LOSS
}
/** Determine the [Outcome] of [first] vs [second] from the perspective of [first]. */
fun determineOutcome(first: Move, second: Move): Outcome = TODO()

View File

@ -1,14 +0,0 @@
/*
* This Kotlin source file was generated by the Gradle 'init' task.
*/
package rps
import kotlin.test.Test
import kotlin.test.assertEquals
class GameTest {
@Test
fun testAppHasAGreeting() {
assertEquals(2 + 2, 4)
}
}

View File

@ -0,0 +1,21 @@
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)
}
}
}