30 lines
1.2 KiB
JavaScript
30 lines
1.2 KiB
JavaScript
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' }))
|