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
@@ -1,9 +1,16 @@
class BMSSP {
constructor(inputGraph) {
// Main graph represented as an array of edges
this.graph = [];
// Set to store unique node IDs
this.nodeIDs = new Set();

for (let edge of inputGraph) {
// Create a deep copy of each edge array
this.graph.push([...edge]);
// Add node IDs to the set
this.nodeIDs.add(edge[0]);
this.nodeIDs.add(edge[1]);
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/main.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ describe("BMSSP constructor", () => {
expect(myBMSSP.graph).toEqual(roadNetCA);
});
});

describe("BMSSP nodeIDs", () => {
test("stores unique node IDs correctly", () => {
const myBMSSP = new BMSSP(roadNetCA);
const uniqueNodeIDs = new Set();
roadNetCA.forEach((edge) => {
uniqueNodeIDs.add(edge[0]);
uniqueNodeIDs.add(edge[1]);
});
expect(myBMSSP.nodeIDs).toEqual(uniqueNodeIDs);
});
});