feat(course): audit fixes and twelve extensions (Modules 7b, 12, 13)
Audit pass: - Frame rule counts frames since the last move, so every step lasts exactly movesEvery(score) frames, also right after a speed-up - clampTime + MAX_GAP_MS: a hidden tab no longer replays the whole gap - Pong Restart keeps held keys - Fact corrections (mulberry32 output coverage, Haskell IO, uniform) - New fixture cases from a mutation analysis Extensions (all three tracks, shared fixtures, course text): - Turn queue (Exercise 10.6), persisted high score (10.7), replay viewer (10.8), play() end-to-end helper (9.5) - Optional State (4.7) and optional Module 7b, stack-safe IO - Module 12, property-based testing with generators, shrinking, invariants and a model-based oracle - Module 13, Conway's Life with a Click event - JS type checking via jsconfig, JSDoc and types.d.ts - Maintainer tools: scripts/mutate.mjs, scripts/typecheck-js.sh, Playwright end-to-end suite (e2e/, scripts/e2e.sh) Docs: docs/contract.md is the canonical contract; specs and build log under docs/superpowers. Verified: JS 728, Scala 689, F# 691 unit tests; stubs and progression M01-M13 and M07b; 176 end-to-end tests on Chromium and WebKit. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
876f5aabb1
commit
edd57f0148
253 files changed
+21753
-503
No files matched your search
+25
-2
@@ -7,6 +7,9 @@ open Snake.IO
|
||||
open Snake.Stream
|
||||
open Snake.Tests.M09Helpers
|
||||
|
||||
// The ops of drawing one state's view.
|
||||
let private drawOps (state: GameState) : Op list = View.view state |> List.map Draw
|
||||
|
||||
[<Tests>]
|
||||
let tests =
|
||||
testList "M09 App" [
|
||||
@@ -37,12 +40,19 @@ let tests =
|
||||
(View.view (Spawn.newGame 42u) |> List.map Draw)
|
||||
"ops")
|
||||
|
||||
// Module 10 (Exercise 10.7) makes `main` also load the stored best and draw one more shape after the game's
|
||||
// view, so this test accepts both versions; M10 pins the final one exactly.
|
||||
testCase "main asks for a random seed, then builds the stream from it" (fun () ->
|
||||
let traced = IO.trace 42u (App.main ())
|
||||
Expect.equal traced.Ops [ RandomSeed ] "ops"
|
||||
|
||||
Expect.isTrue
|
||||
(traced.Ops = [ RandomSeed ] || traced.Ops = [ RandomSeed; LoadBest ])
|
||||
$"main may only ask for the seed (and, from m10 on, the stored best); it asked for %A{traced.Ops}"
|
||||
|
||||
let outs, _ = Stream.step (Time 0L) traced.Result
|
||||
Expect.equal (List.length outs) 1 "one drawing"
|
||||
Expect.equal (drawn (List.head outs)) (View.view (Spawn.newGame 42u)) "drawing")
|
||||
let expected = View.view (Spawn.newGame 42u)
|
||||
Expect.equal (drawn (List.head outs) |> List.truncate (List.length expected)) expected "drawing")
|
||||
|
||||
// `main` itself switches to speedActions in m10, so the 150 ms behaviour is checked on the same program built from classicActions.
|
||||
testCase "the program built from classicActions draws the new game first, then the ticked game after 150 ms" (fun () ->
|
||||
@@ -60,4 +70,17 @@ let tests =
|
||||
let later, _ = Stream.step (Time 150L) next
|
||||
Expect.equal (List.length first) 1 "one drawing"
|
||||
Expect.isNonEmpty later "more drawings")
|
||||
|
||||
// ---- play: the whole program in one equality (Exercise 9.5)
|
||||
|
||||
testCase "play on the classic program equals the scenes of the expected states" (fun () ->
|
||||
let events = [ Time 150L; KeyDown "ArrowUp"; KeyDown "x"; Time 300L; Time 310L ]
|
||||
let expectedStates = Game.history (Spawn.newGame 42u) [ Tick; Turn Up; Tick ]
|
||||
Expect.equal (App.play 42u events (classicMain ())) (List.map drawOps expectedStates) "drawings")
|
||||
|
||||
testCase "play with no events gives no drawings" (fun () ->
|
||||
Expect.equal (App.play 42u [] (classicMain ())) [] "drawings")
|
||||
|
||||
testCase "play uses the seed for the program's RandomSeed" (fun () ->
|
||||
Expect.equal (App.play 7u [ Time 0L ] (classicMain ())) [ drawOps (Spawn.newGame 7u) ] "drawings")
|
||||
]
|
||||
Reference in new issue
Block a user