import { expect, test } from "bun:test"; import { makeGrid } from "./grid.ts"; const LINES = ["#########", "#.......#", "#.##.##.#", "#.......#", "#########"]; const cells = (g: ReturnType) => g.cellsOf("."); test("many distances to one fixed target build one field", () => { const g = makeGrid(LINES, 10); const target = cells(g)[0]!; for (const from of cells(g)) g.walkDistance(from, target); expect(g.fieldsBuilt()).toBe(1); }); test("varying the target builds a field per target", () => { const g = makeGrid(LINES, 10); const from = cells(g)[0]!; for (const to of cells(g)) g.walkDistance(from, to); expect(g.fieldsBuilt()).toBe(cells(g).length); }); test("pathStep shares the field walkDistance built for the goal", () => { const g = makeGrid(LINES, 10); const goal = cells(g).at(-1)!; for (const from of cells(g)) { g.walkDistance(from, goal); g.pathStep(from, goal); } expect(g.fieldsBuilt()).toBe(1); }); test("walk distance is symmetric, so swapping the arguments is safe", () => { const g = makeGrid(LINES, 10); for (const a of cells(g)) for (const b of cells(g)) expect(g.walkDistance(a, b)).toBe(g.walkDistance(b, a)); }); test("clearPaths forgets the fields, so the next ask builds again", () => { const g = makeGrid(LINES, 10); const [a, b] = cells(g); g.walkDistance(a!, b!); g.clearPaths(); g.walkDistance(a!, b!); expect(g.fieldsBuilt()).toBe(2); });