Skip to content

Commit 665559b

Browse files
committed
feat: Add shortestPaths output array
1 parent 782e09b commit 665559b

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,13 +4,20 @@ 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
1012
this.graph.push([...edge]);
1113
// Add node IDs to the set
1214
this.nodeIDs.add(edge[0]);
1315
this.nodeIDs.add(edge[1]);
16+
17+
// Initialize shortest paths with Infinity on each nodeID
18+
for (let nodeId of this.nodeIDs) {
19+
this.shortestPaths.push([nodeId, Infinity]);
20+
}
1421
}
1522
}
1623
}

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)