summaryrefslogtreecommitdiffhomepage
path: root/test/hole.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/hole.cpp')
-rw-r--r--test/hole.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/hole.cpp b/test/hole.cpp
index 7ccc86c3..09395c47 100644
--- a/test/hole.cpp
+++ b/test/hole.cpp
@@ -1,5 +1,7 @@
#include "app.hpp"
#include "src/hole.hpp"
+#include "src/hole-cut.hpp"
+#include "src/tile-constants.hpp"
namespace floormat {
namespace {
@@ -53,6 +55,44 @@ void test1(Vector2i offset)
#endif
}
+auto make_search_predicate(const CutResult<int>& res)
+{
+ return [&](Vector2i min, Vector2i max) -> bool {
+ for (auto i = 0u; i < res.size; i++)
+ if (res.array[i].min == min && res.array[i].max == max)
+ return true;
+ return false;
+ };
+}
+
+void test2()
+{
+ const auto res = CutResult<int>::cut({{}, Vector2ub{tile_size_xy}}, {Vector2i(-tile_size_xy/2), Vector2ub{tile_size_xy}});
+ fm_assert(res.size == 2);
+ const auto has = make_search_predicate(res);
+ fm_assert(has({-32, 0}, {32, 32}));
+ fm_assert(has({0, -32}, {32, 0}));
+}
+
+void test3()
+{
+ constexpr auto h = tile_size_xy/2;
+
+ {
+ const auto res = CutResult<Int>::cut({-h, -1}, {h, 1}, {-2, -100}, {2, 100});
+ fm_assert(res.found());
+ fm_assert_equal(2, (int)res.size);
+ }
+ {
+ const auto res = CutResult<Int>::cut({-h, 0}, {h, 0}, {-2, -100}, {2, 100});
+ fm_assert(res.found());
+ fm_assert_equal(2, (int)res.size);
+ const auto has = make_search_predicate(res);
+ fm_assert(has({-h, 0}, {-2, 0}));
+ fm_assert(has({ 2, 0}, { h, 0}));
+ }
+}
+
} // namespace
void Test::test_hole()
@@ -67,6 +107,9 @@ void Test::test_hole()
for (auto offset : offsets)
test1(offset);
+
+ test2();
+ test3();
}
} // namespace floormat