|
|
|
@ -48,6 +48,17 @@ describe("hex graph utilities", () => { |
|
|
|
expect(shortestPathLength(graph, "A", "C")).toBe(Infinity); |
|
|
|
}); |
|
|
|
|
|
|
|
it("returns Infinity for invalid from/to nodes", () => { |
|
|
|
const graph = buildGraph({ |
|
|
|
A: { id: "A", q: 0, r: 0, neighbors: ["B"] }, |
|
|
|
B: { id: "B", q: 1, r: 0, neighbors: ["A"] }, |
|
|
|
}); |
|
|
|
|
|
|
|
expect(shortestPathLength(graph, "X", "X")).toBe(Infinity); |
|
|
|
expect(shortestPathLength(graph, "X", "A")).toBe(Infinity); |
|
|
|
expect(shortestPathLength(graph, "A", "X")).toBe(Infinity); |
|
|
|
}); |
|
|
|
|
|
|
|
it("checks graph connectivity", () => { |
|
|
|
const connectedGraph = buildGraph({ |
|
|
|
A: { id: "A", q: 0, r: 0, neighbors: ["B"] }, |
|
|
|
@ -64,4 +75,14 @@ describe("hex graph utilities", () => { |
|
|
|
expect(isConnected(connectedGraph)).toBe(true); |
|
|
|
expect(isConnected(disconnectedGraph)).toBe(false); |
|
|
|
}); |
|
|
|
|
|
|
|
it("treats empty and single-node graph as connected", () => { |
|
|
|
const emptyGraph = buildGraph({}); |
|
|
|
const singleNodeGraph = buildGraph({ |
|
|
|
A: { id: "A", q: 0, r: 0, neighbors: [] }, |
|
|
|
}); |
|
|
|
|
|
|
|
expect(isConnected(emptyGraph)).toBe(true); |
|
|
|
expect(isConnected(singleNodeGraph)).toBe(true); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|