quill/val Public Public: anyone can read this; nobody can change it.
forked from benjivers/val
workbenchthis machine
Files 967e12d2fa288842a7c42ddda720f0c8a28efc34
| 1 | /** |
| 2 | * The engine's body contract, checked against this game's own snapshot rather |
| 3 | * than one a test made up: a game that renames `alive` passes every render |
| 4 | * test and draws every enemy as a corpse. It lives here, not in `engine/`, |
| 5 | * because it needs the game. |
| 6 | */ |
| 7 | |
| 8 | import { expect, test } from "bun:test"; |
| 9 | import { valGame } from "./arena.ts"; |
| 10 | import { snapshotProblems } from "./engine/body.ts"; |
| 11 | import { newMatch } from "./match.ts"; |
| 12 | |
| 13 | test("every body and `me` in a real snapshot of a running match fits the contract", () => { |
| 14 | const state = newMatch(7); |
| 15 | const game = valGame(state, () => {}); |
| 16 | for (let i = 0; i < 90; i++) game.step(state, 1 / 30); |
| 17 | let bodies = 0; |
| 18 | for (const viewer of state.players) { |
| 19 | const seen = state.players.filter((p) => p.id === viewer.id || game.visible(state, viewer, p)); |
| 20 | const snap = game.snapshot(state, viewer, seen) as { me: unknown; players: unknown[] }; |
| 21 | expect(snapshotProblems(snap)).toEqual([]); |
| 22 | bodies += snap.players.length; |
| 23 | } |
| 24 | expect(bodies).toBeGreaterThan(state.players.length); |
| 25 | }); |