CDT++
Causal Dynamical Triangulations in C++
Loading...
Searching...
No Matches
Move_tracker_test.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Causal Dynamical Triangulations in C++ using CGAL
3
4 Copyright © 2021 Adam Getchell
5 ******************************************************************************/
6
10
11#include "Move_tracker.hpp"
12
13#include <doctest/doctest.h>
14
15#include "Manifold.hpp"
16
17using namespace std;
18using namespace manifolds;
19using namespace move_tracker;
20
21SCENARIO("MoveTracker special members" * doctest::test_suite("move_tracker"))
22{
23 spdlog::debug("MoveTracker special members.\n");
24 GIVEN("A MoveTracker.")
25 {
26 WHEN("It's properties are examined.")
27 {
28 THEN("It is no-throw destructible.")
29 {
30 REQUIRE(is_nothrow_destructible_v<MoveTracker<Manifold_3>>);
31 spdlog::debug("It is no-throw destructible.\n");
32 }
33 THEN("It is no-throw default constructible.")
34 {
35 REQUIRE(is_nothrow_default_constructible_v<MoveTracker<Manifold_3>>);
36 spdlog::debug("It is no-throw default constructible.\n");
37 }
38 THEN("It is copy constructible.")
39 {
40 REQUIRE(is_copy_constructible_v<MoveTracker<Manifold_3>>);
41 spdlog::debug("It is copy constructible.\n");
42 }
43 THEN("It is copy assignable.")
44 {
45 REQUIRE(is_copy_assignable_v<MoveTracker<Manifold_3>>);
46 spdlog::debug("It is copy assignable.\n");
47 }
48 THEN("It is no-throw move constructible.")
49 {
50 REQUIRE(is_nothrow_move_constructible_v<MoveTracker<Manifold_3>>);
51 spdlog::debug("Small function optimization supported.");
52 spdlog::debug("It is no-throw move constructible.\n");
53 }
54 THEN("It is no-throw move assignable.")
55 {
56 REQUIRE(is_nothrow_move_assignable_v<MoveTracker<Manifold_3>>);
57 spdlog::debug("It is no-throw move assignable.\n");
58 }
59 THEN("It is no-throw swappable")
60 {
61 REQUIRE(is_nothrow_swappable_v<MoveTracker<Manifold_3>>);
62 spdlog::debug("It is no-throw swappable.\n");
63 }
64 }
65 }
66}
67
68SCENARIO("Move type to integer conversion" *
69 doctest::test_suite("move_tracker"))
70{
71 spdlog::debug("Move type to integer conversion.\n");
72 GIVEN("A move type.")
73 {
74 auto move23 = move_type::TWO_THREE;
75 REQUIRE_EQ(as_integer(move23), 0);
76 auto move32 = move_type::THREE_TWO;
77 REQUIRE_EQ(as_integer(move32), 1);
78 auto move26 = move_type::TWO_SIX;
79 REQUIRE_EQ(as_integer(move26), 2);
80 auto move62 = move_type::SIX_TWO;
81 REQUIRE_EQ(as_integer(move62), 3);
82 auto move44 = move_type::FOUR_FOUR;
83 REQUIRE_EQ(as_integer(move44), 4);
84 }
85}
86
87SCENARIO("Integer to move type conversion" *
88 doctest::test_suite("move_tracker"))
89{
90 spdlog::debug("Integer to move type conversion.\n");
91 GIVEN("An integer.")
92 {
93 auto move_choice = 0;
94 REQUIRE_EQ(as_move(move_choice), move_type::TWO_THREE);
95 move_choice = 1;
96 REQUIRE_EQ(as_move(move_choice), move_type::THREE_TWO);
97 move_choice = 2;
98 REQUIRE_EQ(as_move(move_choice), move_type::TWO_SIX);
99 move_choice = 3;
100 REQUIRE_EQ(as_move(move_choice), move_type::SIX_TWO);
101 move_choice = 4;
102 REQUIRE_EQ(as_move(move_choice), move_type::FOUR_FOUR);
103 }
104}
105
106SCENARIO("MoveTracker functionality" * doctest::test_suite("move_tracker"))
107{
108 spdlog::debug("MoveTracker functionality.\n");
109 GIVEN("A 3D Move_tracker.")
110 {
111 MoveTracker<Manifold_3> tracked_moves;
112 THEN("There are the correct number of elements.")
113 {
114 REQUIRE_EQ(tracked_moves.size(), NUMBER_OF_3D_MOVES);
115 }
116 THEN("Each element is zero-initialized.")
117 {
118 REQUIRE_EQ(tracked_moves.total(), 0);
119 }
120 THEN("Moves can be added.")
121 {
122 // Add +1 to each move
123 tracked_moves.two_three_moves()++;
124 tracked_moves.three_two_moves()++;
125 tracked_moves.two_six_moves()++;
126 tracked_moves.six_two_moves()++;
127 tracked_moves.four_four_moves()++;
128 // Now check that it's added
129 for (auto move : tracked_moves.moves_view()) { REQUIRE_EQ(move, 1); }
130 }
131 THEN("Two move trackers can be added.")
132 {
133 // Add +1 move to left-hand side
134 tracked_moves.two_three_moves() += 1;
135 tracked_moves.three_two_moves() += 1;
136 tracked_moves.two_six_moves() += 1;
137 tracked_moves.six_two_moves() += 1;
138 tracked_moves.four_four_moves() += 1;
139 MoveTracker<Manifold_3> added_moves;
140 added_moves.two_three_moves() += 2;
141 added_moves.three_two_moves() += 2;
142 added_moves.two_six_moves() += 2;
143 added_moves.six_two_moves() += 2;
144 added_moves.four_four_moves() += 2;
145 // Add the MoveTrackers
146 tracked_moves += added_moves;
147
148 // Now check
149 for (auto move : tracked_moves.moves_view()) { REQUIRE_EQ(move, 3); }
150 }
151 }
152 GIVEN("A 4D Move_tracker.")
153 {
154 MoveTracker<Manifold_4> tracked_moves;
155 THEN("There are the correct number of elements.")
156 {
157 REQUIRE_EQ(tracked_moves.size(), NUMBER_OF_4D_MOVES);
158 }
159 THEN("Each element is zero-initialized.")
160 {
161 REQUIRE_EQ(tracked_moves.total(), 0);
162 }
163 THEN("Moves can be added.")
164 {
165 // Add +1 to each move
166 tracked_moves.two_four_moves()++;
167 tracked_moves.four_two_moves()++;
168 tracked_moves.three_three_moves()++;
169 tracked_moves.four_six_moves()++;
170 tracked_moves.six_four_moves()++;
171 tracked_moves.two_eight_moves()++;
172 tracked_moves.eight_two_moves()++;
173 for (auto move : tracked_moves.moves_view()) { REQUIRE_EQ(move, 1); }
174 }
175 THEN("Two move trackers can be added.")
176 {
177 // Add +1 move to left-hand side
178 tracked_moves.two_four_moves() += 1;
179 tracked_moves.four_two_moves() += 1;
180 tracked_moves.three_three_moves() += 1;
181 tracked_moves.four_six_moves() += 1;
182 tracked_moves.six_four_moves() += 1;
183 tracked_moves.two_eight_moves() += 1;
184 tracked_moves.eight_two_moves() += 1;
185 MoveTracker<Manifold_4> added_moves;
186 added_moves.two_four_moves() += 2;
187 added_moves.four_two_moves() += 2;
188 added_moves.three_three_moves() += 2;
189 added_moves.four_six_moves() += 2;
190 added_moves.six_four_moves() += 2;
191 added_moves.two_eight_moves() += 2;
192 added_moves.eight_two_moves() += 2;
193 // Add the Move_trackers
194 tracked_moves += added_moves;
195
196 // Now check
197 for (auto move : tracked_moves.moves_view()) { REQUIRE_EQ(move, 3); }
198 }
199 }
200}
Data structures for manifolds.
Track ergodic moves.
auto as_integer(Enumeration value) -> std::underlying_type_t< Enumeration >
Convert enum to integer.
auto as_move(int const move_choice) -> move_type
Convert integer to move_type.
SCENARIO("Perform bistellar flip on Delaunay triangulation" *doctest::test_suite("bistellar"))
The data and methods to track ergodic moves.
auto two_six_moves() -> auto &
Write access to (2,6) moves.
auto three_three_moves() -> auto &
Write access to (3,3) moves.
auto two_eight_moves() -> auto &
Write access to (2,8) moves.
auto two_four_moves() -> auto &
Write access to (2,4) moves.
auto size() const noexcept
Container size.
auto four_six_moves() -> auto &
Write access to (4,6) moves.
auto four_two_moves() -> auto &
Write access to (4,2) moves.
auto total() const noexcept
Total moves.
auto moves_view() const
Get a view of the moves.
auto four_four_moves() -> auto &
Write access to (4,4) moves.
auto six_four_moves() -> auto &
Write access to (6,4) moves.
auto eight_two_moves() -> auto &
Write access to (8,2) moves.
auto six_two_moves() -> auto &
Write access to (6,2) moves.
auto three_two_moves() -> auto &
Write access to (3,2) moves.
auto two_three_moves() -> auto &
Write access to (2,3) moves.