3 var expect = require('expect.js');
4 var dijkstra = require('../dijkstra.js');
5 var find_path = dijkstra.find_path;
7 describe('dijkstra.js', function () {
9 describe('.find_path()', function () {
11 it('should find the path between two points, all edges have weight 1', function () {
17 b: {a: 1, c: 1, e: 1},
19 d: {a: 1, e: 1, g: 1},
20 e: {b: 1, d: 1, f: 1, h: 1},
21 f: {c: 1, e: 1, i: 1},
23 h: {e: 1, g: 1, i: 1},
26 var path = find_path(graph, 'a', 'i');
27 expect(path).to.eql(['a', 'd', 'e', 'f', 'i']);
30 it('should find the path between two points, weighted edges', function () {
32 a: {b: 10, c: 100, d: 1},
40 var path = find_path(graph, 'a', 'c');
41 expect(path).to.eql(['a', 'd', 'e', 'f', 'c']);
42 path = find_path(graph, 'd', 'b');
43 expect(path).to.eql(['d', 'b']);
46 it('should throw on unreachable destination', function () {
48 a: {b: 10, c: 100, d: 1},
56 expect(function () { find_path(graph, 'c', 'a'); }).to.throwException();
57 expect(function () { find_path(graph, 'a', 'g'); }).to.throwException();
60 it('should throw on non-existent destination', function () {
62 a: {b: 10, c: 100, d: 1},
70 expect(function () { find_path(graph, 'a', 'z'); }).to.throwException();
74 describe('.single_source_shortest_paths()', function () {
75 it('should find all paths from a node', function () {
77 a: {b: 10, c: 100, d: 1},
86 var paths = dijkstra.single_source_shortest_paths(graph, 'a');
87 expect(paths).to.eql({