41 lines
1.8 KiB
TypeScript
41 lines
1.8 KiB
TypeScript
import { content, type Location, type ShipModel } from "@deadhead/content";
|
||
import { describe, expect, it } from "vitest";
|
||
import { checkRoute, rangeFrom, routeDistance } from "../src/index";
|
||
|
||
const loc = (id: string) => content.location(id)!;
|
||
const courier = content.shipModel("courier")!;
|
||
const withRange = (range: number): ShipModel => ({ ...courier, fuelRangeMillionKm: range });
|
||
|
||
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 d = routeDistance(loc("moon"), loc("mars"));
|
||
const ship = withRange(d / 1.2);
|
||
expect(routeDistance(loc("earth"), loc("mars"))).toBeGreaterThan(ship.fuelRangeMillionKm);
|
||
expect(checkRoute(ship, loc("earth"), loc("mars"))).toEqual({
|
||
ok: false,
|
||
reason: "out-of-range",
|
||
});
|
||
expect(checkRoute(ship, loc("moon"), loc("mars"))).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, 250, 460, 1250]) {
|
||
for (const from of ids) {
|
||
for (const to of ids) {
|
||
if (from === to) continue;
|
||
const old = routeDistance(loc(from), loc(to)) <= range;
|
||
expect(checkRoute(withRange(range), flat(loc(from)), flat(loc(to))).ok).toBe(old);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
});
|