File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 11class 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}
Original file line number Diff line number Diff 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+ } ) ;
You can’t perform that action at this time.
0 commit comments