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
|
#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()})));
}
|