@@ -110,13 +110,20 @@ describe("Dijkstra's Shortest Path Algorithm", function () {
110110describe ( 'addWeightFunction' , ( ) => {
111111 it ( 'should return edgeWeight if currentPathWeight is undefined' , ( ) => {
112112 const graph = new Graph ( ) ;
113- const params = { edgeWeight : 5 , currentPathWeight : undefined , hop : 1 , sourceGraph : graph } ;
113+ const params = {
114+ edgeWeight : 5 , currentPathWeight : undefined , hop : 1 ,
115+ graph : graph , path : { d : new Map ( ) , p : new Map ( ) , q : new Set ( ) } ,
116+ previousNode : 'a' , currentNode : 'b'
117+ } ;
114118 expect ( addWeightFunction ( params ) ) . toBe ( 5 ) ;
115119 } ) ;
116120
117121 it ( 'should return the sum of edgeWeight and currentPathWeight' , ( ) => {
118122 const graph = new Graph ( )
119- const params = { edgeWeight : 5 , currentPathWeight : 10 , hop : 1 , sourceGraph : graph } ;
123+ const params = { edgeWeight : 5 , currentPathWeight : 10 , hop : 1 ,
124+ graph : graph , path : { d : new Map ( ) , p : new Map ( ) , q : new Set ( ) } ,
125+ previousNode : 'a' , currentNode : 'b'
126+ } ;
120127 expect ( addWeightFunction ( params ) ) . toBe ( 15 ) ;
121128 } ) ;
122129} ) ;
@@ -156,8 +163,22 @@ describe('shortestPath with custom weight functions', () => {
156163 const graph = new Graph ( ) . addEdge ( 'a' , 'b' , 1 ) . addEdge ( 'b' , 'c' , 2 ) ;
157164 shortestPath ( graph , 'a' , 'c' , customWeightFn ) ;
158165
159- expect ( customWeightFn ) . toHaveBeenCalledWith ( { edgeWeight : 2 , currentPathWeight : undefined , hop : 1 , sourceGraph : graph } ) ;
160- expect ( customWeightFn ) . toHaveBeenCalledWith ( { edgeWeight : 1 , currentPathWeight : 2 , hop : 2 , sourceGraph : graph } ) ;
166+ expect ( customWeightFn ) . toHaveBeenCalledWith ( { edgeWeight : 2 , currentPathWeight : undefined , hop : 1 ,
167+ graph : graph , currentNode : 'b' , previousNode : 'c' ,
168+ path : {
169+ d : new Map ( [ [ 'a' , 0 ] , [ 'b' , 1 ] , [ 'c' , 3 ] ] ) ,
170+ p : new Map ( [ [ 'b' , 'a' ] , [ 'c' , 'b' ] ] ) ,
171+ q : new Set ( ) ,
172+ } ,
173+ } ) ;
174+ expect ( customWeightFn ) . toHaveBeenCalledWith ( { edgeWeight : 1 , currentPathWeight : 2 , hop : 2 ,
175+ graph : graph , currentNode : 'a' , previousNode : 'b' ,
176+ path : {
177+ d : new Map ( [ [ 'a' , 0 ] , [ 'b' , 1 ] , [ 'c' , 3 ] ] ) ,
178+ p : new Map ( [ [ 'b' , 'a' ] , [ 'c' , 'b' ] ] ) ,
179+ q : new Set ( ) ,
180+ }
181+ } ) ;
161182 } ) ;
162183
163184 it ( 'should compute shortest path with a custom weight function in a graph with multiple paths' , ( ) => {
0 commit comments