54 lines
1.9 KiB
JavaScript
54 lines
1.9 KiB
JavaScript
import { TestCase } from "./framework/test_case.js";
|
|
import { ECONOMY } from "../shared/data.js";
|
|
import { HOURS_PER_YEAR } from "../shared/game_state.js";
|
|
|
|
function config(overrides = {}) {
|
|
return { ...ECONOMY, ...overrides };
|
|
}
|
|
|
|
export class EconomyTest extends TestCase {
|
|
test_population_growth_scales_with_step() {
|
|
const cfg = config({ basePopulationGrowthRate: 0.005 });
|
|
const hourly = cfg.populationGrowthFactor(HOURS_PER_YEAR);
|
|
const daily = cfg.populationGrowthFactor(HOURS_PER_YEAR, 24);
|
|
this.assertApprox(daily, Math.pow(1 + hourly, 24) - 1, 1e-9);
|
|
this.assertApprox(Math.pow(1 + hourly, HOURS_PER_YEAR) - 1, 0.005, 1e-6);
|
|
}
|
|
|
|
test_population_growth_zero_rate_is_zero() {
|
|
const cfg = config({ basePopulationGrowthRate: 0 });
|
|
this.assertEqual(cfg.populationGrowthFactor(HOURS_PER_YEAR, 24), 0);
|
|
}
|
|
|
|
test_population_growth_guards_invalid_period() {
|
|
const cfg = config({ basePopulationGrowthRate: 0.005 });
|
|
this.assertEqual(cfg.populationGrowthFactor(0), 0);
|
|
this.assertEqual(cfg.populationGrowthFactor(HOURS_PER_YEAR, 0), 0);
|
|
}
|
|
|
|
test_production_capacity() {
|
|
const cfg = config({ gdpPerProductionPoint: 100000000 });
|
|
this.assertApprox(cfg.productionCapacity(1000000000), 10);
|
|
this.assertApprox(cfg.productionCapacity(0), 0);
|
|
}
|
|
|
|
test_production_capacity_guards_divisor() {
|
|
this.assertEqual(config({ gdpPerProductionPoint: 0 }).productionCapacity(1000), 0);
|
|
}
|
|
|
|
test_training_hours() {
|
|
this.assertApprox(config({ gdpPerProductionPoint: 100 }).trainingHours(1000, 50), 5);
|
|
}
|
|
|
|
test_training_hours_without_capacity_is_zero() {
|
|
this.assertEqual(config({ gdpPerProductionPoint: 0 }).trainingHours(1000, 50), 0);
|
|
}
|
|
|
|
test_budget_income_scales_with_hours() {
|
|
const cfg = config({ budgetGdpRate: 0.001 });
|
|
this.assertApprox(cfg.budgetIncome(1000), 1);
|
|
this.assertApprox(cfg.budgetIncome(1000, 24), 24);
|
|
}
|
|
|
|
}
|