// Graph Window data KAT (ui/graph_view.hpp + sim/graph_history.hpp): the XGRP history decodes to // 16 metrics × 52 dwords (12 monthly + 20 semiannual + 20 quinquennial ring entries — the corrected // layout), LONDON's newest City-Size sample matches the raw chunk, the load-time maxima recompute // scales the plots, and the monthly recorder shifts/appends. Skips the // city-dependent checks without LONDON. #include "sc2k/io/sc2_file.hpp" #include "sc2k/render/asset_loader.hpp" #include "sc2k/sim/graph_history.hpp" #include "sc2k/ui/graph_view.hpp" #include #include #include #include "test_harness.hpp" #include "test_paths.hpp" // clang-format off int main(){ using namespace sc2k; i18n::load_locale(render::assets_dir()+"/lang", "en"); // metric names are catalog keys CHECK(std::string(ui::graph_metric_name(0))=="City Size"); CHECK(std::string(ui::graph_metric_name(7))=="Crime"); CHECK(std::string(ui::graph_metric_name(15))=="Fed Rate"); // colours (recovered v50[]): Residents green, Commerce blue, Power red. CHECK(ui::graph_metric_color(1).g==176 && ui::graph_metric_color(1).r==0); CHECK(ui::graph_metric_color(2).b==176 && ui::graph_metric_color(2).r==0); CHECK(ui::graph_metric_color(8).r==176 && ui::graph_metric_color(8).b==0); // plotted-entry index walk: 1yr 11→0, 10yr 31→12, 100yr 51→32. CHECK(ui::graph_points(0)==12 && ui::graph_points(1)==20 && ui::graph_points(2)==20); CHECK(ui::graph_entry_index(0,0)==11 && ui::graph_entry_index(0,11)==0); CHECK(ui::graph_entry_index(1,0)==31 && ui::graph_entry_index(1,19)==12); CHECK(ui::graph_entry_index(2,0)==51 && ui::graph_entry_index(2,19)==32); // The recorder on a blank city: fresh samples land at entry 0, months shift them along the 1-yr // ring, and the Jan/Jul boundary copies entry 0 into the 10-yr ring head (entry 12). { City c; graph_reset(c); CHECK(int(c.xgrp.size())==3328 && c.graph_max[8]==100 && c.graph_max[10]==90 && c.graph_max[11]==150); GraphInputs gi; gi.month=5; gi.zonePops[0]=100; gi.zonePops[1]=60; gi.zonePops[2]=40; gi.lifeExpectancy=70; gi.educationQuotient=80; gi.fedRate=4; graph_history_step(c, gi); CHECK(ui::graph_entry(c,0,0)==1000); // City Size = 10·zonePops[0] CHECK(ui::graph_entry(c,1,0)==1000); // Residents = 10·(cat1+cat2) CHECK(ui::graph_entry(c,8,0)==100 && ui::graph_entry(c,10,0)==70); CHECK(c.graph_max[0]==1000 && c.graph_max[3]==1000); // metrics 0-3 share City Size's max CHECK(ui::graph_entry(c,0,12)==0); // 10-yr ring untouched (month 5) gi.month=6; gi.zonePops[0]=200; graph_history_step(c, gi); CHECK(ui::graph_entry(c,0,0)==2000 && ui::graph_entry(c,0,1)==1000); // monthly shift // clang-format on CHECK(ui::graph_entry(c, 0, 12) == 2000); // July → 10-yr ring head = fresh sample gi.month = 0; gi.yearsSinceFounding = 5; graph_history_step(c, gi); CHECK(ui::graph_entry(c, 0, 13) == 2000); // Jan → 10-yr ring shifted CHECK(ui::graph_entry(c, 0, 32) == 2000); // year%5==0 → 100-yr ring head } const std::string p = city_file("LONDON.SC2"); if (!exists(p)) { std::printf("graphs: names/colours/recorder OK; SKIP city (no LONDON)\n"); return failures ? 1 : 0; } City c; CHECK(io::load_sc2(p, c).ok); CHECK(c.xgrp.size() == 3328); // XGRP RLE-decodes to 16*208 CHECK(ui::graph_entry(c, 0, 0) == 185528); // newest City-Size entry (verified vs raw chunk) CHECK(ui::graph_entry(c, 0, 12) > 0); // the 10-yr ring is populated too graph_recompute_maxima(c); // the on-load pass CHECK(c.graph_max[0] >= 185528); // maxima at least the newest monthly sample CHECK(c.graph_max[1] == c.graph_max[0]); // metrics 1-3 inherit metric 0's max std::printf("graphs: LONDON City-Size newest=%d max=%d; rings + recorder verified\n", ui::graph_entry(c, 0, 0), c.graph_max[0]); if (failures == 0) { std::printf("graphs: all checks passed\n"); return 0; } std::printf("graphs: %d failure(s)\n", failures); return 1; }