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

45 lines
1.4 KiB
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 { deliveryXp, pilotLevel, skillPointsAvailable } from "../src/index";
const config = content.config;
describe("delivery XP", () => {
it("grants more XP for a longer delivery", () => {
expect(deliveryXp(150, 0, config)).toBeGreaterThan(deliveryXp(0.4, 0, config));
});
it("grants more XP for a higher cargo tier", () => {
expect(deliveryXp(50, 3, config)).toBeGreaterThan(deliveryXp(50, 0, config));
});
it("matches a hand calculation", () => {
// base 10 + 0.2 × 100 + 5 × 2.
expect(deliveryXp(100, 2, config)).toBe(40);
});
});
describe("pilot level", () => {
it("starts at level 0", () => {
expect(pilotLevel(0, config)).toBe(0);
});
it("goes up by exactly one when crossing each threshold", () => {
config.pilotLevelXpThresholds.forEach((threshold, i) => {
expect(pilotLevel(threshold - 1, config)).toBe(i);
expect(pilotLevel(threshold, config)).toBe(i + 1);
});
});
});
describe("skill points", () => {
it("gives points per level minus points spent", () => {
expect(skillPointsAvailable(3, 2, config)).toBe(3 * config.skillPointsPerLevel - 2);
});
it("never goes negative", () => {
expect(skillPointsAvailable(0, 5, config)).toBe(0);
expect(skillPointsAvailable(1, 100, config)).toBe(0);
});
});