feat(scala): m01–m06 port with shared fixtures
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
045029639e
commit
1e186733d1
@@ -0,0 +1,54 @@
|
||||
package snake
|
||||
|
||||
import Fixtures.*
|
||||
|
||||
class M02ModelSuite extends munit.FunSuite:
|
||||
cases("m02-delta").foreach { c =>
|
||||
test(s"delta: ${c("name").str}") {
|
||||
assertEquals(Model.delta(direction(c("args")(0))), point(c("expected")))
|
||||
}
|
||||
}
|
||||
|
||||
cases("m02-opposite").foreach { c =>
|
||||
test(s"opposite: ${c("name").str}") {
|
||||
assertEquals(Model.opposite(direction(c("args")(0))), direction(c("expected")))
|
||||
}
|
||||
}
|
||||
|
||||
// pointEquals has no Scala function: case classes already compare structurally with `==`.
|
||||
// The shared fixture is kept so every track checks the same four situations.
|
||||
cases("m02-point-equals").foreach { c =>
|
||||
test(s"pointEquals (case-class ==): ${c("name").str}") {
|
||||
val a = point(c("args")(0))
|
||||
val b = point(c("args")(1))
|
||||
assertEquals(a == b, c("expected").bool)
|
||||
}
|
||||
}
|
||||
|
||||
cases("m02-initial-state").foreach { c =>
|
||||
test(s"initialState: ${c("name").str}") {
|
||||
assertEquals(Model.initialState(c("args")(0).num.toLong), gameState(c("expected")))
|
||||
}
|
||||
}
|
||||
|
||||
test("Point holds its coordinates") {
|
||||
val p = Point(3, 4)
|
||||
assertEquals((p.x, p.y), (3, 4))
|
||||
}
|
||||
|
||||
test("opposite is its own inverse") {
|
||||
Direction.values.foreach(d => assertEquals(Model.opposite(Model.opposite(d)), d))
|
||||
}
|
||||
|
||||
test("Action.Turn carries the direction") {
|
||||
assertEquals(Action.Turn(Direction.Left), Action.Turn(Direction.Left))
|
||||
assertNotEquals(Action.Turn(Direction.Left), Action.Turn(Direction.Right))
|
||||
Action.Turn(Direction.Left) match
|
||||
case Action.Turn(d) => assertEquals(d, Direction.Left)
|
||||
case other => fail(s"expected Turn, got $other")
|
||||
}
|
||||
|
||||
test("the other Actions are distinct constants") {
|
||||
val all = List(Action.Tick, Action.TogglePause, Action.Restart, Action.Frame)
|
||||
assertEquals(all.distinct.length, 4)
|
||||
}
|
||||
Reference in New Issue
Block a user