import { content, type Location, type ShipModel } from "@deadhead/content"; import { describe, expect, it } from "vitest"; import { checkRoute, rangeFrom, realToGame, routeDistance } from "../src/index"; const loc = (id: string) => content.location(id)!; const courier = content.shipModel("courier")!; const withRange = (range: number): ShipModel => ({ ...courier, fuelRangeMillionKm: range }); const start = realToGame(Date.parse(content.config.epoch.realStart), content.config); const MONTH = 30.44 * 24 * 3_600_000; const samples = Array.from({ length: 16 * 12 + 1 }, (_, i) => start + i * MONTH); describe("range from the origin (Step 10L.2)", () => { it("stretches a 100M km range to 130 from the Moon and 115 from Mars", () => { expect(rangeFrom(withRange(100), loc("earth"))).toBe(100); expect(rangeFrom(withRange(100), loc("moon"))).toBeCloseTo(130); expect(rangeFrom(withRange(100), loc("mars"))).toBeCloseTo(115); }); it("passes a leg from the Moon that fails from Earth when it is between 1× and 1.3× range", () => { const t = samples[0]!; const d = routeDistance(loc("moon"), loc("mars"), t); const ship = withRange(d / 1.2); expect(routeDistance(loc("earth"), loc("mars"), t)).toBeGreaterThan(ship.fuelRangeMillionKm); expect(checkRoute(ship, loc("earth"), loc("mars"), t)).toEqual({ ok: false, reason: "out-of-range", }); expect(checkRoute(ship, loc("moon"), loc("mars"), t)).toEqual({ ok: true }); }); it("matches the old check exactly when every factor is 1", () => { const flat = (l: Location): Location => ({ ...l, launchRangeFactor: 1 }); const ids = ["earth", "moon", "mars", "ceres-station", "jupiter-cloud-platform"]; for (const range of [5, 198, 450, 1250]) { for (const from of ids) { for (const to of ids) { if (from === to) continue; for (const t of samples) { const old = routeDistance(loc(from), loc(to), t) <= range; expect(checkRoute(withRange(range), flat(loc(from)), flat(loc(to)), t).ok).toBe(old); } } } } }); });