Add game enums and outcome calculation test
This commit is contained in:
parent
580b279122
commit
9a4f8f6043
|
@ -1,5 +0,0 @@
|
||||||
package rps
|
|
||||||
|
|
||||||
fun main() {
|
|
||||||
println("Hello, world")
|
|
||||||
}
|
|
|
@ -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()
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user