Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/test/blocks_along_line_test.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-20 14:33:09 +1000
commit6352e8e3196f78388b6c771073f9e03eaa612673 (patch)
treee23772f79a7fbc41bc9108951e9e136857484bf4 /source/test/blocks_along_line_test.cpp
parent6741a057e5639280d85d0f88ba26f000baa58f61 (diff)
everything everywhere
all at once
Diffstat (limited to 'source/test/blocks_along_line_test.cpp')
-rw-r--r--source/test/blocks_along_line_test.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/source/test/blocks_along_line_test.cpp b/source/test/blocks_along_line_test.cpp
new file mode 100644
index 0000000..5026c00
--- /dev/null
+++ b/source/test/blocks_along_line_test.cpp
@@ -0,0 +1,45 @@
+#include "StarBlocksAlongLine.hpp"
+#include "StarList.hpp"
+
+#include "gtest/gtest.h"
+
+using namespace Star;
+
+void testLine(Vec2D a, Vec2D b, Vec2I offset, List<Vec2I> comp) {
+ List<Vec2I> res;
+ forBlocksAlongLine(a + Vec2D(offset),
+ b - a,
+ [&res](int x, int y) {
+ res.append({x, y});
+ return true;
+ });
+ for (auto& c : comp)
+ c += offset;
+ EXPECT_TRUE(comp == res);
+}
+
+void testGroup(Vec2I offset) {
+ testLine(Vec2D(0.5, 0.5), Vec2D(0.5, 0.5), offset, {{0, 0}});
+ testLine(Vec2D(-0.5, -0.5), Vec2D(-0.5, -0.5), offset, {{-1, -1}});
+
+ testLine(Vec2D(-0.5, -0.5), Vec2D(0.5, 0.5), offset, {{-1, -1}, {0, 0}});
+ testLine(Vec2D(0.5, 0.5), Vec2D(-0.5, -0.5), offset, {{0, 0}, {-1, -1}});
+ testLine(Vec2D(-0.5, 0.5), Vec2D(0.5, -0.5), offset, {{-1, 0}, {0, -1}});
+ testLine(Vec2D(0.5, -0.5), Vec2D(-0.5, 0.5), offset, {{0, -1}, {-1, 0}});
+
+ testLine(Vec2D(0.5, -0.5), Vec2D(0.5, 0.5), offset, {{0, -1}, {0, 0}});
+ testLine(Vec2D(-0.5, 0.5), Vec2D(0.5, 0.5), offset, {{-1, 0}, {0, 0}});
+
+ testLine(Vec2D(0.0, 0.5), Vec2D(0.0, -0.5), offset, {{0, 0}, {0, -1}});
+ testLine(Vec2D(0.5, 0.0), Vec2D(-0.5, 0.0), offset, {{0, 0}, {-1, 0}});
+}
+
+TEST(BlocksAlongLine, All) {
+ testGroup({0, 0});
+ testGroup({50, 50});
+ testGroup({-5, -50});
+ testGroup({50, -5});
+ testGroup({100, 10});
+ testGroup({-10, -100});
+ testGroup({-10, 10});
+}