@@ -218,4 +218,47 @@ describe('Graph', () => {
218218
219219 expect ( graph . getWeight ( ) ) . toBe ( 10 ) ;
220220 } ) ;
221+
222+ it ( 'should be possible to delete edges from graph' , ( ) => {
223+ const graph = new Graph ( ) ;
224+
225+ const vertexA = new GraphVertex ( 'A' ) ;
226+ const vertexB = new GraphVertex ( 'B' ) ;
227+ const vertexC = new GraphVertex ( 'C' ) ;
228+
229+ const edgeAB = new GraphEdge ( vertexA , vertexB ) ;
230+ const edgeBC = new GraphEdge ( vertexB , vertexC ) ;
231+ const edgeAC = new GraphEdge ( vertexA , vertexC ) ;
232+
233+ graph
234+ . addEdge ( edgeAB )
235+ . addEdge ( edgeBC )
236+ . addEdge ( edgeAC ) ;
237+
238+ expect ( graph . getAllEdges ( ) . length ) . toBe ( 3 ) ;
239+
240+ graph . deleteEdge ( edgeAB ) ;
241+
242+ expect ( graph . getAllEdges ( ) . length ) . toBe ( 2 ) ;
243+ expect ( graph . getAllEdges ( ) [ 0 ] . getKey ( ) ) . toBe ( edgeBC . getKey ( ) ) ;
244+ expect ( graph . getAllEdges ( ) [ 1 ] . getKey ( ) ) . toBe ( edgeAC . getKey ( ) ) ;
245+ } ) ;
246+
247+ it ( 'should should throw an error when trying to delete not existing edge' , ( ) => {
248+ function deleteNotExistingEdge ( ) {
249+ const graph = new Graph ( ) ;
250+
251+ const vertexA = new GraphVertex ( 'A' ) ;
252+ const vertexB = new GraphVertex ( 'B' ) ;
253+ const vertexC = new GraphVertex ( 'C' ) ;
254+
255+ const edgeAB = new GraphEdge ( vertexA , vertexB ) ;
256+ const edgeBC = new GraphEdge ( vertexB , vertexC ) ;
257+
258+ graph . addEdge ( edgeAB ) ;
259+ graph . deleteEdge ( edgeBC ) ;
260+ }
261+
262+ expect ( deleteNotExistingEdge ) . toThrowError ( ) ;
263+ } ) ;
221264} ) ;
0 commit comments