aboutsummaryrefslogtreecommitdiff
path: root/test/string_matrix.test.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-03-19 13:21:54 +0100
committerHampusM <hampus@hampusmat.com>2022-06-13 17:56:56 +0200
commit55c93fe609888be73677317978959040cf35b2ff (patch)
tree41ee53961eb5667136432b69773ef7acf3ad8259 /test/string_matrix.test.cpp
parent020303df1410d10546f53d0bfee4f48797d4f067 (diff)
refactor: implement matrix iterator
Diffstat (limited to 'test/string_matrix.test.cpp')
-rw-r--r--test/string_matrix.test.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/string_matrix.test.cpp b/test/string_matrix.test.cpp
new file mode 100644
index 0000000..522a274
--- /dev/null
+++ b/test/string_matrix.test.cpp
@@ -0,0 +1,53 @@
+#include "engine/graphics/string_matrix.hpp"
+#include "engine/data/bounds.hpp"
+
+#include <doctest/doctest.h>
+#include <type_traits>
+
+constexpr uint32_t MATRIX_WIDTH = 76;
+constexpr uint32_t MATRIX_HEIGHT = 31;
+
+TEST_CASE("String matrix")
+{
+ auto string_matrix =
+ StringMatrix(Bounds({.width = MATRIX_WIDTH, .height = MATRIX_HEIGHT}));
+
+ SUBCASE("Can set & get elements")
+ {
+ // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
+ const auto position = Vector2({.x = 56, .y = 20});
+
+ string_matrix.set(position, "#");
+
+ CHECK(string_matrix.get(position) == "#");
+ }
+
+ SUBCASE("Can iterate")
+ {
+ CHECK(std::is_same_v<decltype(string_matrix.begin()),
+ MatrixIterator<std::string_view>>);
+
+ CHECK(std::is_same_v<decltype(string_matrix.end()),
+ MatrixIterator<std::string_view>>);
+
+ uint32_t row_iter_cnt = 0;
+
+ for (auto row : string_matrix)
+ {
+ row_iter_cnt++;
+
+ CHECK(std::is_same_v<decltype(row), MatrixRow<std::string_view>>);
+
+ uint32_t col_iter_cnt = 0;
+
+ for (auto &col : row)
+ {
+ col_iter_cnt++;
+ }
+
+ CHECK(col_iter_cnt == MATRIX_WIDTH);
+ }
+
+ CHECK(row_iter_cnt == MATRIX_HEIGHT);
+ }
+}