module Snake.Tests.M02Model open Expecto open Snake.Model open Snake.Tests.Fixtures [] 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") ]