import { describe, expect, it } from "vitest"; import { generateCrosswordLayout } from "@/lib/arcade/crosswordEngine"; import { crosswordTestPack } from "@/lib/arcade/crosswordTestData"; describe("Crossword grid engine", () => { it("is deterministic and respects the selected target", () => { const pack = crosswordTestPack(); const first = generateCrosswordLayout(pack, "mini", "same-seed"); const second = generateCrosswordLayout(pack, "mini", "same-seed"); expect(second).toEqual(first); expect(first.entries).toHaveLength(15); expect(first.entries.length).toBeLessThanOrEqual(first.targetCount); expect(first.entries.length + first.omittedEntries.length).toBe(80); }); it("creates matching cells, shared intersections, and sequential clue numbers", () => { const layout = generateCrosswordLayout(crosswordTestPack(), "standard", "grid-rules"); const cellByKey = new Map(layout.cells.map((cell) => [cell.key, cell])); expect(layout.entries.length).toBeGreaterThanOrEqual(15); expect(layout.cells.some((cell) => cell.entryIds.length > 1)).toBe(true); for (const entry of layout.entries) { expect(entry.cellKeys.map((key, index) => cellByKey.get(key)?.answer === entry.answer[index]).every(Boolean)).toBe(true); expect(entry.number).toBeGreaterThan(0); } }); });