Files
Battle-for-Tismo/tests/game_clock_test.js
T
adrien d73ea4735d Grew the economy at a constant rate and forecast the budget
GDP per capita had no natural growth, so a nation's economy only moved
when population, buildings or war did. The summary stats also offered
inconsistent hover text: a native browser tooltip for popularity and none
at all for the budget.

- Every land tile now gains a constant 0.01% of the GDP per capita it
  opened with, once a day. Because the amount is fixed the relative growth
  rate tapers over the years. Each tile's opening figure is snapshotted
  once and shipped to the browser, so the tile panel and the GDP-per-capita
  map mode stay in step with the server.
- The population, GDP and GDP/capita tooltips show the relative growth:
  against 1 January 2000 through the first year, then year on year. The
  monthly captures now keep a rolling thirteen months for the baseline.
- Every summary stat explains itself through the same custom bubble.
  Popularity's native title moved onto it, and Budget forecasts the next
  calendar month at the current hourly net, as a compact figure such as
  "+€3.28B/mo" (hoursInNextMonth follows the real calendar).
- The tile GDP breakdown shows gains with a plus sign (natural growth,
  ports) rather than the old minus.

Added tests for the constant daily gain, the falling relative rate, the
first-year and year-on-year baselines, the snapshot baseline, the budget
forecast and the calendar month length.
2026-09-21 12:27:11 +02:00

32 lines
1.2 KiB
JavaScript

import { TestCase } from "./framework/test_case.js";
import { dateString, unixTime, hoursInNextMonth, START_UNIX_TIME, UNIX_SECONDS_PER_HOUR } from "../shared/game_clock.js";
export class GameClockTest extends TestCase {
test_starts_in_the_year_2000() {
this.assertEqual(dateString(0), "1 January 2000, 00:00");
}
test_advances_one_hour_at_a_time() {
this.assertEqual(dateString(1), "1 January 2000, 01:00");
this.assertEqual(dateString(24), "2 January 2000, 00:00");
this.assertEqual(dateString(48), "3 January 2000, 00:00");
}
test_a_full_year_passes_after_8760_hours() {
// The clock counts a fixed 365-day year but renders the real calendar, so
// 2000 (a leap year) ends on 31 December.
this.assertEqual(dateString(8760), "31 December 2000, 00:00");
}
test_unix_time_is_start_plus_hours() {
this.assertEqual(unixTime(0), START_UNIX_TIME);
this.assertEqual(unixTime(5), START_UNIX_TIME + 5 * UNIX_SECONDS_PER_HOUR);
}
test_the_next_month_follows_the_real_calendar() {
// January has 31 days, and February 2000 has 29.
this.assertEqual(hoursInNextMonth(0), 31 * 24);
this.assertEqual(hoursInNextMonth(31 * 24), 29 * 24);
}
}