// Known-answer test for the traffic decay (scheduler tick 19): v -= v>>2. #include "sc2k/sim/traffic.hpp" #include #include "test_harness.hpp" int main() { using namespace sc2k; City c; c.xtrf.cells[0] = 100; // 100 - 25 = 75 c.xtrf.cells[1] = 255; // 255 - 63 = 192 c.xtrf.cells[2] = 3; // 3 - 0 = 3 c.xtrf.cells[3] = 0; // 0 c.xtrf.cells[4] = 4; // 4 - 1 = 3 c.xtrf.cells[5] = 200; // 200 - 50 = 150 long total = decay_traffic(c); CHECK(c.xtrf.cells[0] == 75); CHECK(c.xtrf.cells[1] == 192); CHECK(c.xtrf.cells[2] == 3); CHECK(c.xtrf.cells[3] == 0); CHECK(c.xtrf.cells[4] == 3); CHECK(c.xtrf.cells[5] == 150); CHECK(total == 75 + 192 + 3 + 0 + 3 + 150); // rest of the field is 0 if (failures == 0) { std::printf("traffic: all checks passed\n"); return 0; } std::printf("traffic: %d failure(s)\n", failures); return 1; }