sim
This commit is contained in:
parent
746d218eda
commit
e590baf28d
44 changed files with 8308 additions and 0 deletions
33
sim/test/map.test.ts
Normal file
33
sim/test/map.test.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { test } from 'node:test';
|
||||
import { GRID, LINES, LINES_AT, LOCATIONS, levelFor, otherEnd } from '../src/map.ts';
|
||||
|
||||
const RULES_MD = readFileSync(new URL('../../rules.md', import.meta.url), 'utf8');
|
||||
|
||||
test('24 lines, 20 of them with gateways', () => {
|
||||
assert.equal(LINES.length, 24);
|
||||
assert.equal(LINES.filter((l) => l.gateway).length, 20);
|
||||
});
|
||||
|
||||
test('adjacency matches the table in rules.md', () => {
|
||||
const table = RULES_MD.split('### Adjacency')[1].split('###')[0];
|
||||
const rows = [...table.matchAll(/^\| (S1|S2|[A-E]\d) \| ([^|]+) \|$/gm)];
|
||||
assert.equal(rows.length, LOCATIONS.length);
|
||||
for (const [, loc, list] of rows) {
|
||||
const expected = list.split(',').map((x) => x.trim()).sort();
|
||||
const actual = LINES_AT.get(loc)!.map((l) => otherEnd(l, loc)).sort();
|
||||
assert.deepEqual(actual, expected, loc);
|
||||
}
|
||||
});
|
||||
|
||||
test('levels are mirrored between the players', () => {
|
||||
const mirror = (loc: string) => ({ A: 'E', B: 'D', C: 'C', D: 'B', E: 'A' })[loc[0]]! + loc[1];
|
||||
for (const loc of GRID) assert.equal(levelFor(0, loc), levelFor(1, mirror(loc)), loc);
|
||||
assert.equal(levelFor(0, 'S1'), 1);
|
||||
assert.equal(levelFor(0, 'A2'), 2);
|
||||
assert.equal(levelFor(0, 'B1'), 2);
|
||||
assert.equal(levelFor(0, 'C2'), 3);
|
||||
assert.equal(levelFor(0, 'D1'), 4);
|
||||
assert.equal(levelFor(0, 'E3'), 5);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue