#include #include #include #include #include #include "engine/data/vector2.hpp" #include "game/cell_helper.hpp" #include "mocks/matrix.hpp" // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST_CASE("CellHelper") { SECTION("can identify dying cell") { auto mock_matrix = std::make_shared>(); 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.compute_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.compute_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.compute_is_cell_dying(cell_pos) == true); } }