mega-plant/lib/profit.test.ts

34 lines
1.2 KiB
TypeScript

// Unit tests pinning profit behavior. Part 1.1 acceptance: TLB01 January = -1,795.03.
// Run: node --import tsx --test lib/profit.test.ts (or `npm test` if wired)
import { test } from "node:test";
import assert from "node:assert/strict";
import { computeProfit } from "./profit";
test("TLB01 January: workbook formula = SUM(income - fixed), app default matches", () => {
// Source: Machine Graph Data row for TLB01, month 1
// income = 21896, fixed_expenses = 23691.03, running_cost = 1897.5
// Workbook: 21896 - 23691.03 = -1795.03
const result = computeProfit({
income: 21896,
fixed: 23691.03,
running: 1897.5,
});
assert.equal(result.toFixed(2), "-1795.03");
});
test("includeRunningCost=true: subtracts running", () => {
const result = computeProfit(
{ income: 21896, fixed: 23691.03, running: 1897.5 },
{ includeRunningCost: true }
);
assert.equal(result.toFixed(2), "-3692.53");
});
test("zero income, zero fixed → zero profit", () => {
assert.equal(computeProfit({ income: 0, fixed: 0, running: 0 }), 0);
});
test("missing running cost behaves identically with default flag", () => {
const a = computeProfit({ income: 100, fixed: 30, running: 0 });
assert.equal(a, 70);
});