UNPKG

raptor-journey-planner

Version:

Implementation of the Round bAsed Public Transit Optimized Router (Raptor) journey planning algorithm.

52 lines (51 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai = require("chai"); const StringResults_1 = require("../../../../src/transfer-pattern/results/StringResults"); describe("StringResults", () => { it("Merges duplicate paths", () => { const tree = new StringResults_1.StringResults({}); const expected = { "AB": new Set([""]), "AC": new Set(["B"]), "AD": new Set(["B,C"]) }; mergePath(["A", "B", "C", "D"], tree); mergePath(["A", "B", "C"], tree); chai.expect(tree.finalize()).to.deep.equal(expected); }); it("Orders results", () => { const tree = new StringResults_1.StringResults({}); const expected = { "AC": new Set(["B"]), "BC": new Set(["", "D"]), "CE": new Set(["B"]), "CD": new Set([""]), }; mergePath(["C", "B", "A"], tree); mergePath(["C", "D", "B"], tree); mergePath(["C", "B", "E"], tree); chai.expect(tree.finalize()).to.deep.equal(expected); }); it("Adds different paths", () => { const tree = new StringResults_1.StringResults({}); const expected = { "AC": new Set(["", "B"]), "AB": new Set(["", "C"]), "AD": new Set(["B,C", "C,B"]) }; mergePath(["A", "B", "C", "D"], tree); mergePath(["A", "C", "B", "D"], tree); chai.expect(tree.finalize()).to.deep.equal(expected); }); }); function mergePath(path, tree) { const kConnections = {}; for (let i = 1; i < path.length; i++) { const origin = path[i - 1]; const destination = path[i]; kConnections[destination] = {}; kConnections[destination][i] = [{ stopTimes: [{ stop: origin }] }, 0, 1]; } tree.add(kConnections); }