40 lines
1.2 KiB
Scala
40 lines
1.2 KiB
Scala
package snake
|
|
|
|
import Fixtures.*
|
|
|
|
class M05GameSuite extends munit.FunSuite:
|
|
cases("m05-update").foreach { c =>
|
|
test(s"update: ${c("name").str}") {
|
|
val a = c("args")
|
|
assertEquals(Game.update(gameState(a(0)), action(a(1))), gameState(c("expected")))
|
|
}
|
|
}
|
|
|
|
cases("m05-replay").foreach { c =>
|
|
test(s"replay: ${c("name").str}") {
|
|
val a = c("args")
|
|
assertEquals(Game.replay(gameState(a(0)), list(a(1))(action)), gameState(c("expected")))
|
|
}
|
|
}
|
|
|
|
cases("m05-history").foreach { c =>
|
|
test(s"history: ${c("name").str}") {
|
|
val a = c("args")
|
|
assertEquals(Game.history(gameState(a(0)), list(a(1))(action)), list(c("expected"))(gameState))
|
|
}
|
|
}
|
|
|
|
private val replayArgs = cases("m05-replay")(0)("args")
|
|
private val start = gameState(replayArgs(0))
|
|
private val actions = list(replayArgs(1))(action)
|
|
|
|
test("history has one more state than there are actions") {
|
|
assertEquals(Game.history(start, actions).length, actions.length + 1)
|
|
}
|
|
|
|
test("history starts at the start state and ends where replay ends") {
|
|
val states = Game.history(start, actions)
|
|
assertEquals(states.head, start)
|
|
assertEquals(states.last, Game.replay(start, actions))
|
|
}
|