Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/bmssp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]);
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/main.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});