-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathMove_always_test.cpp
178 lines (170 loc) · 5.95 KB
/
Move_always_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
/*******************************************************************************
Causal Dynamical Triangulations in C++ using CGAL
Copyright © 2021 Adam Getchell
******************************************************************************/
/// @file Move_always_test.cpp
/// @brief Tests for the Move Always algorithm
/// @author Adam Getchell
#include "Move_always.hpp"
#include <doctest/doctest.h>
using namespace std;
using namespace manifolds;
SCENARIO("MoveStrategy<MOVE_ALWAYS> special member and swap properties" *
doctest::test_suite("move_always"))
{
spdlog::debug(
"MoveStrategy<MOVE_ALWAYS> special member and swap properties.\n");
GIVEN("A Move always move strategy.")
{
WHEN("Special members are examined.")
{
THEN("It is no-throw destructible.")
{
REQUIRE(is_nothrow_destructible_v<MoveAlways_3>);
REQUIRE(is_nothrow_destructible_v<MoveAlways_4>);
spdlog::debug("It is no-throw destructible.\n");
}
THEN("It is no-throw default constructible.")
{
REQUIRE(is_nothrow_default_constructible_v<MoveAlways_3>);
REQUIRE(is_nothrow_default_constructible_v<MoveAlways_4>);
spdlog::debug("It is no-throw default constructible.\n");
}
THEN("It is no-throw copy constructible.")
{
REQUIRE(is_nothrow_copy_constructible_v<MoveAlways_3>);
REQUIRE(is_nothrow_copy_constructible_v<MoveAlways_4>);
spdlog::debug("It is no-throw copy constructible.\n");
}
THEN("It is no-throw copy assignable.")
{
REQUIRE(is_nothrow_copy_assignable_v<MoveAlways_3>);
REQUIRE(is_nothrow_copy_assignable_v<MoveAlways_4>);
spdlog::debug("It is no-throw copy assignable.\n");
}
THEN("It is no-throw move constructible.")
{
REQUIRE(is_nothrow_move_constructible_v<MoveAlways_3>);
REQUIRE(is_nothrow_move_constructible_v<MoveAlways_4>);
spdlog::debug("It is no-throw move constructible.\n");
}
THEN("It is no-throw move assignable.")
{
REQUIRE(is_nothrow_move_assignable_v<MoveAlways_3>);
REQUIRE(is_nothrow_move_assignable_v<MoveAlways_4>);
spdlog::debug("It is no-throw move assignable.\n");
}
THEN("It is no-throw swappable.")
{
REQUIRE(is_nothrow_swappable_v<MoveAlways_3>);
REQUIRE(is_nothrow_swappable_v<MoveAlways_4>);
spdlog::debug("It is no-throw swappable.\n");
}
THEN("It is constructible from 2 parameters.")
{
REQUIRE(is_constructible_v<MoveAlways_3, Int_precision, Int_precision>);
REQUIRE(is_constructible_v<MoveAlways_4, Int_precision, Int_precision>);
spdlog::debug("It is constructible from 2 parameters.\n");
}
}
}
}
SCENARIO("MoveAlways member functions" * doctest::test_suite("move_always"))
{
spdlog::debug("MoveAlways member functions.\n");
GIVEN("A correctly-constructed Manifold_3.")
{
auto constexpr simplices = 640;
auto constexpr timeslices = 4;
Manifold_3 const manifold(simplices, timeslices);
REQUIRE(manifold.is_correct());
WHEN("A MoveAlways_3 is constructed.")
{
auto constexpr passes = 10;
auto constexpr checkpoint = 5;
MoveAlways_3 const mover(passes, checkpoint);
THEN("The correct passes and checkpoints are instantiated.")
{
CHECK_EQ(mover.passes(), passes);
CHECK_EQ(mover.checkpoint(), checkpoint);
}
THEN("Attempted, successful, and failed moves are zero-initialized.")
{
CHECK_EQ(mover.get_attempted().total(), 0);
CHECK_EQ(mover.get_succeeded().total(), 0);
CHECK_EQ(mover.get_failed().total(), 0);
}
}
WHEN("A MoveAlways_3 algorithm is instantiated.")
{
auto constexpr passes = 1;
auto constexpr checkpoint = 1;
MoveAlways_3 const mover(passes, checkpoint);
THEN("The correct passes and checkpoints are instantiated.")
{
CHECK_EQ(mover.passes(), passes);
CHECK_EQ(mover.checkpoint(), checkpoint);
}
THEN("Attempted moves and successful moves are zero-initialized.")
{
CHECK_EQ(mover.get_attempted().total(), 0);
CHECK_EQ(mover.get_succeeded().total(), 0);
CHECK_EQ(mover.get_failed().total(), 0);
}
}
}
}
// This may take a while, so the scenario decorated with doctest::skip()
// to disable by default
SCENARIO("Using the MoveAlways algorithm" * doctest::test_suite("move_always") *
doctest::skip())
{
spdlog::debug("Using the MoveAlways algorithm.\n");
GIVEN("A correctly-constructed Manifold_3.")
{
auto constexpr simplices = 64;
auto constexpr timeslices = 3;
Manifold_3 const manifold(simplices, timeslices);
REQUIRE(manifold.is_correct());
WHEN("A MoveAlways_3 algorithm is used.")
{
auto constexpr passes = 1;
auto constexpr checkpoint = 1;
MoveAlways_3 mover(passes, checkpoint);
THEN("A lot of moves are made.")
{
auto result = mover(manifold);
// Output
CHECK(result.is_valid());
AND_THEN(
"The correct number of attempted, successful, and failed moves are "
"made.")
{
CHECK_EQ(mover.get_attempted().total(),
mover.get_succeeded().total() + mover.get_failed().total());
// Human verification
mover.print_results();
}
}
}
}
GIVEN("A 4D manifold.")
{
WHEN("A MoveStrategy4 is constructed.")
{
auto constexpr passes = 1;
auto constexpr checkpoint = 1;
MoveAlways_4 const mover(passes, checkpoint);
THEN("The correct passes and checkpoints are instantiated.")
{
CHECK_EQ(mover.passes(), passes);
CHECK_EQ(mover.checkpoint(), checkpoint);
}
THEN("Attempted moves and successful moves are zero-initialized.")
{
CHECK_EQ(mover.get_attempted().two_four_moves(), 0);
CHECK_EQ(mover.get_failed().two_four_moves(), 0);
}
}
}
}