Skip to content

Commit d0a1358

Browse files
committed
Add basic tests for bellman ford
1 parent 28b5d0f commit d0a1358

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
var exported =
2+
require('../../../src/graphs/shortest-path/bellman-ford'),
3+
bellmanFord = exported.bellmanFord,
4+
Vertex = exported.Vertex,
5+
Edge = exported.Edge;
6+
7+
describe('Bellman-Ford', function () {
8+
'use strict';
9+
it('should exports a method called bellmanFord', function () {
10+
expect(typeof bellmanFord).toBe('function');
11+
});
12+
13+
it('should work for an empty graph', function () {
14+
var vs = [];
15+
var e = [];
16+
expect(bellmanFord(vs, e, undefined))
17+
.toEqual({ parents: {}, distances: { undefined: 0 } });
18+
});
19+
20+
it('should work for a graph with a single vertex', function () {
21+
var vs = [new Vertex(1)];
22+
var e = [];
23+
expect(bellmanFord(vs, e, 1))
24+
.toEqual({ parents: { '1': null }, distances: { '1': 0 }});
25+
});
26+
27+
it('should work in the general case', function () {
28+
var vs = [new Vertex(1), new Vertex(2), new Vertex(3)];
29+
var e = [];
30+
expect(bellmanFord(vs, e, 1))
31+
.toEqual({ parents: { '1': null }, distances: { '1': 0 }});
32+
});
33+
});

0 commit comments

Comments
 (0)