mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-29 17:37:34 +01:00
61 lines
2.4 KiB
TypeScript
61 lines
2.4 KiB
TypeScript
import { PositiveInteger } from "../../src/types";
|
|
import { Corporation } from "../../src/Corporation/Corporation";
|
|
import { CorpUpgrades } from "../../src/Corporation/data/CorporationUpgrades";
|
|
import { calculateMaxAffordableUpgrade, calculateUpgradeCost } from "../../src/Corporation/helpers";
|
|
|
|
describe("Corporation", () => {
|
|
let corporation: Corporation;
|
|
|
|
beforeEach(() => {
|
|
corporation = new Corporation({ name: "Test" });
|
|
});
|
|
|
|
describe("helpers.calculateUpgradeCost", () => {
|
|
it("should have fixed formula", () => {
|
|
for (let currentUpgradeLevel = 0; currentUpgradeLevel < 5; currentUpgradeLevel++) {
|
|
Object.values(CorpUpgrades).forEach((upgrade) => {
|
|
corporation.upgrades[upgrade.name].level = currentUpgradeLevel;
|
|
|
|
for (let targetUpgradeLevel = currentUpgradeLevel + 1; targetUpgradeLevel < 6; targetUpgradeLevel++) {
|
|
expect(calculateUpgradeCost(corporation, upgrade, targetUpgradeLevel as PositiveInteger)).toMatchSnapshot(
|
|
`${upgrade.name}: from ${currentUpgradeLevel} to ${targetUpgradeLevel}`,
|
|
);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("helpers.calculateMaxAffordableUpgrade", () => {
|
|
it("should return zero for negative funds", () => {
|
|
corporation.funds = -1;
|
|
|
|
Object.values(CorpUpgrades).forEach((upgrade) => {
|
|
expect(calculateMaxAffordableUpgrade(corporation, upgrade)).toBe(0);
|
|
});
|
|
});
|
|
|
|
it("should return zero for zero funds", () => {
|
|
corporation.funds = 0;
|
|
|
|
Object.values(CorpUpgrades).forEach((upgrade) => {
|
|
expect(calculateMaxAffordableUpgrade(corporation, upgrade)).toBe(0);
|
|
});
|
|
});
|
|
|
|
it("should be in sync with 'calculateUpgradeCost'", () => {
|
|
for (let currentUpgradeLevel = 0; currentUpgradeLevel < 100; currentUpgradeLevel++) {
|
|
Object.values(CorpUpgrades).forEach((upgrade) => {
|
|
corporation.upgrades[upgrade.name].level = currentUpgradeLevel;
|
|
|
|
for (let targetUpgradeLevel = currentUpgradeLevel + 1; targetUpgradeLevel < 100; targetUpgradeLevel++) {
|
|
const calculatedCost = calculateUpgradeCost(corporation, upgrade, targetUpgradeLevel as PositiveInteger);
|
|
corporation.funds = calculatedCost + 1; // +1 for floating point accuracy issues
|
|
expect(calculateMaxAffordableUpgrade(corporation, upgrade)).toEqual(targetUpgradeLevel);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
});
|
|
});
|