You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
2.0 KiB
62 lines
2.0 KiB
import { describe, expect, it } from "vitest";
|
|
import { shortestPathLength } from "../../src/game/chase/hexGraph";
|
|
import { generateChaseRound } from "../../src/game/chase/generator";
|
|
import type { Difficulty } from "../../src/game/chase/types";
|
|
|
|
describe("chase round generator", () => {
|
|
it("is deterministic for same seed and difficulty", () => {
|
|
const options = { seed: 20260426, difficulty: "normal" as Difficulty };
|
|
const roundA = generateChaseRound(options);
|
|
const roundB = generateChaseRound(options);
|
|
|
|
expect(roundA).toEqual(roundB);
|
|
});
|
|
|
|
it("matches golden snapshot for fixed seed", () => {
|
|
const round = generateChaseRound({ seed: 424242, difficulty: "easy" });
|
|
|
|
expect({
|
|
startNodeId: round.startNodeId,
|
|
exitNodeId: round.exitNodeId,
|
|
hasEscapePath: round.meta.hasEscapePath,
|
|
nodeCount: Object.keys(round.graph.nodes).length,
|
|
edgeCount: round.graph.edgeList.length,
|
|
firstFiveNodeIds: Object.keys(round.graph.nodes).slice(0, 5),
|
|
}).toMatchInlineSnapshot(`
|
|
{
|
|
"edgeCount": 19,
|
|
"exitNodeId": "0,-1",
|
|
"firstFiveNodeIds": [
|
|
"0,0",
|
|
"1,-1",
|
|
"2,-2",
|
|
"2,-1",
|
|
"1,-2",
|
|
],
|
|
"hasEscapePath": true,
|
|
"nodeCount": 20,
|
|
"startNodeId": "4,-5",
|
|
}
|
|
`);
|
|
});
|
|
|
|
it("generates graph node count between 20 and 30", () => {
|
|
const round = generateChaseRound({ seed: 11, difficulty: "normal" });
|
|
const nodeCount = Object.keys(round.graph.nodes).length;
|
|
expect(nodeCount).toBeGreaterThanOrEqual(20);
|
|
expect(nodeCount).toBeLessThanOrEqual(30);
|
|
});
|
|
|
|
it("ensures an escape path exists", () => {
|
|
const round = generateChaseRound({ seed: 99, difficulty: "hard" });
|
|
const pathLength = shortestPathLength(
|
|
round.graph,
|
|
round.startNodeId,
|
|
round.exitNodeId,
|
|
);
|
|
|
|
expect(round.meta.hasEscapePath).toBe(true);
|
|
expect(pathLength).toBeGreaterThan(0);
|
|
expect(pathLength).toBeLessThan(Infinity);
|
|
});
|
|
});
|
|
|