explodorama / files / test / replayCompare.test.ts
replayCompare.test.ts
| 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { readFileSync } from 'node:fs' |
| 3 | import { buildReplay } from '../src/sim/replayCompare' |
| 4 | import { replay } from '../src/sim/record' |
| 5 | import type { RunRecord } from '../src/sim/record' |
| 6 | import { step } from '../src/sim/turn' |
| 7 | |
| 8 | /** The report of Q101 (seed 1464004408, level 4): the autopilot, with Bomb Pass, walked into its own bomb's blast. */ |
| 9 | const record = JSON.parse(readFileSync(new URL('./fixtures/q101-bomb-pass.json', import.meta.url), 'utf8')) as RunRecord |
| 10 | |
| 11 | describe('the report replay (Q103)', () => { |
| 12 | const script = buildReplay(record) |
| 13 | |
| 14 | it('starts a few turns before the autopilot took over, on the report\'s level', () => { |
| 15 | expect(script.level).toBe(4) |
| 16 | expect(script.prefix.length).toBe(6) |
| 17 | let s = script.start |
| 18 | for (const a of script.prefix) s = step(s, a).state |
| 19 | expect(s.enemies).toHaveLength(0) |
| 20 | // The report went on 3 turns past that moment, then waits. |
| 21 | expect(script.old.slice(0, 3)).toEqual(record.actions.slice(-3)) |
| 22 | }) |
| 23 | |
| 24 | it('shows today\'s autopilot keeping its life where the report lost one', () => { |
| 25 | expect(script.oldEnd.lives).toBeLessThan(script.newEnd.lives) |
| 26 | expect(script.newEnd.lives).toBe(replay({ ...record, actions: record.actions.slice(0, 287) }).lives) |
| 27 | }) |
| 28 | |
| 29 | it('runs with the rules of today', () => { |
| 30 | expect(script.versionMismatch).toBe(false) |
| 31 | }) |
| 32 | }) |