45 lines
2.0 KiB
JavaScript
45 lines
2.0 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_and_guards_invalid_periods() {
|
|
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);
|
|
this.assertEqual(config({ basePopulationGrowthRate: 0 }).populationGrowthFactor(HOURS_PER_YEAR, 24), 0);
|
|
this.assertEqual(cfg.populationGrowthFactor(0), 0);
|
|
this.assertEqual(cfg.populationGrowthFactor(HOURS_PER_YEAR, 0), 0);
|
|
}
|
|
|
|
test_production_capacity_and_training_hours_guard_their_divisor() {
|
|
const cfg = config({ gdpPerProductionPoint: 100000000 });
|
|
this.assertApprox(cfg.productionCapacity(1000000000), 10);
|
|
this.assertApprox(cfg.productionCapacity(0), 0);
|
|
this.assertEqual(config({ gdpPerProductionPoint: 0 }).productionCapacity(1000), 0);
|
|
|
|
this.assertApprox(config({ gdpPerProductionPoint: 100 }).trainingHours(1000, 50), 5);
|
|
this.assertEqual(config({ gdpPerProductionPoint: 0 }).trainingHours(1000, 50), 0);
|
|
}
|
|
|
|
test_building_hours_are_a_tenth_of_training() {
|
|
const cfg = config({ gdpPerProductionPoint: 100 });
|
|
this.assertApprox(cfg.buildingHours(1000, 50), 0.5);
|
|
this.assertApprox(
|
|
cfg.buildingHours(1000, 50),
|
|
cfg.trainingHours(1000, 50) / 10,
|
|
1e-9,
|
|
"construction is ten times faster than training the same cost"
|
|
);
|
|
const scaled = config({ gdpPerProductionPoint: 100, buildingTimeMultiplier: 0.5 });
|
|
this.assertApprox(scaled.buildingHours(1000, 50), 2.5);
|
|
this.assertEqual(config({ gdpPerProductionPoint: 0 }).buildingHours(1000, 50), 0);
|
|
}
|
|
}
|