1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_vector.hpp>
#include <memory>
#include <trompeloeil.hpp>
#include <vector>
#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<MockMatrix<char>>();
auto cell_helper = CellHelper<char>(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);
}
}
|