Files
Battle-for-Tismo/docs/simple_economy/11-tests.md
T
adrien d5305da449 Gave the world a simple economy: one pool per nation and a global market
The simple economy is now the default and the old simulation is frozen as the hard model, selectable per game. A nation keeps one resource pool available in every region, fed by public production works rather than private per-region stores, and construction and training begin at once, paced by the region's spare power instead of gathering materials over days.

Money is euro only: a per-inhabitant daily tax funds a treasury spent in a global market, where buy and sell lots trade against the world stock and move its price. The hard economy keeps its per-nation currencies, central banks and exchange rates.

Simple games skip the price-settling warmup and economic migration; the snapshot carries the economy model, the market and the pool figures the client draws. Added the matching test suites and the design briefs under docs/simple_economy.
2026-09-25 14:58:49 +02:00

4.7 KiB
Raw Blame History

11 — Test plan

Depends on: all modules.

Goal

Cover the simple economy with focused suites while keeping the hard economy's existing suites green. During development run only the affected file:

node tests/run_tests.js --file <name>.js

Never run the full suite by hand; the commit hook runs it.

Conventions

  • Each file extends TestCase from tests/framework/. Look at tests/resources_test.js, tests/money_test.js, tests/industry_test.js, tests/construction_site_test.js and tests/framework/helpers.js for the established fixtures.
  • Build a small map fixture when possible (the DOM tests use one); force RNG with state._random = () => value.
  • Configure simple games explicitly: game.configure(civs, seed, { economyModel: "simple" }), and add a hard counterpart where behaviour must stay unchanged.

Suites

tests/economy_model_test.js (from 01-)

  • Default economyModel is "simple".
  • { economyModel: "hard" } and { economyModel: "simple" } both configure and tick.
  • The snapshot reports the model.
  • An unknown model coerces to "simple".

tests/simple_pool_test.js (from 02-)

  • One pool per civ, seeded; public producer output lands in the pool.
  • No per-tile resourceStock is read for procurement.
  • A build/train order does not enter a materials phase.

tests/simple_construction_test.js (from 03-, 04-)

  • Order enters construction immediately; completes on the hourly tick without a gather day.
  • More regional energy → strictly shorter totalHours (within the same map); zero energy → a finite, slow floor, never instant.
  • Every simple starting region has a working power plant.
  • A simple game has settledDays === 0 and no price settle.

tests/simple_taxes_test.js (from 05-)

  • Daily income equals population × 100 × approval × 2 × modifiers per civ.
  • Income uses the derived approval, not raw popularity.
  • set_tax_rate is refused in simple mode; the single income source shows in the budget breakdown.
  • Construction/training/upkeep do not debit the treasury in simple mode.
  • Hard taxes_test.js / money_test.js still pass.

tests/simple_market_test.js (from 06-)

  • At stock 1_000_000, price equals RESOURCE_MARKET_BASE.
  • Buy lowers stock and raises price; treasury and pool move exactly.
  • Sell raises stock and lowers price.
  • Only lots 100/2000/50000 are accepted.
  • Insufficient funds/stock is refused without partial mutation.
  • A near-empty stock is clamped (no Infinity/NaN).

tests/simple_procurement_test.js (from 07-)

  • Consumption draws move the pool exactly.
  • No trade-graph/supplier lookup runs in simple mode.
  • A shortfall stalls the work / leaves the need unmet without a bid.

tests/simple_migration_test.js (from 08-)

  • Two regions with very different income do not exchange people in simple mode.
  • Natural growth still applies.
  • Hard politics_test.js migration tests pass.

tests/simple_snapshot_test.js (from 10-)

  • Simple snapshot carries economyModel, the market (stock+price) and the viewer's pool.
  • A market change bumps its version and re-ships; an unchanged market is omitted.
  • market_trade validation accepts a valid lot and rejects bad input.

Hard-economy regression

The hard-model suites must pass unchanged: resources_test.js, money_test.js, taxes_test.js, industry_test.js, construction_site_test.js, politics_test.js, growth_test.js, air_test.js. If a hard path had to be refactored, add a direct hard assertion rather than relying on the hook alone.

Acceptance criteria

  • Each new suite fails before its module is implemented and passes after.
  • No hard-economy test is modified to accommodate a simple-economy change without a note in this file.

Implementation notes

  • All suites above are in place. tests/simple_migration_test.js is the dedicated home for the 08 checks; the simple-mode migration cases were also added beside the hard ones in tests/politics_test.js (as 08 asked), so the behaviour is pinned from both there and migration_test.js.
  • The new migration suite carries a direct hard control (test_the_hard_model_still_moves_people_for_income) so the no-op overrides are proved to differ from the original model rather than relying on the hook.
  • Verified green during development: economy_model_test, simple_pool_test, simple_construction_test, simple_taxes_test, simple_market_test, simple_procurement_test, simple_snapshot_test, simple_ui_test, simple_migration_test, plus the hard regression suites (resources_test, money_test, taxes_test, industry_test, construction_site_test, politics_test, migration_test, growth_test, air_test).