Skip to content

Commit e29c323

Browse files
authored
Add graph tests, bring coverage to 100% (#38)
2 parents 51fe89e + f38f51a commit e29c323

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/data-structures/testGraph.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,23 @@ describe('Graph', () => {
245245
assert.deepStrictEqual(inst.getNeighbours(3), ['4']);
246246
});
247247

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+
248265
it('should check if vertex is removed', () => {
249266
const inst = new Graph();
250267

@@ -271,4 +288,12 @@ describe('Graph', () => {
271288
assert.deepStrictEqual(inst.getNeighbours(1), ['2', '3']);
272289
assert.deepStrictEqual(inst.getNeighbours(3), ['1']);
273290
});
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), /Vertix 2 does not exist/);
298+
});
274299
});

0 commit comments

Comments
 (0)