Skip to content

Instantly share code, notes, and snippets.

View waterlink's full-sized avatar

Alex Fedorov waterlink

View GitHub Profile
@waterlink
waterlink / Game.kt
Created October 15, 2018 15:50
step - 9
if (first == SCISSORS && second != ROCK ||
first == PAPER && second != SCISSORS ||
first == ROCK && second != PAPER) {
return FIRST_PLAYER
}
@waterlink
waterlink / Throw.kt
Created October 15, 2018 15:49
step - 8
interface Throw {
val winsAgainst: List<Throw>
fun beats(other: Throw) = winsAgainst.contains(other)
object SCISSORS : Throw {
override val winsAgainst = listOf(PAPER, LIZARD)
}
object PAPER : Throw {
override val winsAgainst = listOf(ROCK, SPOCK)
@waterlink
waterlink / GameTest.kt
Created October 15, 2018 15:48
step - 7
@Test
fun `game rules`() {
// Classic rules
SCISSORS beats PAPER
PAPER beats ROCK
ROCK beats SCISSORS
// Additional modern rules
ROCK beats LIZARD
LIZARD beats SPOCK
@waterlink
waterlink / Throw.kt
Created October 15, 2018 15:47
step - 6
interface Throw {
val winsAgainst: Throw
fun beats(other: Throw) = other == winsAgainst
object SCISSORS : Throw {
override val winsAgainst = PAPER
}
object PAPER : Throw {
override val winsAgainst = ROCK
@waterlink
waterlink / Throw.kt
Created October 15, 2018 15:46
step - 5
object SCISSORS : Throw {
override fun beats(other: Throw) = other == PAPER
}
object PAPER : Throw {
override fun beats(other: Throw) = other == ROCK
}
object ROCK : Throw {
override fun beats(other: Throw) = other == SCISSORS
@waterlink
waterlink / Throw.kt
Created October 15, 2018 15:45
step - 4
interface Throw {
fun beats(other: Throw): Boolean
object SCISSORS : Throw {
override fun beats(other: Throw) = other != ROCK
}
object PAPER : Throw {
override fun beats(other: Throw) = other != SCISSORS
}
@waterlink
waterlink / Throw.kt
Created October 15, 2018 15:44
step - 3
enum class Throw {
SCISSORS, PAPER, ROCK;
fun beats(other: Throw) =
this == SCISSORS && other != ROCK ||
this == PAPER && other != SCISSORS ||
this == ROCK && other != PAPER
}
@waterlink
waterlink / Game.kt
Created October 15, 2018 15:44
step - 2
if (first.beats(second)) {
return FIRST_PLAYER
}
@waterlink
waterlink / Game.kt
Created October 15, 2018 15:42
step - 1
fun play(first: Throw, second: Throw): Winner {
if (first == second) {
return TIE
}
if (first == SCISSORS && second != ROCK ||
first == PAPER && second != SCISSORS ||
first == ROCK && second != PAPER) {
return FIRST_PLAYER
}
return SECOND_PLAYER
package myapp
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import myapp.ExamplesTest.ExampleResponse.Kitten
import org.assertj.core.api.Assertions.assertThat
import org.intellij.lang.annotations.Language
import org.junit.Test
class ExamplesTest {