Something went wrong. Try again.
[Mirror] Libreopolis is a cross-platform city simulation game fully compatible with SimCity 2000. gitlab.com/conasg/libreopolis
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// Pure test of debug/field_stats.hpp: min/avg/max/non-zero over the City field layers + the region form.#include "sc2k/city.hpp"#include "sc2k/debug/field_stats.hpp"#include <cstdio>
using namespace sc2k;using namespace sc2k::debug;
#include "test_harness.hpp"
int main() { City c;
// All-zero 32x32 layer. FieldStats z = field_stats(c.xfir); CHECK(z.min == 0 && z.max == 0 && z.nonzero == 0 && z.count == 32 * 32 && z.avg == 0.0);
// A few non-zero cells: max/min/nonzero/avg. c.xfir.at(0, 0) = 10; c.xfir.at(1, 1) = 20; c.xfir.at(2, 2) = 0; c.xfir.at(3, 3) = 30; FieldStats s = field_stats(c.xfir); CHECK(s.max == 30 && s.min == 0 && s.nonzero == 3 && s.count == 32 * 32); CHECK(s.avg > 0.0 && s.avg < 1.0); // 60 / 1024
// Region: the 2x2 block (0,0)-(1,1) holds {10, 0, 0, 20}. FieldStats r = field_stats_region(c.xfir, 0, 0, 1, 1); CHECK(r.count == 4 && r.max == 20 && r.min == 0 && r.nonzero == 2);
// Region clamps to the layer bounds (and swaps inverted corners). FieldStats rc = field_stats_region(c.xfir, -5, -5, 100, 100); CHECK(rc.count == 32 * 32); FieldStats rsw = field_stats_region(c.xfir, 1, 1, 0, 0); // inverted == same 2x2 CHECK(rsw.count == 4 && rsw.max == 20);
// Works on a 64x64 layer too. c.xcrm.at(10, 10) = 255; FieldStats cs = field_stats(c.xcrm); CHECK(cs.max == 255 && cs.nonzero == 1 && cs.count == 64 * 64);
if (failures == 0) { std::printf("field_stats: all checks passed\n"); return 0; } std::printf("field_stats: %d failure(s)\n", failures); return 1;}