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"); } }