feat(js): m01 util and m02 model with tests, fixtures, purity audit
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
5be3cebe71
commit
22c221a042
@@ -0,0 +1,29 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { point, pointEquals, delta, opposite, Action, initialState } from '../src/model.js'
|
||||
import { loadFixture, freeze } from './helpers.js'
|
||||
|
||||
const fixtureTests = (name, f) => {
|
||||
const fx = loadFixture(name)
|
||||
fx.cases.forEach((c) =>
|
||||
test(`m02 ${fx.function}: ${c.name}`, () => assert.deepStrictEqual(f(...freeze(c.args)), c.expected)))
|
||||
}
|
||||
|
||||
fixtureTests('m02-delta', delta)
|
||||
fixtureTests('m02-opposite', opposite)
|
||||
fixtureTests('m02-point-equals', pointEquals)
|
||||
fixtureTests('m02-initial-state', initialState)
|
||||
|
||||
test('m02 point builds a {x, y} record', () => assert.deepStrictEqual(point(3, 4), { x: 3, y: 4 }))
|
||||
|
||||
test('m02 opposite is its own inverse', () =>
|
||||
['Up', 'Down', 'Left', 'Right'].forEach((d) => assert.equal(opposite(opposite(d)), d)))
|
||||
|
||||
test('m02 Action constants are tagged records', () => {
|
||||
assert.deepStrictEqual(Action.Tick, { tag: 'Tick' })
|
||||
assert.deepStrictEqual(Action.TogglePause, { tag: 'TogglePause' })
|
||||
assert.deepStrictEqual(Action.Restart, { tag: 'Restart' })
|
||||
assert.deepStrictEqual(Action.Frame, { tag: 'Frame' })
|
||||
})
|
||||
test('m02 Action.Turn carries the direction', () =>
|
||||
assert.deepStrictEqual(Action.Turn('Left'), { tag: 'Turn', dir: 'Left' }))
|
||||
Reference in New Issue
Block a user