Files
Battle-for-Tismo/tests/inflation_test.js
T
adrien 6f73e2cc51 Reworked the world around a fixed sea share and settled coasts
World generation now aims at a fixed share of the ice-free tiles (60%) instead of a minimum continent count, bisecting the water level for it rather than sweeping every step, and still joins the ocean into one body. Ice and tundra are the outermost rows only, scaled down on small maps so the fixtures keep usable land.

Cities score their site, coastal plains best and landlocked worst, avoiding tundra and desert. Every nation that holds a coast gets a port city on each island it owns, and any landmass left empty is settled by the nearest nation, so no land starts unowned. A coastal city opens with a port already built.

Bundles the in-progress work in the tree: the commodity monthly price series and inflation the central bank's chart reads, and the rolling city-to-city migration graph the population map draws as flow arrows.
2026-09-22 17:00:38 +02:00

57 lines
2.4 KiB
JavaScript

import { TestCase } from "./framework/test_case.js";
import { smallState } from "./framework/helpers.js";
import { RESOURCE_IDS, RESOURCE_MARKET_BASE } from "../shared/data.js";
export class InflationHistoryTest extends TestCase {
test_the_index_starts_at_one_hundred() {
const state = smallState();
for (const id of RESOURCE_IDS) {
const info = state.resourceInflation(id);
this.assertApprox(info.index, 100, 1e-9, `${id} index`);
this.assertApprox(info.monthly, 0, 1e-9, `${id} monthly`);
this.assertApprox(info.yearly, 0, 1e-9, `${id} yearly`);
}
}
test_monthly_inflation_compares_with_last_month() {
const state = smallState();
const base = RESOURCE_MARKET_BASE.steel;
state.setResourcePrice("steel", base * 1.1);
state._sampleResourcePrices();
const info = state.resourceInflation("steel");
this.assertApprox(info.index, 110, 1e-6, "the index tracks the price");
this.assertApprox(info.monthly, 0.1, 1e-9, "a tenth dearer than last month");
this.assertApprox(info.yearly, 0.1, 1e-9, "and since the start, through 2000");
}
test_yearly_inflation_uses_the_same_month_a_year_earlier() {
const state = smallState();
const base = RESOURCE_MARKET_BASE.food;
// Twelve monthly openings, each 1% dearer than the last.
for (let month = 1; month <= 12; month++) {
state.setResourcePrice("food", base * (1 + 0.01 * month));
state._sampleResourcePrices();
}
// Then the live price a further step up.
state.setResourcePrice("food", base * 1.13);
const info = state.resourceInflation("food");
// The year-ago sample is January 2000 (the base); last month's opening is
// the eleventh sample.
this.assertApprox(info.yearly, 0.13, 1e-9, "growth since the same month last year");
this.assertApprox(info.monthly, 1.13 / 1.11 - 1, 1e-9, "growth since last month");
}
test_the_snapshot_ships_the_series_and_inflation() {
const state = smallState();
const shared = state.serializeShared();
this.assertSize(shared.resourcePriceHistory, RESOURCE_IDS.length);
this.assertSize(shared.resourceInflation, RESOURCE_IDS.length);
for (const [id, prices] of shared.resourcePriceHistory) {
this.assertTrue(RESOURCE_IDS.includes(id));
this.assertSize(prices, 1, "one opening price at the start");
}
const steel = shared.resourceInflation.find((entry) => entry.id === "steel");
this.assertApprox(steel.index, 100, 1e-9);
}
}