diff options
author | HampusM <hampus@hampusmat.com> | 2022-06-02 19:51:54 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:57:00 +0200 |
commit | eecf4b1e666211a13afa56f93477c55e8fd01621 (patch) | |
tree | 410510d6e058995174d5a5b0f535fb457a0c3542 /test/cell_helper_test.cpp | |
parent | 87f55120f96d0f4f80b497dc9006d89df2dda125 (diff) |
feat: implement game of lifev0.1.0
Diffstat (limited to 'test/cell_helper_test.cpp')
-rw-r--r-- | test/cell_helper_test.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/test/cell_helper_test.cpp b/test/cell_helper_test.cpp new file mode 100644 index 0000000..b570aba --- /dev/null +++ b/test/cell_helper_test.cpp @@ -0,0 +1,99 @@ +#include "engine/data/vector2.hpp" +#include "game/cell_helper.hpp" + +#include "mocks/matrix.hpp" + +#include <gtest/gtest.h> + +#include <list> +#include <memory> + +class CellHelperTest : public testing::Test +{ +protected: +}; + +TEST_F(CellHelperTest, IsCellDying) +{ + const auto mock_matrix = MockMatrix<char>(); + + const auto rows = 8U; + const auto columns = 6U; + + const auto position = Vector2({.x = 3, .y = 5}); + + EXPECT_CALL(mock_matrix, get_row_cnt()).WillRepeatedly(testing::Return(rows)); + + EXPECT_CALL(mock_matrix, get_column_cnt()).WillRepeatedly(testing::Return(columns)); + + EXPECT_CALL(mock_matrix, get(position + Vector2::up())) + .WillOnce(testing::Return('x')) + .WillOnce(testing::Return(' ')) + .WillOnce(testing::Return(' ')); + + EXPECT_CALL(mock_matrix, get(position + Vector2::down())) + .WillRepeatedly(testing::Return(' ')); + + EXPECT_CALL(mock_matrix, get(position + Vector2::left())) + .WillOnce(testing::Return('x')) + .WillOnce(testing::Return('x')) + .WillOnce(testing::Return(' ')); + + EXPECT_CALL(mock_matrix, get(position + Vector2::right())) + .WillOnce(testing::Return('x')) + .WillOnce(testing::Return(' ')) + .WillOnce(testing::Return(' ')); + + EXPECT_CALL(mock_matrix, get(position + Vector2::up() + Vector2::left())) + .WillRepeatedly(testing::Return(' ')); + + EXPECT_CALL(mock_matrix, get(position + Vector2::up() + Vector2::right())) + .WillRepeatedly(testing::Return('x')); + + EXPECT_CALL(mock_matrix, get(position + Vector2::down() + Vector2::left())) + .WillRepeatedly(testing::Return(' ')); + + EXPECT_CALL(mock_matrix, get(position + Vector2::down() + Vector2::right())) + .WillRepeatedly(testing::Return(' ')); + + auto cell_helper = CellHelper<char>(mock_matrix); + + EXPECT_EQ(cell_helper.is_cell_dying(position), true); + + EXPECT_EQ(cell_helper.is_cell_dying(position), false); + + EXPECT_EQ(cell_helper.is_cell_dying(position), true); +} + +TEST_F(CellHelperTest, FindNeighbours) +{ + const auto mock_matrix = MockMatrix<char>(); + + const auto rows = 8U; + const auto columns = 6U; + + const auto position = Vector2({.x = 3, .y = 5}); + + EXPECT_CALL(mock_matrix, get_row_cnt()).WillOnce(testing::Return(rows)); + + EXPECT_CALL(mock_matrix, get_column_cnt()).WillOnce(testing::Return(columns)); + + auto cell_helper = CellHelper<char>(mock_matrix); + + const auto living_neighbour_cells = cell_helper.find_neighbours(position); + + EXPECT_EQ(living_neighbour_cells.size(), 8U); + + EXPECT_THAT( + living_neighbour_cells, + testing::ContainerEq(std::list<Vector2>( + {position + Vector2::up(), + position + Vector2::down(), + position + Vector2::left(), + position + Vector2::right(), + position + Vector2::up() + Vector2::left(), + position + Vector2::up() + Vector2::right(), + position + Vector2::down() + Vector2::left(), + position + Vector2::down() + Vector2::right()}))); +} + |