Files
Battle-for-Tismo/tests/warmup_test.js
T
adrien 49613f2a1c Made training gather materials, fixed the trade graph, and banked money gifts
Unit orders now gather steel and high-tech over the days before training, exactly as buildings do, and clicking a queued order reveals what it is gathering, its reserved budget and the soldiers it will draw.

The trade graph cached a producer-less node list under a stamp that already reflected the producers' stores, so every seeded mine stayed invisible to buyers and rare-good prices settled at a huge multiple of base; the storage nodes are now re-read after production.

Money gifts draw the giver's central-bank reserves in the denomination first, buy the rest from the issuing bank at the market rate, convert into the receiver's currency, and cannot buy from a bank their nation is at war with.

Pruned the finished design briefs (intelligence, stacks, air movement, politics performance, economy balance, training UI and FIXME) and refreshed the index and cross-references.
2026-09-24 21:20:47 +02:00

57 lines
2.4 KiB
JavaScript

import { TestCase } from "./framework/test_case.js";
import { smallState } from "./framework/helpers.js";
import { HOURS_PER_DAY } from "../shared/game_state/constants.js";
import { RESOURCE_MARKET_BASE } from "../shared/data.js";
// The opening settle: the server runs the world forward until commodity prices
// hold steady, so a fresh game is not served mid-shakeout.
export class WarmupTest extends TestCase {
test_prices_are_not_steady_before_the_window_is_full() {
const state = smallState();
this.assertFalse(state.pricesAreSteady(7, 0.1), "a fresh market has no history to judge");
}
test_settling_stops_once_prices_hold_steady() {
const state = smallState();
const days = state.warmUpToStability({ maxDays: 90 });
this.assertLess(days, 90, "it stopped early rather than at the cap");
this.assertGreaterOrEqual(days, 7, "it ran at least the seven-day window");
this.assertTrue(state.pricesAreSteady(7, 0.1), "prices are steady when it decides to stop");
}
test_settling_stops_at_the_cap_when_it_never_steadies() {
const state = smallState();
const days = state.warmUpToStability({ maxDays: 3 });
this.assertEqual(days, 3, "the cap bounds a world that never settles");
this.assertEqual(state.totalHours, 3 * HOURS_PER_DAY, "three days were actually run");
}
test_a_zero_cap_skips_the_settle() {
const state = smallState();
this.assertEqual(state.warmUpToStability({ maxDays: 0 }), 0, "nothing is run");
this.assertEqual(state.totalHours, 0, "the clock did not move");
}
test_a_fixed_warm_up_still_runs_the_exact_days() {
const state = smallState();
state.warmUp(5);
this.assertEqual(state.totalHours, 5 * HOURS_PER_DAY, "a fixed settle runs every day asked for");
}
// The rare goods used to settle at a huge multiple of their base because the
// seeded mines were cached as unreachable and never sold, so a regression here
// is what a producer-less trade graph looks like.
test_the_settled_world_opens_with_the_rare_goods_near_their_base() {
const state = smallState();
state.warmUpToStability({ maxDays: 150 });
for (const id of ["luxury", "hightech"]) {
const index = state.getResourcePrice(id) / RESOURCE_MARKET_BASE[id];
this.assertTrue(
index > 0.5 && index < 2.5,
`${id} settles near its base price (index ${index.toFixed(2)})`
);
}
this.assertTrue(state.pricesAreSteady(7, 0.1), "and the market is steady");
}
}