Skip to content

Commit 782e09b

Browse files
authored
feat(constructor): Add nodeIDs set (#34)
1 parent a83b354 commit 782e09b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/bmssp.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
class BMSSP {
22
constructor(inputGraph) {
3+
// Main graph represented as an array of edges
34
this.graph = [];
5+
// Set to store unique node IDs
6+
this.nodeIDs = new Set();
7+
48
for (let edge of inputGraph) {
59
// Create a deep copy of each edge array
610
this.graph.push([...edge]);
11+
// Add node IDs to the set
12+
this.nodeIDs.add(edge[0]);
13+
this.nodeIDs.add(edge[1]);
714
}
815
}
916
}

test/main.test.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,15 @@ describe("BMSSP constructor", () => {
2525
expect(myBMSSP.graph).toEqual(roadNetCA);
2626
});
2727
});
28+
29+
describe("BMSSP nodeIDs", () => {
30+
test("stores unique node IDs correctly", () => {
31+
const myBMSSP = new BMSSP(roadNetCA);
32+
const uniqueNodeIDs = new Set();
33+
roadNetCA.forEach((edge) => {
34+
uniqueNodeIDs.add(edge[0]);
35+
uniqueNodeIDs.add(edge[1]);
36+
});
37+
expect(myBMSSP.nodeIDs).toEqual(uniqueNodeIDs);
38+
});
39+
});

0 commit comments

Comments
 (0)