import { content } from "@deadhead/content"; import { describe, expect, it } from "vitest"; import { economicDistance, fuelCost, routeDistance } from "../src/index"; const { config } = content; const courier = content.shipModel("courier")!; const earth = content.location("earth")!; const moon = content.location("moon")!; const { referenceMillionKm: ref, exponent } = config.economicDistance; describe("economic distance (decision 0.5.84)", () => { it("leaves an Earth–Moon length leg unchanged", () => { expect(economicDistance(ref, config)).toBeCloseTo(ref); }); it("grows more slowly than distance past the reference, and keeps order", () => { expect(economicDistance(130, config)).toBeLessThan(130); expect(economicDistance(130, config)).toBeGreaterThan(economicDistance(60, config)); // Doubling the distance multiplies it by 2^exponent. expect(economicDistance(20, config) / economicDistance(10, config)).toBeCloseTo(2 ** exponent); }); it("is the plain distance with an exponent of 1", () => { const linear = { ...config, economicDistance: { referenceMillionKm: ref, exponent: 1 } }; expect(economicDistance(130, linear)).toBeCloseTo(130); }); }); describe("fuel cost", () => { it("costs more Earth→Moon than Moon→Earth for the same ship", () => { const t = Date.parse("2100-01-01T00:00:00Z"); const distance = routeDistance(earth, moon, t); expect(fuelCost(courier, earth, distance, config)).toBeGreaterThan( fuelCost(courier, moon, distance, config), ); }); it("scales with economic distance", () => { expect(fuelCost(courier, earth, 10, config) / fuelCost(courier, earth, 5, config)).toBeCloseTo( 2 ** exponent, ); }); it("matches a hand calculation", () => { // Economic distance of 0.5M km × 200 credits/M km × Earth multiplier 2.1. const expected = ref * (0.5 / ref) ** exponent * 200 * 2.1; expect(fuelCost(courier, earth, 0.5, config)).toBeCloseTo(expected); }); });