feat(fsharp): m01-m06 util, model, rules, random, spawn, game, view with Expecto tests

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Lucas Winther
2026-10-29 00:49:42 +01:00
co-authored by Claude Opus 5.5
parent 183821737e
commit 9cbefeb2be
27 changed files with 851 additions and 6 deletions
+42
View File
@@ -0,0 +1,42 @@
module Snake.Tests.M02Model
open Expecto
open Snake.Model
open Snake.Tests.Fixtures
[<Tests>]
let tests =
testList "M02 Model" [
yield! fixtureTests "m02-delta" "delta" (fun c ->
Expect.equal (delta (direction (arg 0 c))) (point (expected c)) "delta")
yield! fixtureTests "m02-opposite" "opposite" (fun c ->
Expect.equal (opposite (direction (arg 0 c))) (direction (expected c)) "opposite")
// pointEquals has no F# function: records already compare structurally with `=`.
// The shared fixture is kept so every track checks the same four situations.
yield! fixtureTests "m02-point-equals" "pointEquals (record =)" (fun c ->
Expect.equal (point (arg 0 c) = point (arg 1 c)) (bool (expected c)) "point equality")
yield! fixtureTests "m02-initial-state" "initialState" (fun c ->
Expect.equal (initialState (u32 (arg 0 c))) (gameState (expected c)) "initialState")
testCase "Point holds its coordinates" (fun () ->
let p = { X = 3; Y = 4 }
Expect.equal (p.X, p.Y) (3, 4) "coordinates")
testCase "opposite is its own inverse" (fun () ->
for d in [ Up; Down; Left; Right ] do
Expect.equal (opposite (opposite d)) d $"{d}")
testCase "Action Turn carries the direction" (fun () ->
Expect.equal (Turn Left) (Turn Left) "same direction"
Expect.notEqual (Turn Left) (Turn Right) "different directions"
match Turn Left with
| Turn d -> Expect.equal d Left "carried direction"
| other -> failtest $"expected Turn, got {other}")
testCase "the other Actions are distinct constants" (fun () ->
Expect.equal (List.length (List.distinct [ Tick; TogglePause; Restart; Frame ])) 4 "distinct")
]