From b53a6f2d25ac4458340115f671959cc25a508537 Mon Sep 17 00:00:00 2001 From: Catatomik Date: Thu, 16 Oct 2025 22:11:15 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A7=F0=9F=90=9B=20Force=20jest=20t?= =?UTF-8?q?ests=20root?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jest.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 7530fcb..134cee4 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,7 +6,8 @@ const tsJestTransformCfg = createDefaultPreset().transform; module.exports = { collectCoverageFrom: ["src/**/*.ts"], coverageReporters: ["text", "lcov", "json-summary"], - testMatch: ["**/test/**/*.test.ts"], + // Using https://jestjs.io/docs/configuration#rootdir-string + testMatch: ["/test/**/*.test.ts"], testEnvironment: "node", transform: { ...tsJestTransformCfg, From 7edc8580987331e2133c49c38867ca2cffed3cbd Mon Sep 17 00:00:00 2001 From: Catatomik Date: Thu, 16 Oct 2025 22:11:56 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=9A=A7=20Use=20interface=20implementa?= =?UTF-8?q?tion=20for=20common=20public=20RAPTOR=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/McRAPTOR.ts | 13 +++++-------- src/RAPTOR.ts | 4 ++-- src/base.ts | 31 +++++++++++++++++++------------ test/McSharedRAPTOR.test.ts | 6 +++--- test/SharedRAPTOR.test.ts | 7 +++++-- test/assets/asset.d.ts | 6 +++--- test/assets/utils.ts | 4 ++-- test/base.test.ts | 4 ---- 8 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/McRAPTOR.ts b/src/McRAPTOR.ts index 2b758b4..669a5ae 100644 --- a/src/McRAPTOR.ts +++ b/src/McRAPTOR.ts @@ -1,14 +1,11 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ -import BaseRAPTOR from "./base"; +import BaseRAPTOR, { IRAPTOR } from "./base"; import { Bag, Criterion, Id, IRAPTORData, IStop, Journey, JourneyStep, Label, makeJSComparable, Route } from "./structures"; -export default class McRAPTOR extends BaseRAPTOR< - TimeVal, - SI, - RI, - V, - CA -> { +export default class McRAPTOR + extends BaseRAPTOR + implements IRAPTOR +{ /** @description A {@link Label} Bags_i(SI) stores earliest known arrival times and best values for criteria at stop `SI` with up to `i` trips. */ protected bags: Map>>[] = []; diff --git a/src/RAPTOR.ts b/src/RAPTOR.ts index 4f8b3d6..963a1bb 100644 --- a/src/RAPTOR.ts +++ b/src/RAPTOR.ts @@ -1,11 +1,11 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ -import BaseRAPTOR from "./base"; +import BaseRAPTOR, { IRAPTOR } from "./base"; import { Id, IStop, Journey, JourneyStep, Label, makeJSComparable, Route } from "./structures"; /** * @description A RAPTOR instance */ -export default class RAPTOR extends BaseRAPTOR { +export default class RAPTOR extends BaseRAPTOR implements IRAPTOR { /** @description A {@link Label} Ti(SI) represents the earliest known arrival time at stop SI with up to i trips. */ protected multiLabel: Map>[] = []; diff --git a/src/base.ts b/src/base.ts index 6543f2f..48b83f8 100644 --- a/src/base.ts +++ b/src/base.ts @@ -8,11 +8,28 @@ interface RAPTORRunSettings { maxTransferLength: number; } +interface IRAPTOR { + /** + * Run a RAPTOR query + * @param ps Query source + * @param pt Query target ; can be `null` to set query mode to "One-To-All". + */ + run(ps: SI, pt: SI | null, departureTime: TimeVal, settings: RAPTORRunSettings, rounds: number): void; + /** + * Get best journeys from a target stop {@link pt} after running the algorithm with {@link run}. + * @param pt Target stop to get best journeys to + * @returns A list of journeys for each round. + */ + getBestJourneys(pt: SI): Journey[][]; +} + /** * @description A RAPTOR instance * @template TimeVal Time representation internal type, its full type is {@link Time}. */ -export default class BaseRAPTOR { +export default class BaseRAPTOR + implements Pick, "run"> +{ static defaultRounds = 6; protected runParams: { @@ -115,11 +132,6 @@ export default class BaseRAPTOR[][] { - throw new Error("Not implemented"); - } } -export type { RAPTORRunSettings }; +export type { IRAPTOR, RAPTORRunSettings }; diff --git a/test/McSharedRAPTOR.test.ts b/test/McSharedRAPTOR.test.ts index d91de20..fc39515 100644 --- a/test/McSharedRAPTOR.test.ts +++ b/test/McSharedRAPTOR.test.ts @@ -14,7 +14,7 @@ import { TimeScal, Timestamp, } from "../src"; -import BaseRAPTOR from "../src/base"; +import BaseRAPTOR, { IRAPTOR } from "../src/base"; import { TestDataset } from "./assets/asset"; import BTOneLine from "./assets/BTOneLine"; import BTTwoLines from "./assets/BTTwoLines"; @@ -22,9 +22,9 @@ import FDOneLine from "./assets/FDOneLine"; import FDTwoLines from "./assets/FDTwoLines"; import oneLine from "./assets/oneLine"; import oneLineOTA from "./assets/oneLineOTA"; +import specialCases from "./assets/specialCases"; import twoLines from "./assets/twoLines"; import twoLinesOTA from "./assets/twoLinesOTA"; -import specialCases from "./assets/specialCases"; describe("McSharedRAPTOR", () => { // Same as RAPTOR @@ -46,7 +46,7 @@ describe("McSharedRAPTOR", () => { for (const journeys of res) expect(journeys.length || 1).toBe(1); test.validate( res.map((journeys) => (journeys.length ? [journeys[0]] : [])), - sharedRaptorInstance as BaseRAPTOR, + sharedRaptorInstance as BaseRAPTOR & IRAPTOR, ); } }); diff --git a/test/SharedRAPTOR.test.ts b/test/SharedRAPTOR.test.ts index 7080730..f240592 100644 --- a/test/SharedRAPTOR.test.ts +++ b/test/SharedRAPTOR.test.ts @@ -1,6 +1,6 @@ import { describe } from "@jest/globals"; import { InternalTimeInt, SharedRAPTOR, SharedRAPTORData, SharedTime, sharedTimeIntOrderLow, sharedTimeScal, TimeScal, Timestamp } from "../src"; -import BaseRAPTOR from "../src/base"; +import BaseRAPTOR, { IRAPTOR } from "../src/base"; import { TestDataset } from "./assets/asset"; import oneLine from "./assets/oneLine"; import oneLineOTA from "./assets/oneLineOTA"; @@ -23,7 +23,10 @@ describe("SharedRAPTOR", () => { for (const test of asset.tests) { sharedRaptorInstance.run(...test.params); const res = test.params[1] !== null ? sharedRaptorInstance.getBestJourneys(test.params[1]) : []; - test.validate(res, sharedRaptorInstance as BaseRAPTOR); + test.validate( + res, + sharedRaptorInstance as BaseRAPTOR & IRAPTOR, + ); } }); } diff --git a/test/assets/asset.d.ts b/test/assets/asset.d.ts index 0c26108..e661ff1 100644 --- a/test/assets/asset.d.ts +++ b/test/assets/asset.d.ts @@ -1,13 +1,13 @@ import { McRAPTOR, RAPTOR, RAPTORData } from "../../src"; -import BaseRAPTOR from "../../src/base"; +import BaseRAPTOR, { IRAPTOR } from "../../src/base"; interface TestAsset { data: ConstructorParameters>; tests: { params: Parameters["run"]>; validate: ( - res: ReturnType["getBestJourneys"]>, - raptorInstance: InstanceType>, + res: ReturnType["getBestJourneys"]>, + raptorInstance: InstanceType> & IRAPTOR, ) => void; }[]; } diff --git a/test/assets/utils.ts b/test/assets/utils.ts index 06a78cd..4d73686 100644 --- a/test/assets/utils.ts +++ b/test/assets/utils.ts @@ -1,5 +1,5 @@ import { Journey, Time } from "../../src"; -import BaseRAPTOR from "../../src/base"; +import BaseRAPTOR, { IRAPTOR } from "../../src/base"; import { McTestAsset, TestAsset } from "./asset"; const validateWithoutCriteria = @@ -26,7 +26,7 @@ const validateWithoutCriteria = }); validate( journeysWithoutCriteria as Parameters["tests"][number]["validate"]>[0], - rap as unknown as BaseRAPTOR, + rap as unknown as BaseRAPTOR & IRAPTOR, ); return [journeysWithoutCriteria, res.map((journeys, k) => journeys.filter((j) => j !== journeysWithoutCriteria[k][0]))]; diff --git a/test/base.test.ts b/test/base.test.ts index 5a2fd6b..47862aa 100644 --- a/test/base.test.ts +++ b/test/base.test.ts @@ -24,10 +24,6 @@ describe("Base RAPTOR should not be usable", () => { expect(() => { (raptorInstance as unknown as { traverseFootPaths: BaseRAPTOR["traverseFootPaths"] }).traverseFootPaths(0, new Stop(0, [], [])); }).toThrow("Not implemented"); - - expect(() => { - (raptorInstance as unknown as { getBestJourneys: BaseRAPTOR["getBestJourneys"] }).getBestJourneys(0); - }).toThrow("Not implemented"); }); }); From 127c1d3604f157b6b93901cee6bf98b3a0563288 Mon Sep 17 00:00:00 2001 From: Catatomik Date: Thu, 16 Oct 2025 20:13:16 +0000 Subject: [PATCH 3/3] Updating coverage badges --- badges/coverage-functions.svg | 2 +- badges/coverage-lines.svg | 2 +- badges/coverage-statements.svg | 2 +- badges/coverage-total.svg | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/badges/coverage-functions.svg b/badges/coverage-functions.svg index fd6da43..66c721c 100644 --- a/badges/coverage-functions.svg +++ b/badges/coverage-functions.svg @@ -1 +1 @@ -Coverage: functions: 93.87%Coverage: functions93.87% \ No newline at end of file +Coverage: functions: 93.84%Coverage: functions93.84% \ No newline at end of file diff --git a/badges/coverage-lines.svg b/badges/coverage-lines.svg index 16a6ff5..fa8a6eb 100644 --- a/badges/coverage-lines.svg +++ b/badges/coverage-lines.svg @@ -1 +1 @@ -Coverage: lines: 95.69%Coverage: lines95.69% \ No newline at end of file +Coverage: lines: 95.68%Coverage: lines95.68% \ No newline at end of file diff --git a/badges/coverage-statements.svg b/badges/coverage-statements.svg index a2a43b3..4d9345e 100644 --- a/badges/coverage-statements.svg +++ b/badges/coverage-statements.svg @@ -1 +1 @@ -Coverage: statements: 94.55%Coverage: statements94.55% \ No newline at end of file +Coverage: statements: 94.54%Coverage: statements94.54% \ No newline at end of file diff --git a/badges/coverage-total.svg b/badges/coverage-total.svg index ab2b88a..cb54e8b 100644 --- a/badges/coverage-total.svg +++ b/badges/coverage-total.svg @@ -1 +1 @@ -Coverage: total: 92.52%Coverage: total92.52% \ No newline at end of file +Coverage: total: 92.5%Coverage: total92.5% \ No newline at end of file