CDT++
Causal Dynamical Triangulations in C++
Loading...
Searching...
No Matches
Function_ref_test.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Causal Dynamical Triangulations in C++ using CGAL
3
4 Copyright © 2017 Adam Getchell
5 ******************************************************************************/
6
12
13#include <doctest/doctest.h>
14
15#include <tl/function_ref.hpp>
16
17#include "Ergodic_moves_3.hpp"
18
19using namespace std;
20using namespace manifolds;
21
22SCENARIO("Simple Lambda operations" * doctest::test_suite("function_ref"))
23{
24 auto constexpr increment_lambda = [](int a) { return ++a; }; // NOLINT
25 GIVEN("A simple lambda.")
26 {
27 WHEN("Lambda is called with 0.")
28 {
29 THEN("We should get 1.") { REQUIRE_EQ(increment_lambda(0), 1); }
30 }
31
32 WHEN("Lambda is called with 1.")
33 {
34 THEN("We should get 2.") { REQUIRE_EQ(increment_lambda(1), 2); }
35 }
36
37 WHEN("Lambda is called with 5.")
38 {
39 THEN("We should get 6.") { REQUIRE_EQ(increment_lambda(5), 6); }
40 }
41 }
42}
43
44SCENARIO("Complex lambda operations" * doctest::test_suite("function_ref"))
45{
46 GIVEN("A lambda storing a move.")
47 {
48 auto constexpr desired_simplices = 640;
49 auto constexpr desired_timeslices = 4;
50 Manifold_3 manifold(desired_simplices, desired_timeslices);
51 REQUIRE(manifold.is_correct());
52 WHEN("A lambda is constructed for a move.")
53 {
54 auto const move23 = [](Manifold_3& m) { // NOLINT
55 return ergodic_moves::do_23_move(m).value();
56 };
57 THEN("Running the lambda makes the move.")
58 {
59 auto result = move23(manifold);
60 result.update();
61 CHECK(ergodic_moves::check_move(manifold, result,
62 move_tracker::move_type::TWO_THREE));
63 // Human verification
64 fmt::print("Manifold properties:\n");
65 manifold.print_details();
66 fmt::print("Moved manifold properties:\n");
67 result.print_details();
68 }
69 }
70 }
71}
72
73SCENARIO("Function_ref operations" * doctest::test_suite("function_ref"))
74{
75 GIVEN("A simple lambda stored in a function_ref.")
76 {
77 auto const increment = [](int incr) { return ++incr; };
78 tl::function_ref<int(int)> const lambda_ref(increment);
79 WHEN("Function_ref is called with 0.")
80 {
81 THEN("We should get 1.") { REQUIRE_EQ(lambda_ref(1), 2); }
82 }
83 }
84 GIVEN("A function pointer to a move stored in a function_ref.")
85 {
86 auto constexpr desired_simplices = 640;
87 auto constexpr desired_timeslices = 4;
88 Manifold_3 manifold(desired_simplices, desired_timeslices);
89 REQUIRE(manifold.is_correct());
90 tl::function_ref const complex_ref(ergodic_moves::do_23_move);
91 WHEN("The function_ref is invoked.")
92 {
93 auto result = complex_ref(manifold);
94 result->update();
95 THEN("The move from the function_ref is correct.")
96 {
97 CHECK(ergodic_moves::check_move(manifold, result.value(),
98 move_tracker::move_type::TWO_THREE));
99 // Human verification
100 fmt::print("Manifold properties:\n");
101 manifold.print_details();
102 fmt::print("Moved manifold properties:\n");
103 result->print_details();
104 }
105 }
106 }
107 GIVEN("A lambda invoking a move stored in a function_ref.")
108 {
109 auto constexpr desired_simplices = 640;
110 auto constexpr desired_timeslices = 4;
111 Manifold_3 manifold(desired_simplices, desired_timeslices);
112 REQUIRE(manifold.is_correct());
113 auto const move23 = [](Manifold_3& t_manifold) {
114 return ergodic_moves::do_23_move(t_manifold).value();
115 };
116 tl::function_ref<Manifold_3(Manifold_3&)> const complex_ref(move23);
117 WHEN("The function_ref is invoked.")
118 {
119 auto result = complex_ref(manifold);
120 result.update();
121 THEN(
122 "The move stored in the lambda invoked by the function_ref is "
123 "correct.")
124 {
125 CHECK(ergodic_moves::check_move(manifold, result,
126 move_tracker::move_type::TWO_THREE));
127 // Human verification
128 fmt::print("Manifold properties:\n");
129 manifold.print_details();
130 fmt::print("Moved manifold properties:\n");
131 result.print_details();
132 }
133 }
134 }
135}
Pachner moves on 2+1 dimensional foliated Delaunay triangulations.
auto do_23_move(Manifold &t_manifold) -> Expected
Perform a (2,3) move.
SCENARIO("Perform bistellar flip on Delaunay triangulation" *doctest::test_suite("bistellar"))