// Known-answer test for ordinance costs (the original's per-ordinance formula). // Verifies each case against the original's fraction-of-population formula. #include "sc2k/sim/ordinances.hpp" #include #include "test_harness.hpp" int main() { using namespace sc2k; const int r10 = 1000, c10 = 500, i10 = 300, totPop10 = 1800, power = 200; CHECK(ordinance_cost(0, r10, c10, i10, totPop10, power) == 500); // sales tax = C CHECK(ordinance_cost(1, r10, c10, i10, totPop10, power) == 1000); // income tax = R CHECK(ordinance_cost(2, r10, c10, i10, totPop10, power) == 1000); // gambling = 2C CHECK(ordinance_cost(3, r10, c10, i10, totPop10, power) == 500); // parking = R/2 CHECK(ordinance_cost(4, r10, c10, i10, totPop10, power) == -333); // R/-3 CHECK(ordinance_cost(5, r10, c10, i10, totPop10, power) == -83); // C/-6 CHECK(ordinance_cost(6, r10, c10, i10, totPop10, power) == -500); // R/-2 CHECK(ordinance_cost(8, r10, c10, i10, totPop10, power) == -166); // R/-6 CHECK(ordinance_cost(9, r10, c10, i10, totPop10, power) == -200); // R/-5 CHECK(ordinance_cost(12, r10, c10, i10, totPop10, power) == -500); // -C CHECK(ordinance_cost(13, r10, c10, i10, totPop10, power) == -300); // -I CHECK(ordinance_cost(15, r10, c10, i10, totPop10, power) == -166); // C/-3 CHECK(ordinance_cost(16, r10, c10, i10, totPop10, power) == -2000); // energy conservation = -(totPop10 + power) CHECK(ordinance_cost(17, r10, c10, i10, totPop10, power) == 0); // nuclear free zone (free) CHECK(ordinance_cost(19, r10, c10, i10, totPop10, power) == -300); // pollution controls = -I // net of {sales tax (bit0) + income tax (bit1)} = C + R CHECK(ordinances_net(0x3, r10, c10, i10, totPop10, power) == 1500); // net of {gambling (bit2) + business advertising (bit13, = -I)} = 2C − I CHECK(ordinances_net((1u << 2) | (1u << 13), r10, c10, i10, totPop10, power) == 1000 - 300); if (failures == 0) { std::printf("ordinances: all checks passed\n"); return 0; } std::printf("ordinances: %d failure(s)\n", failures); return 1; }