74 lines
3.1 KiB
JavaScript
74 lines
3.1 KiB
JavaScript
import { TestCase } from "./framework/test_case.js";
|
|
import { smallState, stripPorts } from "./framework/helpers.js";
|
|
import { GOVERNMENTS } from "../shared/data.js";
|
|
|
|
const BIG_BUDGET = 1.0e15;
|
|
|
|
export class GameStateGovernmentTest extends TestCase {
|
|
test_every_civilisation_starts_on_the_first_government() {
|
|
const state = smallState();
|
|
this.assertSize(state.governments, GOVERNMENTS.length);
|
|
this.assertEqual(state.getGovernment(0), 0);
|
|
this.assertEqual(state.getGovernment(1), 0);
|
|
this.assertNotNull(state.getGovernmentResource(0));
|
|
}
|
|
|
|
test_request_set_government_changes_and_charges_budget() {
|
|
const state = smallState();
|
|
state.budgets.set(0, BIG_BUDGET);
|
|
const before = state.getBudget(0);
|
|
this.assertTrue(state.requestSetGovernment(0, 1));
|
|
this.assertEqual(state.getGovernment(0), 1);
|
|
this.assertLess(state.getBudget(0), before, "the switch was paid for");
|
|
}
|
|
|
|
test_request_set_government_rejects_current_and_unknown() {
|
|
const state = smallState();
|
|
state.budgets.set(0, BIG_BUDGET);
|
|
this.assertFalse(state.requestSetGovernment(0, 0), "already in power");
|
|
this.assertFalse(state.requestSetGovernment(0, 999), "unknown government");
|
|
this.assertFalse(state.requestSetGovernment(999, 1), "unknown civilisation");
|
|
}
|
|
|
|
test_request_set_government_goes_ahead_on_an_empty_treasury() {
|
|
const state = smallState();
|
|
state.budgets.set(0, 0);
|
|
// The government can always pay, borrowing from the central bank.
|
|
this.assertTrue(state.requestSetGovernment(0, 1));
|
|
this.assertLess(state.getBudget(0), 0, "the adoption cost became debt");
|
|
}
|
|
|
|
test_government_effects_are_folded_into_gdp() {
|
|
const state = smallState();
|
|
// Ports add a flat GDP that is not scaled by the government, so strip the
|
|
// seeded ones to keep the government multiplier the only variable.
|
|
stripPorts(state, 0);
|
|
state.budgets.set(0, BIG_BUDGET);
|
|
const monarchy = state.governments.findIndex((g) => g.id === "monarchy");
|
|
const republicGdp = state.getPlayerGdp(0);
|
|
this.assertTrue(state.requestSetGovernment(0, monarchy));
|
|
this.assertApprox(state.getPlayerGdp(0), (republicGdp * 1.1) / 1.05, 0.01);
|
|
}
|
|
|
|
test_technocracy_produces_research_each_hour() {
|
|
const state = smallState();
|
|
state.budgets.set(0, BIG_BUDGET);
|
|
const technocracy = state.governments.findIndex((g) => g.id === "technocracy");
|
|
this.assertTrue(state.requestSetGovernment(0, technocracy));
|
|
const method = state.technologies.findIndex((t) => t.id === "renewable_energy");
|
|
this.assertTrue(state.requestFocusTechnology(0, method));
|
|
this.assertEqual(state.getTechnologyProgress(0), 0);
|
|
state.advanceHour();
|
|
this.assertApprox(state.getTechnologyProgress(0), 3.0);
|
|
}
|
|
|
|
test_snapshot_exposes_government() {
|
|
const state = smallState();
|
|
const snapshot = state.snapshot(0);
|
|
this.assertSize(snapshot.governments, state.governments.length);
|
|
this.assertSize(snapshot.government, state.civilisations.length);
|
|
this.assertHas(snapshot.viewerStats, "government");
|
|
this.assertEqual(snapshot.viewerStats.government, 0);
|
|
}
|
|
}
|