// Host test: c++ -std=c++11 -Wall -Wextra -Werror -Isrc // tests/orientation_test.cpp -o /tmp/orientation-test && /tmp/orientation-test #include "orientation.h" #include #include int main() { using namespace orientation; for (unsigned r = 0; r < 4; ++r) { std::vector visited(panel_width * panel_height, false); for (int y = 0; y < panel_height; ++y) { for (int x = 0; x < panel_width; ++x) { int i = source_index(r, x, y); assert(i >= 0 && i < width(r) * height(r)); assert(!visited[i]); visited[i] = true; int sx = i % width(r), sy = i / width(r); int px = sx, py = sy; if (r == 1) { px = panel_width - 1 - sy; py = sx; } if (r == 2) { px = panel_width - 1 - sx; py = panel_height - 1 - sy; } if (r == 3) { px = sy; py = panel_height - 1 - sx; } assert(px == x && py == y); } } for (bool seen : visited) assert(seen); } Filter f; assert(f.update(-1, 0, 0, 0) == 0); assert(f.update(-1, 0, 0, 299) == 0); assert(f.update(-1, 0, 0, 300) == 1); assert(f.update(0, 0, 1, 1000) == 1); // flat: hold assert(f.update(0.7f, 0.7f, 0, 2000) == 1); // diagonal: hold assert(f.update(0, -1, 0, 2100) == 1); assert(f.update(0, 0, 1, 2399) == 1); // interrupted candidate assert(f.update(0, -1, 0, 2400) == 1); assert(f.update(0, -1, 0, 2700) == 2); assert(f.update(1, 0, 0, 2800) == 2); assert(f.update(1, 0, 0, 3100) == 3); assert(f.update(0, 1, 0, 3200) == 3); assert(f.update(0, 1, 0, 3500) == 0); Filter wrap; assert(wrap.update(-1, 0, 0, UINT32_MAX - 100) == 0); assert(wrap.update(-1, 0, 0, 198) == 0); assert(wrap.update(-1, 0, 0, 199) == 1); }