[hotfix] Ignore type checking for edge
[platform/framework/web/wrtjs.git] / device_home / node_modules / dijkstrajs / test / dijkstra.test.js
1 "use strict";var expect=require("expect.js"),dijkstra=require("../dijkstra.js"),find_path=dijkstra.find_path;describe("dijkstra.js",(function(){describe(".find_path()",(function(){it("should find the path between two points, all edges have weight 1",(function(){var e=find_path({a:{b:10,d:1},b:{a:1,c:1,e:1},c:{b:1,f:1},d:{a:1,e:1,g:1},e:{b:1,d:1,f:1,h:1},f:{c:1,e:1,i:1},g:{d:1,h:1},h:{e:1,g:1,i:1},i:{f:1,h:1}},"a","i");expect(e).to.eql(["a","d","e","f","i"])})),it("should find the path between two points, weighted edges",(function(){var e={a:{b:10,c:100,d:1},b:{c:10},d:{b:1,e:1},e:{f:1},f:{c:1},g:{b:1}},t=find_path(e,"a","c");expect(t).to.eql(["a","d","e","f","c"]),t=find_path(e,"d","b"),expect(t).to.eql(["d","b"])})),it("should throw on unreachable destination",(function(){var e={a:{b:10,c:100,d:1},b:{c:10},d:{b:1,e:1},e:{f:1},f:{c:1},g:{b:1}};expect((function(){find_path(e,"c","a")})).to.throwException(),expect((function(){find_path(e,"a","g")})).to.throwException()})),it("should throw on non-existent destination",(function(){var e={a:{b:10,c:100,d:1},b:{c:10},d:{b:1,e:1},e:{f:1},f:{c:1},g:{b:1}};expect((function(){find_path(e,"a","z")})).to.throwException()}))})),describe(".single_source_shortest_paths()",(function(){it("should find all paths from a node",(function(){var e=dijkstra.single_source_shortest_paths({a:{b:10,c:100,d:1},b:{c:10},d:{b:1,e:1},e:{f:1},f:{c:1},g:{b:1}},"a");expect(e).to.eql({d:"a",b:"d",e:"d",f:"e",c:"f"})}))}))}));