@@ -72,14 +72,23 @@ describe('topologicalSort', () => {
7272 } ) ;
7373
7474 it ( 'Should exclude source nodes with a cycle.' , function ( ) {
75- const graph = new Graph ( ) . addEdge ( 'a' , 'b' ) . addEdge ( 'b' , 'c' ) . addEdge ( 'c' , 'a' ) ;
75+ const graph = new Graph < string , { type : string } > ( ) ;
76+ graph
77+ . addEdge ( 'a' , 'b' , undefined , { type : 'foo' } )
78+ . addEdge ( 'b' , 'c' , undefined , { type : 'foo' } )
79+ . addEdge ( 'c' , 'a' , undefined , { type : 'bar' } ) ;
80+
7681 const sorted = topologicalSort ( graph , {
7782 sourceNodes : [ 'a' ] ,
78- includeSourceNodes : false ,
83+ includeSourceNodes : true ,
84+ shouldFollow : ( source , target ) =>
85+ graph . getEdgeProperties ( source , target ) . type === 'foo' ,
7986 } ) ;
80- expect ( sorted . length ) . toEqual ( 2 ) ;
81- expect ( sorted [ 0 ] ) . toEqual ( 'b' ) ;
82- expect ( sorted [ 1 ] ) . toEqual ( 'c' ) ;
87+
88+ expect ( sorted . length ) . toEqual ( 3 ) ;
89+ expect ( sorted [ 0 ] ) . toEqual ( 'a' ) ;
90+ expect ( sorted [ 1 ] ) . toEqual ( 'b' ) ;
91+ expect ( sorted [ 2 ] ) . toEqual ( 'c' ) ;
8392 } ) ;
8493
8594 it ( 'Should exclude source nodes with multiple cycles.' , function ( ) {
0 commit comments