feat(js): m05 game and m06 view with fixtures and tests

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas Winther
2026-10-28 23:45:10 +01:00
co-authored by Claude Sonnet 5.5
parent 08b462d5cc
commit b83f94894e
12 changed files with 1398 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { update, replay, history } from '../src/game.js'
import { loadFixture, freeze } from './helpers.js'
const fixtureTests = (name, f) => {
const fx = loadFixture(name)
fx.cases.forEach((c) =>
test(`m05 ${fx.function}: ${c.name}`, () => assert.deepStrictEqual(f(...freeze(c.args)), c.expected)))
}
fixtureTests('m05-update', update)
fixtureTests('m05-replay', replay)
fixtureTests('m05-history', history)
test('m05 history has one more state than there are actions', () => {
const [state, actions] = loadFixture('m05-replay').cases[0].args
assert.equal(history(freeze(state), freeze(actions)).length, actions.length + 1)
})
test('m05 history starts at the start state and ends where replay ends', () => {
const [state, actions] = freeze(loadFixture('m05-replay').cases[0].args)
const states = history(state, actions)
assert.deepStrictEqual(states[0], state)
assert.deepStrictEqual(states[states.length - 1], replay(state, actions))
})