@@ -109,12 +109,14 @@ describe("Dijkstra's Shortest Path Algorithm", function () {
109109
110110describe ( 'addWeightFunction' , ( ) => {
111111 it ( 'should return edgeWeight if currentPathWeight is undefined' , ( ) => {
112- const params = { edgeWeight : 5 , currentPathWeight : undefined , hop : 1 } ;
112+ const graph = new Graph ( ) ;
113+ const params = { edgeWeight : 5 , currentPathWeight : undefined , hop : 1 , sourceGraph : graph } ;
113114 expect ( addWeightFunction ( params ) ) . toBe ( 5 ) ;
114115 } ) ;
115116
116117 it ( 'should return the sum of edgeWeight and currentPathWeight' , ( ) => {
117- const params = { edgeWeight : 5 , currentPathWeight : 10 , hop : 1 } ;
118+ const graph = new Graph ( )
119+ const params = { edgeWeight : 5 , currentPathWeight : 10 , hop : 1 , sourceGraph : graph } ;
118120 expect ( addWeightFunction ( params ) ) . toBe ( 15 ) ;
119121 } ) ;
120122} ) ;
@@ -154,8 +156,8 @@ describe('shortestPath with custom weight functions', () => {
154156 const graph = new Graph ( ) . addEdge ( 'a' , 'b' , 1 ) . addEdge ( 'b' , 'c' , 2 ) ;
155157 shortestPath ( graph , 'a' , 'c' , customWeightFn ) ;
156158
157- expect ( customWeightFn ) . toHaveBeenCalledWith ( { edgeWeight : 2 , currentPathWeight : undefined , hop : 1 } ) ;
158- expect ( customWeightFn ) . toHaveBeenCalledWith ( { edgeWeight : 1 , currentPathWeight : 2 , hop : 2 } ) ;
159+ expect ( customWeightFn ) . toHaveBeenCalledWith ( { edgeWeight : 2 , currentPathWeight : undefined , hop : 1 , sourceGraph : graph } ) ;
160+ expect ( customWeightFn ) . toHaveBeenCalledWith ( { edgeWeight : 1 , currentPathWeight : 2 , hop : 2 , sourceGraph : graph } ) ;
159161 } ) ;
160162
161163 it ( 'should compute shortest path with a custom weight function in a graph with multiple paths' , ( ) => {
0 commit comments