Skip to content

Commit 9b7ec5a

Browse files
authored
feat: Add shortestPaths output array (#37)
1 parent 782e09b commit 9b7ec5a

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/bmssp.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class BMSSP {
44
this.graph = [];
55
// Set to store unique node IDs
66
this.nodeIDs = new Set();
7+
// Array to store shortest paths
8+
this.shortestPaths = [];
79

810
for (let edge of inputGraph) {
911
// Create a deep copy of each edge array
@@ -12,6 +14,11 @@ class BMSSP {
1214
this.nodeIDs.add(edge[0]);
1315
this.nodeIDs.add(edge[1]);
1416
}
17+
18+
// Initialize shortest paths with Infinity on each nodeID (after all nodes are collected)
19+
for (let nodeId of this.nodeIDs) {
20+
this.shortestPaths.push([nodeId, Infinity]);
21+
}
1522
}
1623
}
1724

test/main.test.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,14 @@ describe("BMSSP nodeIDs", () => {
3737
expect(myBMSSP.nodeIDs).toEqual(uniqueNodeIDs);
3838
});
3939
});
40+
41+
describe("BMSSP shortestPaths", () => {
42+
test("initializes shortest paths with Infinity", () => {
43+
const myBMSSP = new BMSSP(roadNetCA);
44+
const expectedShortestPaths = [];
45+
myBMSSP.nodeIDs.forEach((nodeId) => {
46+
expectedShortestPaths.push([nodeId, Infinity]);
47+
});
48+
expect(myBMSSP.shortestPaths).toEqual(expectedShortestPaths);
49+
});
50+
});

0 commit comments

Comments
 (0)