From e6f5a570a8811524f4f7cba822aeb07d56d5dd5d Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Thu, 13 Nov 2025 17:29:00 -0800 Subject: [PATCH] Fix: Make graph truly bidirectional as stated --- tests/1_dijkstra/test.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/1_dijkstra/test.js b/tests/1_dijkstra/test.js index 0ea62f3..ddc5b41 100644 --- a/tests/1_dijkstra/test.js +++ b/tests/1_dijkstra/test.js @@ -4,18 +4,20 @@ export default { // - The function must accept a graph, a start node, and an end node. // - You MUST use a dynamic import() to load the 'js-priority-queue' library from a CDN for the priority queue. // - The function should return the total weight of the shortest path, or Infinity if no path exists. -// - Graph format: { 'A': { 'B': 1, 'C': 4 }, 'B': { ... }, ... }`, +// - Graph format: { 'A': { 'B': 1, 'C': 4 }, 'B': { 'A': 1, ... }, ... } (edges are bidirectional, both directions listed)`, runTest: async (findShortestPath) => { const assert = { strictEqual: (a, e, m) => { if (a !== e) throw new Error(m || `FAIL: ${a} !== ${e}`) }, }; const graph = { - A: { B: 2, C: 5 }, B: { A: 2, C: 6, D: 1, E: 3 }, C: { A: 5, B: 6, F: 8 }, - D: { B: 1, E: 4 }, E: { B: 3, D: 4, F: 2 }, F: { C: 8, E: 2 } + A: { B: 2, C: 5 }, + B: { A: 2, C: 6, D: 1, E: 3 }, + C: { A: 5, B: 6, F: 8 }, + D: { B: 1, E: 4 }, + E: { B: 3, D: 4, F: 2 }, + F: { C: 8, E: 2 } }; const dist = await findShortestPath(graph, 'A', 'F'); assert.strictEqual(dist, 7, "Test Failed: Path A to F should be 7."); } }; - -