From 2bff8c999edde11270ecaf6fbd2d24f54d0e360b Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 29 Jun 2022 22:15:36 +0200 Subject: refactor: cell helper take matrix as shared pointer --- test/cell_helper_test.cpp | 74 +++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 38 deletions(-) (limited to 'test/cell_helper_test.cpp') diff --git a/test/cell_helper_test.cpp b/test/cell_helper_test.cpp index c9618fd..36f2a62 100644 --- a/test/cell_helper_test.cpp +++ b/test/cell_helper_test.cpp @@ -1,22 +1,20 @@ -#include "engine/data/vector2.hpp" -#include "game/cell_helper.hpp" - -#include "mocks/matrix.hpp" - #include #include -#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 = MockMatrix(); + auto mock_matrix = std::make_shared>(); auto cell_helper = CellHelper(mock_matrix); @@ -37,135 +35,135 @@ TEST_CASE("CellHelper") 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_row_cnt()).RETURN(MATRIX_ROWS).TIMES(AT_LEAST(1)); - REQUIRE_CALL(mock_matrix, get_column_cnt()) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + 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)) + REQUIRE_CALL(*mock_matrix, get(cell_pos_down_right)) // NOLINTNEXTLINE(readability-identifier-length) .RETURN(' ') .IN_SEQUENCE(matrix_call_seq); @@ -175,7 +173,7 @@ TEST_CASE("CellHelper") SECTION("can find neighbours") { - auto mock_matrix = MockMatrix(); + auto mock_matrix = std::make_shared>(); auto cell_helper = CellHelper(mock_matrix); @@ -185,10 +183,10 @@ TEST_CASE("CellHelper") const auto cell_pos = Vector2({.x = 8, .y = 3}); // NOLINTNEXTLINE(readability-identifier-length) - REQUIRE_CALL(mock_matrix, get_row_cnt()).RETURN(MATRIX_ROWS); + REQUIRE_CALL(*mock_matrix, get_row_cnt()).RETURN(MATRIX_ROWS); // NOLINTNEXTLINE(readability-identifier-length) - REQUIRE_CALL(mock_matrix, get_column_cnt()).RETURN(MATRIX_COLUMNS); + REQUIRE_CALL(*mock_matrix, get_column_cnt()).RETURN(MATRIX_COLUMNS); const auto living_neighbour_cells = cell_helper.find_neighbours(cell_pos); -- cgit v1.2.3-18-g5258