From dd1903aa08b2dc2f2e11856eb4b0441729356746 Mon Sep 17 00:00:00 2001 From: Piotr Spieker Date: Fri, 6 Dec 2024 17:45:43 +0100 Subject: [PATCH] Add unit test for Maze::positionConsideringTunnel() --- demo/test/maze.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 demo/test/maze.cpp diff --git a/demo/test/maze.cpp b/demo/test/maze.cpp new file mode 100644 index 00000000..71b2b636 --- /dev/null +++ b/demo/test/maze.cpp @@ -0,0 +1,37 @@ +#include "utils/maze.hpp" + +#include + +namespace utils::a_star { + +using namespace demo; + +TEST(MazeState, positionConsideringTunnel) { + const char str[] = {"### #" + "# " + "### #"}; + Maze maze{makeCustomMazeState({5, 3}, str)}; + + // Regular position -> no wrapping + EXPECT_EQ(maze.positionConsideringTunnel({1, 1}).x, 1); + EXPECT_EQ(maze.positionConsideringTunnel({1, 1}).y, 1); + + // Regular position -> no wrapping + EXPECT_EQ(maze.positionConsideringTunnel({4, 1}).x, 4); + EXPECT_EQ(maze.positionConsideringTunnel({4, 1}).y, 1); + + // Position out of maze, without tunnel -> clamping + EXPECT_EQ(maze.positionConsideringTunnel({5, 1}).x, 4); + EXPECT_EQ(maze.positionConsideringTunnel({5, 1}).y, 1); + + // Regular position -> no wrapping + EXPECT_EQ(maze.positionConsideringTunnel({3, 0}).x, 3); + EXPECT_EQ(maze.positionConsideringTunnel({3, 0}).y, 0); + + // Position out of maze, with tunnel -> wrapping + EXPECT_EQ(maze.positionConsideringTunnel({3, -1}).x, 3); + EXPECT_EQ(maze.positionConsideringTunnel({3, -1}).y, 2); +} + + +} // namespace utils::a_star \ No newline at end of file