47 lines
2.0 KiB
TypeScript
47 lines
2.0 KiB
TypeScript
import { content, type Location, type ShipModel } from "@deadhead/content";
|
||
import { describe, expect, it } from "vitest";
|
||
import { checkRoute, economicDistance, rangeFrom, routeDistance } from "../src/index";
|
||
|
||
const loc = (id: string) => content.location(id)!;
|
||
const courier = content.shipModel("courier")!;
|
||
/** A Courier whose full tank reaches exactly `range` from a factor-1 origin (decision 0.5.95). */
|
||
const withRange = (range: number): ShipModel => ({
|
||
...courier,
|
||
tankCapacityFu: courier.burnFuPerMillionKm * economicDistance(range, content.config),
|
||
});
|
||
|
||
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"), content.config)).toBeCloseTo(100);
|
||
expect(rangeFrom(withRange(100), loc("moon"), content.config)).toBeCloseTo(130);
|
||
expect(rangeFrom(withRange(100), loc("mars"), content.config)).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(d / 1.2);
|
||
expect(checkRoute(ship, loc("earth"), loc("mars"), content.config)).toEqual({
|
||
ok: false,
|
||
reason: "out-of-range",
|
||
});
|
||
expect(checkRoute(ship, loc("moon"), loc("mars"), content.config)).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)), content.config).ok,
|
||
).toBe(old);
|
||
}
|
||
}
|
||
}
|
||
});
|
||
});
|