optimized events
This commit is contained in:
@@ -4,6 +4,7 @@ import type {
|
||||
VoyageHarbour
|
||||
} from "@watermaps/shared";
|
||||
import {
|
||||
DEFAULT_ROUTE_EVENT_CORRIDORS_NM,
|
||||
nextRouteEventsByKind,
|
||||
upcomingRouteEvents
|
||||
} from "../src/routeEvents";
|
||||
@@ -80,6 +81,66 @@ describe("upcomingRouteEvents", () => {
|
||||
expect(events.map((event) => event.id)).toEqual(["detour"]);
|
||||
});
|
||||
|
||||
it("uses a focused half-mile harbour corridor by default", () => {
|
||||
expect(DEFAULT_ROUTE_EVENT_CORRIDORS_NM.harbour).toBe(0.5);
|
||||
|
||||
const events = upcomingRouteEvents({
|
||||
route,
|
||||
harbours: [
|
||||
harbour("near-harbour", 0.4, 0.008),
|
||||
harbour("unrelated-harbour", 0.5, 0.01)
|
||||
]
|
||||
});
|
||||
|
||||
expect(events.map((event) => event.id)).toEqual(["near-harbour"]);
|
||||
});
|
||||
|
||||
it("prefers a nearby same-named lock over a duplicate harbour classification", () => {
|
||||
const duplicateHarbour = {
|
||||
...harbour("harbour-lock", 0.4, 0.0005),
|
||||
name: "Nesserländer Schleuse"
|
||||
};
|
||||
const duplicateLock = {
|
||||
...lock("lock", 0.4, 0, 0, 0),
|
||||
name: "Nesserlander Schleuse"
|
||||
};
|
||||
const distinctHarbour = {
|
||||
...harbour("real-harbour", 0.6, 0),
|
||||
name: "Stadthafen"
|
||||
};
|
||||
|
||||
const events = upcomingRouteEvents({
|
||||
route,
|
||||
harbours: [duplicateHarbour, distinctHarbour],
|
||||
locks: [duplicateLock]
|
||||
});
|
||||
|
||||
expect(events.map((event) => `${event.kind}:${event.name}`)).toEqual([
|
||||
"lock:Nesserlander Schleuse",
|
||||
"harbour:Stadthafen"
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not merge same-named facilities that are spatially distinct", () => {
|
||||
const events = upcomingRouteEvents({
|
||||
route,
|
||||
harbours: [
|
||||
{
|
||||
...harbour("harbour", 0.4, 0.003),
|
||||
name: "Kanalschleuse"
|
||||
}
|
||||
],
|
||||
locks: [
|
||||
{
|
||||
...lock("lock", 0.4, 0, 0, 0),
|
||||
name: "Kanalschleuse"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
expect(events.map((event) => event.kind).sort()).toEqual(["harbour", "lock"]);
|
||||
});
|
||||
|
||||
it("calculates ETA and retains both speed and reference-time provenance", () => {
|
||||
const [event] = upcomingRouteEvents({
|
||||
route,
|
||||
|
||||
Reference in New Issue
Block a user