Skip to content

Instantly share code, notes, and snippets.

View waterlink's full-sized avatar

Alex Fedorov waterlink

View GitHub Profile

Keybase proof

I hereby claim:

To claim this, I am signing this object:

describe("FetcherTwo") {
lateinit var asyncQueue: AsyncQueue
lateinit var fetcher: FetcherTwo
val client = Client()
beforeEachTest {
asyncQueue = AsyncQueue()
fetcher = FetcherTwo(asyncQueue, client)
}
@waterlink
waterlink / Game.kt
Created October 15, 2018 16:05
step - 16
fun play(first: Throw, second: Throw): Winner {
if (first == second) {
return TIE
}
return when (first vs second) {
// classic rules
SCISSORS beats PAPER,
PAPER beats ROCK,
ROCK beats SCISSORS -> FIRST_PLAYER
@waterlink
waterlink / Game.kt
Created October 15, 2018 16:03
step - 15
return when (first to second) {
// classic rules
SCISSORS to PAPER,
PAPER to ROCK,
ROCK to SCISSORS -> FIRST_PLAYER
// additional modern rules
ROCK to LIZARD,
LIZARD to SPOCK,
SPOCK to SCISSORS,
@waterlink
waterlink / Game.kt
Created October 15, 2018 16:02
step - 14
fun play(first: Throw, second: Throw): Winner {
if (first == second) {
return TIE
}
return when (first to second) {
SCISSORS to PAPER,
PAPER to ROCK,
ROCK to SCISSORS -> FIRST_PLAYER
@waterlink
waterlink / Game.kt
Created October 15, 2018 15:54
step - 13
val firstWins = when (first to second) {
SCISSORS to PAPER,
PAPER to ROCK,
ROCK to SCISSORS -> true
else -> false
}
@waterlink
waterlink / GameRules.kt
Last active October 15, 2018 15:52
step - 12
private fun rules(first: Throw,
second: Throw,
block: GameRules.() -> Boolean) =
GameRules(first, second).run(block)
class GameRules(private val first: Throw,
private val second: Throw) {
infix fun Throw.beats(other: Throw) =
first == this && second == other
}
@waterlink
waterlink / Game.kt
Created October 15, 2018 15:51
step - 11
val firstWins = rules(first, second) {
SCISSORS beats PAPER ||
PAPER beats ROCK ||
ROCK beats SCISSORS
}
if (firstWins) {
return FIRST_PLAYER
}
@waterlink
waterlink / Game.kt
Created October 15, 2018 15:50
step - 10
val scissorsBeatPaper = first == SCISSORS && second == PAPER
val paperBeatsRock = first == PAPER && second == ROCK
val rockBeatsScissors = first == ROCK && second == SCISSORS
if (scissorsBeatPaper || paperBeatsRock || rockBeatsScissors) {
return FIRST_PLAYER
}
@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
}