deadhead-space-freight-tycoon/packages/sim/test/fuel.test.ts

26 lines
970 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { content } from "@deadhead/content";
import { describe, expect, it } from "vitest";
import { fuelCost, routeDistance } from "../src/index";
const courier = content.shipModel("courier")!;
const earth = content.location("earth")!;
const moon = content.location("moon")!;
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)).toBeGreaterThan(fuelCost(courier, moon, distance));
});
it("scales linearly with distance", () => {
expect(fuelCost(courier, earth, 2)).toBe(2 * fuelCost(courier, earth, 1));
expect(fuelCost(courier, earth, 10)).toBe(10 * fuelCost(courier, earth, 1));
});
it("matches a hand calculation", () => {
// 0.5M km × 200 credits/M km × Earth multiplier 3.
expect(fuelCost(courier, earth, 0.5)).toBe(300);
});
});