@@ -378,7 +378,7 @@ describe("Graph", function () {
378378 var graph = Graph ( ) . addEdge ( "a" , "b" ) . addEdge ( "b" , "c" ) ;
379379 assert . deepEqual (
380380 graph . shortestPath ( "a" , "c" ) ,
381- withWeight ( [ "a" , "b" , "c" ] , 2 )
381+ withWeight ( [ "a" , "b" , "c" ] , 2 ) ,
382382 ) ;
383383 } ) ;
384384
@@ -396,11 +396,11 @@ describe("Graph", function () {
396396
397397 assert . deepEqual (
398398 graph . shortestPath ( "s" , "z" ) ,
399- withWeight ( [ "s" , "y" , "z" ] , 5 + 2 )
399+ withWeight ( [ "s" , "y" , "z" ] , 5 + 2 ) ,
400400 ) ;
401401 assert . deepEqual (
402402 graph . shortestPath ( "s" , "x" ) ,
403- withWeight ( [ "s" , "y" , "t" , "x" ] , 5 + 3 + 1 )
403+ withWeight ( [ "s" , "y" , "t" , "x" ] , 5 + 3 + 1 ) ,
404404 ) ;
405405 } ) ;
406406
@@ -423,11 +423,11 @@ describe("Graph", function () {
423423 var graph = Graph ( ) . addEdge ( "a" , "b" ) . addEdge ( "b" , "c" ) . addEdge ( "d" , "e" ) ;
424424 assert . deepEqual (
425425 graph . shortestPath ( "a" , "c" ) ,
426- withWeight ( [ "a" , "b" , "c" ] , 2 )
426+ withWeight ( [ "a" , "b" , "c" ] , 2 ) ,
427427 ) ;
428428 } ) ;
429429
430- it ( "Should compute shortest paths on six edges ." , function ( ) {
430+ it ( "Should compute shortest paths." , function ( ) {
431431 var graph = Graph ( )
432432 . addEdge ( "a" , "b" )
433433 . addEdge ( "b" , "c" )
@@ -436,14 +436,21 @@ describe("Graph", function () {
436436 . addEdge ( "a" , "e" )
437437 . addEdge ( "e" , "f" )
438438 . addEdge ( "f" , "c" ) ;
439+ const serializedGraph = graph . serialize ( ) ;
439440 assert . deepEqual ( graph . shortestPaths ( "a" , "c" ) , [
440441 withWeight ( [ "a" , "b" , "c" ] , 2 ) ,
441442 withWeight ( [ "a" , "d" , "c" ] , 2 ) ,
442443 ] ) ;
443- // need to check nodes are still present because we remove them to get all shortest paths
444- const nodes = [ "a" , "b" , "c" , "d" , "e" , "f" ] ;
445- assert . equal ( graph . nodes ( ) . length , nodes . length ) ;
446- nodes . forEach ( ( node ) => assert ( contains ( graph . nodes ( ) , node ) ) ) ;
444+ // check graph has not changed
445+ const postSerializedGraph = graph . serialize ( ) ;
446+ assert . equal (
447+ postSerializedGraph . links . length ,
448+ serializedGraph . links . length ,
449+ ) ;
450+ assert . equal (
451+ postSerializedGraph . nodes . length ,
452+ serializedGraph . nodes . length ,
453+ ) ;
447454 } ) ;
448455 } ) ;
449456
@@ -458,11 +465,7 @@ describe("Graph", function () {
458465} ) ;
459466
460467function contains ( arr , item ) {
461- return (
462- arr . filter ( function ( d ) {
463- return d === item ;
464- } ) . length > 0
465- ) ;
468+ return arr . includes ( item ) ;
466469}
467470
468471function comesBefore ( arr , a , b ) {
0 commit comments