53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { content } from "@deadhead/content";
|
||
import { describe, expect, it } from "vitest";
|
||
import { contractPayout, type PayoutInput } from "../src/index";
|
||
|
||
const config = content.config;
|
||
const standard = content.cargoType("standard")!;
|
||
const dangerous = content.cargoType("dangerous")!;
|
||
|
||
const base: PayoutInput = {
|
||
cargoType: standard,
|
||
tier: 0,
|
||
massTonnes: 10,
|
||
distanceMillionKm: 100,
|
||
firstContact: false,
|
||
};
|
||
|
||
describe("contract payout", () => {
|
||
it("matches a hand calculation", () => {
|
||
// 100 credits/t/M km × 10 t × 100M km.
|
||
expect(contractPayout(base, config)).toBe(100_000);
|
||
});
|
||
|
||
it("scales linearly with mass and distance", () => {
|
||
const payout = contractPayout(base, config);
|
||
expect(contractPayout({ ...base, massTonnes: 30 }, config)).toBe(3 * payout);
|
||
expect(contractPayout({ ...base, distanceMillionKm: 250 }, config)).toBe(2.5 * payout);
|
||
});
|
||
|
||
it("pays more for Dangerous than Standard on the same mass and route", () => {
|
||
expect(contractPayout({ ...base, cargoType: dangerous, tier: 1 }, config)).toBeGreaterThan(
|
||
contractPayout(base, config),
|
||
);
|
||
});
|
||
|
||
it("pays more at a higher tier", () => {
|
||
const tier1 = contractPayout({ ...base, cargoType: dangerous, tier: 1 }, config);
|
||
const tier3 = contractPayout({ ...base, cargoType: dangerous, tier: 3 }, config);
|
||
expect(tier3).toBeGreaterThan(tier1);
|
||
});
|
||
|
||
it("pays more for a first-contact contract", () => {
|
||
expect(contractPayout({ ...base, firstContact: true }, config)).toBe(
|
||
contractPayout(base, config) * config.firstContactPayoutMultiplier,
|
||
);
|
||
});
|
||
|
||
it("rounds to whole credits", () => {
|
||
expect(Number.isInteger(contractPayout({ ...base, distanceMillionKm: 0.384 }, config))).toBe(
|
||
true,
|
||
);
|
||
});
|
||
});
|