#include "engine/data/vector2.hpp" #include "game/cell_helper.hpp" #include "mocks/matrix.hpp" #include #include #include #include #include #include // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST_CASE("CellHelper") { SECTION("can identify dying cell") { auto mock_matrix = MockMatrix(); auto cell_helper = CellHelper(mock_matrix); constexpr auto MATRIX_ROWS = 8U; constexpr auto MATRIX_COLUMNS = 6U; const auto cell_pos = Vector2({.x = 3, .y = 5}); const auto cell_pos_up = cell_pos + Vector2::up(); const auto cell_pos_down = cell_pos + Vector2::down(); const auto cell_pos_left = cell_pos + Vector2::left(); const auto cell_pos_right = cell_pos + Vector2::right(); const auto cell_pos_up_left = cell_pos + Vector2::up() + Vector2::left(); const auto cell_pos_up_right = cell_pos + Vector2::up() + Vector2::right(); const auto cell_pos_down_left = cell_pos + Vector2::down() + Vector2::left(); const auto cell_pos_down_right = cell_pos + Vector2::down() + Vector2::right(); // NOLINTNEXTLINE(readability-identifier-length) REQUIRE_CALL(mock_matrix, get_row_cnt()).RETURN(MATRIX_ROWS).TIMES(AT_LEAST(1)); REQUIRE_CALL(mock_matrix, get_column_cnt()) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(MATRIX_COLUMNS) .TIMES(AT_LEAST(1)); auto matrix_call_seq = trompeloeil::sequence(); REQUIRE_CALL(mock_matrix, get(cell_pos_up)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN('x') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_down)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_left)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN('x') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_right)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN('x') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_up_left)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_up_right)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN('x') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_down_left)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_down_right)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE(cell_helper.is_cell_dying(cell_pos) == true); REQUIRE_CALL(mock_matrix, get(cell_pos_up)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_down)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN('x') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_left)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_right)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_up_left)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_up_right)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_down_left)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN('x') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_down_right)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE(cell_helper.is_cell_dying(cell_pos) == false); REQUIRE_CALL(mock_matrix, get(cell_pos_up)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_down)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_left)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN('x') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_right)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_up_left)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_up_right)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_down_left)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE_CALL(mock_matrix, get(cell_pos_down_right)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); REQUIRE(cell_helper.is_cell_dying(cell_pos) == true); } SECTION("can find neighbours") { auto mock_matrix = MockMatrix(); auto cell_helper = CellHelper(mock_matrix); constexpr auto MATRIX_ROWS = 12U; constexpr auto MATRIX_COLUMNS = 9U; const auto cell_pos = Vector2({.x = 8, .y = 3}); // NOLINTNEXTLINE(readability-identifier-length) REQUIRE_CALL(mock_matrix, get_row_cnt()).RETURN(MATRIX_ROWS); // NOLINTNEXTLINE(readability-identifier-length) REQUIRE_CALL(mock_matrix, get_column_cnt()).RETURN(MATRIX_COLUMNS); const auto living_neighbour_cells = cell_helper.find_neighbours(cell_pos); REQUIRE(living_neighbour_cells.size() == 5U); REQUIRE_THAT( living_neighbour_cells, Catch::Matchers::Contains(std::vector( {cell_pos + Vector2::up(), cell_pos + Vector2::down(), cell_pos + Vector2::left(), cell_pos + Vector2::up() + Vector2::left(), cell_pos + Vector2::down() + Vector2::left()}))); } }