-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathMove_tracker_test.cpp
200 lines (188 loc) · 6.34 KB
/
Move_tracker_test.cpp
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*******************************************************************************
Causal Dynamical Triangulations in C++ using CGAL
Copyright © 2021 Adam Getchell
******************************************************************************/
/// @file Move_tracker_test.cpp
/// @brief Tests of MoveTracker, that is, that moves are tracked properly
/// @author Adam Getchell
#include "Move_tracker.hpp"
#include <doctest/doctest.h>
#include "Manifold.hpp"
using namespace std;
using namespace manifolds;
using namespace move_tracker;
SCENARIO("MoveTracker special members" * doctest::test_suite("move_tracker"))
{
spdlog::debug("MoveTracker special members.\n");
GIVEN("A MoveTracker.")
{
WHEN("It's properties are examined.")
{
THEN("It is no-throw destructible.")
{
REQUIRE(is_nothrow_destructible_v<MoveTracker<Manifold_3>>);
spdlog::debug("It is no-throw destructible.\n");
}
THEN("It is no-throw default constructible.")
{
REQUIRE(is_nothrow_default_constructible_v<MoveTracker<Manifold_3>>);
spdlog::debug("It is no-throw default constructible.\n");
}
THEN("It is copy constructible.")
{
REQUIRE(is_copy_constructible_v<MoveTracker<Manifold_3>>);
spdlog::debug("It is copy constructible.\n");
}
THEN("It is copy assignable.")
{
REQUIRE(is_copy_assignable_v<MoveTracker<Manifold_3>>);
spdlog::debug("It is copy assignable.\n");
}
THEN("It is no-throw move constructible.")
{
REQUIRE(is_nothrow_move_constructible_v<MoveTracker<Manifold_3>>);
spdlog::debug("Small function optimization supported.");
spdlog::debug("It is no-throw move constructible.\n");
}
THEN("It is no-throw move assignable.")
{
REQUIRE(is_nothrow_move_assignable_v<MoveTracker<Manifold_3>>);
spdlog::debug("It is no-throw move assignable.\n");
}
THEN("It is no-throw swappable")
{
REQUIRE(is_nothrow_swappable_v<MoveTracker<Manifold_3>>);
spdlog::debug("It is no-throw swappable.\n");
}
}
}
}
SCENARIO("Move type to integer conversion" *
doctest::test_suite("move_tracker"))
{
spdlog::debug("Move type to integer conversion.\n");
GIVEN("A move type.")
{
auto move23 = move_type::TWO_THREE;
REQUIRE_EQ(as_integer(move23), 0);
auto move32 = move_type::THREE_TWO;
REQUIRE_EQ(as_integer(move32), 1);
auto move26 = move_type::TWO_SIX;
REQUIRE_EQ(as_integer(move26), 2);
auto move62 = move_type::SIX_TWO;
REQUIRE_EQ(as_integer(move62), 3);
auto move44 = move_type::FOUR_FOUR;
REQUIRE_EQ(as_integer(move44), 4);
}
}
SCENARIO("Integer to move type conversion" *
doctest::test_suite("move_tracker"))
{
spdlog::debug("Integer to move type conversion.\n");
GIVEN("An integer.")
{
auto move_choice = 0;
REQUIRE_EQ(as_move(move_choice), move_type::TWO_THREE);
move_choice = 1;
REQUIRE_EQ(as_move(move_choice), move_type::THREE_TWO);
move_choice = 2;
REQUIRE_EQ(as_move(move_choice), move_type::TWO_SIX);
move_choice = 3;
REQUIRE_EQ(as_move(move_choice), move_type::SIX_TWO);
move_choice = 4;
REQUIRE_EQ(as_move(move_choice), move_type::FOUR_FOUR);
}
}
SCENARIO("MoveTracker functionality" * doctest::test_suite("move_tracker"))
{
spdlog::debug("MoveTracker functionality.\n");
GIVEN("A 3D Move_tracker.")
{
MoveTracker<Manifold_3> tracked_moves;
THEN("There are the correct number of elements.")
{
REQUIRE_EQ(tracked_moves.size(), NUMBER_OF_3D_MOVES);
}
THEN("Each element is zero-initialized.")
{
REQUIRE_EQ(tracked_moves.total(), 0);
}
THEN("Moves can be added.")
{
// Add +1 to each move
tracked_moves.two_three_moves()++;
tracked_moves.three_two_moves()++;
tracked_moves.two_six_moves()++;
tracked_moves.six_two_moves()++;
tracked_moves.four_four_moves()++;
// Now check that it's added
for (auto move : tracked_moves.moves_view()) { REQUIRE_EQ(move, 1); }
}
THEN("Two move trackers can be added.")
{
// Add +1 move to left-hand side
tracked_moves.two_three_moves() += 1;
tracked_moves.three_two_moves() += 1;
tracked_moves.two_six_moves() += 1;
tracked_moves.six_two_moves() += 1;
tracked_moves.four_four_moves() += 1;
MoveTracker<Manifold_3> added_moves;
added_moves.two_three_moves() += 2;
added_moves.three_two_moves() += 2;
added_moves.two_six_moves() += 2;
added_moves.six_two_moves() += 2;
added_moves.four_four_moves() += 2;
// Add the MoveTrackers
tracked_moves += added_moves;
// Now check
for (auto move : tracked_moves.moves_view()) { REQUIRE_EQ(move, 3); }
}
}
GIVEN("A 4D Move_tracker.")
{
MoveTracker<Manifold_4> tracked_moves;
THEN("There are the correct number of elements.")
{
REQUIRE_EQ(tracked_moves.size(), NUMBER_OF_4D_MOVES);
}
THEN("Each element is zero-initialized.")
{
REQUIRE_EQ(tracked_moves.total(), 0);
}
THEN("Moves can be added.")
{
// Add +1 to each move
tracked_moves.two_four_moves()++;
tracked_moves.four_two_moves()++;
tracked_moves.three_three_moves()++;
tracked_moves.four_six_moves()++;
tracked_moves.six_four_moves()++;
tracked_moves.two_eight_moves()++;
tracked_moves.eight_two_moves()++;
for (auto move : tracked_moves.moves_view()) { REQUIRE_EQ(move, 1); }
}
THEN("Two move trackers can be added.")
{
// Add +1 move to left-hand side
tracked_moves.two_four_moves() += 1;
tracked_moves.four_two_moves() += 1;
tracked_moves.three_three_moves() += 1;
tracked_moves.four_six_moves() += 1;
tracked_moves.six_four_moves() += 1;
tracked_moves.two_eight_moves() += 1;
tracked_moves.eight_two_moves() += 1;
MoveTracker<Manifold_4> added_moves;
added_moves.two_four_moves() += 2;
added_moves.four_two_moves() += 2;
added_moves.three_three_moves() += 2;
added_moves.four_six_moves() += 2;
added_moves.six_four_moves() += 2;
added_moves.two_eight_moves() += 2;
added_moves.eight_two_moves() += 2;
// Add the Move_trackers
tracked_moves += added_moves;
// Now check
for (auto move : tracked_moves.moves_view()) { REQUIRE_EQ(move, 3); }
}
}
}