diff --git a/src/bmssp.mjs b/src/bmssp.mjs index 13c7343..85b74a9 100644 --- a/src/bmssp.mjs +++ b/src/bmssp.mjs @@ -4,6 +4,8 @@ class BMSSP { this.graph = []; // Set to store unique node IDs this.nodeIDs = new Set(); + // Array to store shortest paths + this.shortestPaths = []; for (let edge of inputGraph) { // Create a deep copy of each edge array @@ -12,6 +14,11 @@ class BMSSP { this.nodeIDs.add(edge[0]); this.nodeIDs.add(edge[1]); } + + // Initialize shortest paths with Infinity on each nodeID (after all nodes are collected) + for (let nodeId of this.nodeIDs) { + this.shortestPaths.push([nodeId, Infinity]); + } } } diff --git a/test/main.test.mjs b/test/main.test.mjs index 37b9522..ab2efe7 100644 --- a/test/main.test.mjs +++ b/test/main.test.mjs @@ -37,3 +37,14 @@ describe("BMSSP nodeIDs", () => { expect(myBMSSP.nodeIDs).toEqual(uniqueNodeIDs); }); }); + +describe("BMSSP shortestPaths", () => { + test("initializes shortest paths with Infinity", () => { + const myBMSSP = new BMSSP(roadNetCA); + const expectedShortestPaths = []; + myBMSSP.nodeIDs.forEach((nodeId) => { + expectedShortestPaths.push([nodeId, Infinity]); + }); + expect(myBMSSP.shortestPaths).toEqual(expectedShortestPaths); + }); +});