scripts/fixtures/ holds the scripts that produced the 2026-11-11 fixtures, with a README on running them safely into a copy. Run in order they reproduce the content of every fixture they touch. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
34 lines
2.2 KiB
JavaScript
34 lines
2.2 KiB
JavaScript
import { writeFileSync } from 'node:fs'
|
|
// Fixture regeneration aid (see scripts/fixtures/README.md). Written during the 2026-11-11 build, kept for reference.
|
|
// Writes into fixtures/ unless FIXTURES_OUT names another directory (with a trailing slash).
|
|
const FIX = process.env.FIXTURES_OUT ?? new URL('../../fixtures/', import.meta.url).pathname
|
|
const SOL = new URL('../../js/solutions/', import.meta.url).href
|
|
const HERE = new URL('./', import.meta.url).pathname
|
|
const { violations } = await import(SOL + 'check.js')
|
|
const base = { width: 5, height: 5, snake: [{ x: 2, y: 2 }, { x: 1, y: 2 }, { x: 0, y: 2 }], dir: 'Right', nextDir: 'Right',
|
|
apple: { x: 4, y: 4 }, seed: 0, score: 0, status: 'Playing', frame: 0 }
|
|
const P = (x, y) => ({ x, y })
|
|
const cases = [
|
|
['a-sane-state-has-no-violations', {}],
|
|
['no-apple-is-fine', { apple: null }],
|
|
['a-pending-perpendicular-turn-is-fine', { nextDir: 'Up' }],
|
|
['a-one-cell-snake-is-fine', { snake: [P(0, 0)] }],
|
|
['a-game-over-state-can-be-sane', { status: 'GameOver', snake: [P(4, 2), P(3, 2), P(2, 2)] }],
|
|
['empty-snake', { snake: [] }],
|
|
['head-off-the-right-edge', { snake: [P(5, 2), P(4, 2), P(3, 2)] }],
|
|
['tail-above-the-board', { snake: [P(1, 1), P(1, 0), P(1, -1)] }],
|
|
['head-on-its-own-body', { snake: [P(2, 2), P(2, 3), P(1, 3), P(1, 2), P(2, 2)] }],
|
|
['snake-with-a-gap', { snake: [P(3, 2), P(1, 2), P(0, 2)] }],
|
|
['snake-with-a-diagonal-step', { snake: [P(2, 2), P(1, 1), P(0, 1)] }],
|
|
['apple-outside-the-board', { apple: P(5, 0) }],
|
|
['apple-on-the-head', { apple: P(2, 2) }],
|
|
['apple-on-the-tail', { apple: P(0, 2) }],
|
|
['pending-turn-straight-back', { nextDir: 'Left' }],
|
|
['pending-turn-straight-back-vertical', { dir: 'Up', nextDir: 'Down' }],
|
|
['several-violations-are-listed-in-order', { snake: [P(5, 2), P(3, 2), P(3, 2)], apple: P(3, 2), nextDir: 'Left' }],
|
|
['doubled-cell-counts-as-overlap-and-as-disconnected', { snake: [P(2, 2), P(2, 2)] }],
|
|
]
|
|
const fx = { function: 'violations', cases: cases.map(([name, patch]) => { const s = { ...base, ...patch }; return { name, args: [s], expected: violations(s) } }) }
|
|
writeFileSync(FIX + 'm12-violations.json', JSON.stringify(fx, null, 2) + '\n')
|
|
fx.cases.forEach((c) => console.log(c.name, JSON.stringify(c.expected)))
|