53 lines
2.2 KiB
TypeScript
53 lines
2.2 KiB
TypeScript
import { content, type ShipModel } from "@deadhead/content";
|
|
import { describe, expect, it } from "vitest";
|
|
import { checkRoute } from "../src/index";
|
|
|
|
const earth = content.location("earth")!;
|
|
const moon = content.location("moon")!;
|
|
const mars = content.location("mars")!;
|
|
const ceres = content.location("ceres-station")!;
|
|
const jupiter = content.location("jupiter-cloud-platform")!;
|
|
const courier = content.shipModel("courier")!;
|
|
const freighter = content.shipModel("freighter")!;
|
|
const bulkHauler = content.shipModel("bulk-hauler")!;
|
|
|
|
/** Test-only ship that cannot land on atmospheric worlds. */
|
|
const vacuumShip: ShipModel = { ...courier, id: "test-vacuum", landingClass: "vacuum" };
|
|
|
|
// The map is fixed (decision 0.5.93), so any time gives the same answer.
|
|
const now = Date.parse("2100-01-01T00:00:00Z");
|
|
const outOfRange = { ok: false, reason: "out-of-range" };
|
|
|
|
// Origins are named in every test (decision 0.5.77: range is per leg, from its origin).
|
|
describe("route eligibility", () => {
|
|
it("lets a Courier fly Earth→Moon and Moon→Earth", () => {
|
|
expect(checkRoute(courier, earth, moon, now)).toEqual({ ok: true });
|
|
expect(checkRoute(courier, moon, earth, now)).toEqual({ ok: true });
|
|
});
|
|
|
|
it("keeps a Courier from Earth out of range of Mars, Ceres and Jupiter", () => {
|
|
for (const to of [mars, ceres, jupiter]) {
|
|
expect(checkRoute(courier, earth, to, now)).toEqual(outOfRange);
|
|
}
|
|
});
|
|
|
|
it("rejects a vacuum-only ship at Earth because it cannot land", () => {
|
|
expect(checkRoute(vacuumShip, moon, earth, now)).toEqual({
|
|
ok: false,
|
|
reason: "cannot-land",
|
|
});
|
|
expect(checkRoute(vacuumShip, earth, moon, now)).toEqual({ ok: true });
|
|
});
|
|
|
|
it("lets a Freighter from Earth reach Mars and Ceres (CR-015 §4)", () => {
|
|
expect(checkRoute(freighter, earth, mars, now)).toEqual({ ok: true });
|
|
expect(checkRoute(freighter, earth, ceres, now)).toEqual({ ok: true });
|
|
});
|
|
|
|
it("lets only the Bulk Hauler reach Jupiter from Earth", () => {
|
|
expect(checkRoute(bulkHauler, earth, jupiter, now)).toEqual({ ok: true });
|
|
expect(checkRoute(freighter, earth, jupiter, now)).toEqual(outOfRange);
|
|
expect(checkRoute(courier, earth, jupiter, now)).toEqual(outOfRange);
|
|
});
|
|
});
|