@@ -37,6 +37,39 @@ describe('GraphVertex', () => {
3737 expect ( vertexA . getEdges ( ) [ 0 ] . toString ( ) ) . toBe ( 'A_B' ) ;
3838 } ) ;
3939
40+ it ( 'should delete edges from vertex' , ( ) => {
41+ const vertexA = new GraphVertex ( 'A' ) ;
42+ const vertexB = new GraphVertex ( 'B' ) ;
43+ const vertexC = new GraphVertex ( 'C' ) ;
44+
45+ const edgeAB = new GraphEdge ( vertexA , vertexB ) ;
46+ const edgeAC = new GraphEdge ( vertexA , vertexC ) ;
47+ vertexA
48+ . addEdge ( edgeAB )
49+ . addEdge ( edgeAC ) ;
50+
51+ expect ( vertexA . hasEdge ( edgeAB ) ) . toBeTruthy ( ) ;
52+ expect ( vertexB . hasEdge ( edgeAB ) ) . toBeFalsy ( ) ;
53+
54+ expect ( vertexA . hasEdge ( edgeAC ) ) . toBeTruthy ( ) ;
55+ expect ( vertexC . hasEdge ( edgeAC ) ) . toBeFalsy ( ) ;
56+
57+ expect ( vertexA . getEdges ( ) . length ) . toBe ( 2 ) ;
58+
59+ expect ( vertexA . getEdges ( ) [ 0 ] . toString ( ) ) . toBe ( 'A_B' ) ;
60+ expect ( vertexA . getEdges ( ) [ 1 ] . toString ( ) ) . toBe ( 'A_C' ) ;
61+
62+ vertexA . deleteEdge ( edgeAB ) ;
63+ expect ( vertexA . hasEdge ( edgeAB ) ) . toBeFalsy ( ) ;
64+ expect ( vertexA . hasEdge ( edgeAC ) ) . toBeTruthy ( ) ;
65+ expect ( vertexA . getEdges ( ) [ 0 ] . toString ( ) ) . toBe ( 'A_C' ) ;
66+
67+ vertexA . deleteEdge ( edgeAC ) ;
68+ expect ( vertexA . hasEdge ( edgeAB ) ) . toBeFalsy ( ) ;
69+ expect ( vertexA . hasEdge ( edgeAC ) ) . toBeFalsy ( ) ;
70+ expect ( vertexA . getEdges ( ) . length ) . toBe ( 0 ) ;
71+ } ) ;
72+
4073 it ( 'should return vertex neighbors in case if current node is start one' , ( ) => {
4174 const vertexA = new GraphVertex ( 'A' ) ;
4275 const vertexB = new GraphVertex ( 'B' ) ;
0 commit comments