File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -245,6 +245,23 @@ describe('Graph', () => {
245
245
assert . deepStrictEqual ( inst . getNeighbours ( 3 ) , [ '4' ] ) ;
246
246
} ) ;
247
247
248
+ it ( 'should check if edge is removed for directed graphs' , ( ) => {
249
+ const graph = new Graph ( true ) ;
250
+
251
+ graph . addVertex ( 1 ) ;
252
+ graph . addVertex ( 2 ) ;
253
+
254
+ graph . addEdge ( 1 , 2 ) ;
255
+
256
+ assert . deepStrictEqual ( graph . getNeighbours ( 1 ) , [ '2' ] ) ;
257
+ assert . deepStrictEqual ( graph . getNeighbours ( 2 ) , [ ] ) ;
258
+
259
+ graph . removeEdge ( 1 , 2 ) ;
260
+
261
+ assert . deepStrictEqual ( graph . getNeighbours ( 1 ) , [ ] ) ;
262
+ assert . deepStrictEqual ( graph . getNeighbours ( 2 ) , [ ] ) ;
263
+ } ) ;
264
+
248
265
it ( 'should check if vertex is removed' , ( ) => {
249
266
const inst = new Graph ( ) ;
250
267
@@ -271,4 +288,12 @@ describe('Graph', () => {
271
288
assert . deepStrictEqual ( inst . getNeighbours ( 1 ) , [ '2' , '3' ] ) ;
272
289
assert . deepStrictEqual ( inst . getNeighbours ( 3 ) , [ '1' ] ) ;
273
290
} ) ;
291
+
292
+ it ( 'should throw an error when trying to remove a non-existing vertex' , ( ) => {
293
+ const graph = new Graph ( ) ;
294
+
295
+ graph . addVertex ( 1 ) ;
296
+
297
+ assert . throws ( ( ) => graph . removeVertex ( 2 ) , / V e r t i x 2 d o e s n o t e x i s t / ) ;
298
+ } ) ;
274
299
} ) ;
You can’t perform that action at this time.
0 commit comments