11#include < cstddef>
2+ #include < limits>
23#include < memory>
34#include < type_traits>
45#include < vector>
1617#include < whirlwind/graph/edge_list.hpp>
1718#include < whirlwind/graph/rectangular_grid_graph.hpp>
1819
20+ #include " ../testing/matchers/forest_matchers.hpp"
21+ #include " ../testing/matchers/range_matchers.hpp"
22+
1923namespace {
2024
25+ namespace CM = Catch::Matchers;
2126namespace ww = whirlwind;
2227
2328CATCH_TEST_CASE (" Dial" , " [graph]" )
2429{
25- using D = int ;
26- using G = ww::CSRGraph<>;
30+ using Distance = int ;
31+ using Graph = ww::CSRGraph<>;
32+
33+ constexpr auto max_distance = std::numeric_limits<Distance>::max ();
2734
2835 auto edgelist = ww::EdgeList ();
2936 edgelist.add_edge (0U , 1U );
3037 edgelist.add_edge (1U , 2U );
3138 edgelist.add_edge (2U , 3U );
3239
33- const auto graph = G (edgelist);
40+ const auto graph = Graph (edgelist);
3441 const auto num_buckets = 101U ;
3542
36- auto dial = ww::Dial<D, G >(graph, num_buckets);
43+ auto dial = ww::Dial<Distance, Graph >(graph, num_buckets);
3744
38- using Distance = decltype (dial)::distance_type;
39- using Graph = decltype (dial)::graph_type;
45+ using Distance_ = decltype (dial)::distance_type;
46+ using Graph_ = decltype (dial)::graph_type;
4047 using Vertex = decltype (dial)::vertex_type;
4148 using Edge = decltype (dial)::edge_type;
4249 using Size = decltype (dial)::size_type;
@@ -45,20 +52,29 @@ CATCH_TEST_CASE("Dial", "[graph]")
4552 {
4653 CATCH_CHECK (std::addressof (dial.graph ()) == std::addressof (graph));
4754 CATCH_CHECK (dial.num_buckets () == num_buckets);
55+
4856 CATCH_CHECK (std::size (dial.buckets ()) == num_buckets);
49- using Catch::Matchers::AllMatch;
50- using Catch::Matchers::IsEmpty;
51- CATCH_CHECK_THAT (dial.buckets (), AllMatch (IsEmpty ()));
57+ CATCH_CHECK_THAT (dial.buckets (), CM::AllMatch (CM::IsEmpty ()));
5258 CATCH_CHECK (dial.current_bucket_id () == 0U );
59+
5360 CATCH_CHECK (dial.done ());
61+
62+ using ww::testing::WasReachedBy;
63+ CATCH_CHECK_THAT (graph.vertices (), CM::NoneMatch (WasReachedBy (dial)));
64+
65+ const auto distances =
66+ graph.vertices () | ranges::views::transform ([&](const auto & vertex) {
67+ return dial.distance_to_vertex (vertex);
68+ });
69+ CATCH_CHECK_THAT (distances, ww::testing::AllEqualTo (max_distance));
5470 }
5571
5672 CATCH_SECTION (" {distance,graph,vertex,edge}_type" )
5773 {
58- CATCH_STATIC_REQUIRE ((std::is_same_v<Distance, D >));
59- CATCH_STATIC_REQUIRE ((std::is_same_v<Graph, G >));
60- CATCH_STATIC_REQUIRE ((std::is_same_v<Vertex, G ::vertex_type>));
61- CATCH_STATIC_REQUIRE ((std::is_same_v<Edge, G ::edge_type>));
74+ CATCH_STATIC_REQUIRE ((std::is_same_v<Distance_, Distance >));
75+ CATCH_STATIC_REQUIRE ((std::is_same_v<Graph_, Graph >));
76+ CATCH_STATIC_REQUIRE ((std::is_same_v<Vertex, Graph ::vertex_type>));
77+ CATCH_STATIC_REQUIRE ((std::is_same_v<Edge, Graph ::edge_type>));
6278 CATCH_STATIC_REQUIRE ((std::is_same_v<Size, std::size_t >));
6379 }
6480
@@ -90,9 +106,7 @@ CATCH_TEST_CASE("Dial", "[graph]")
90106 bucket.pop ();
91107 }
92108
93- using Catch::Matchers::AllMatch;
94- using Catch::Matchers::IsEmpty;
95- CATCH_CHECK_THAT (dial.buckets (), AllMatch (IsEmpty ()));
109+ CATCH_CHECK_THAT (dial.buckets (), CM::AllMatch (CM::IsEmpty ()));
96110 }
97111
98112 CATCH_SECTION (" pop_next_unvisited_vertex" )
@@ -106,7 +120,7 @@ CATCH_TEST_CASE("Dial", "[graph]")
106120
107121 const auto [vertex1, distance1] = dial.pop_next_unvisited_vertex ();
108122 CATCH_CHECK (dial.current_bucket_id () == 0U );
109- CATCH_CHECK_THAT (dial.current_bucket (), Catch::Matchers ::IsEmpty ());
123+ CATCH_CHECK_THAT (dial.current_bucket (), CM ::IsEmpty ());
110124 CATCH_CHECK (vertex1 == vertex0);
111125 CATCH_CHECK (distance1 == distance0);
112126 }
@@ -120,24 +134,18 @@ CATCH_TEST_CASE("Dial", "[graph]")
120134
121135 CATCH_CHECK (dial.current_bucket_id () == 0U );
122136 CATCH_CHECK (std::size (dial.current_bucket ()) == std::size (sources));
137+ CATCH_CHECK_THAT (sources, CM::AllMatch (ww::testing::WasReachedBy (dial)));
123138
124- const auto has_reached_sources =
125- sources | ranges::views::transform ([&](const auto & source) {
126- return dial.has_reached_vertex (source);
127- });
128- CATCH_CHECK_THAT (has_reached_sources, Catch::Matchers::AllTrue ());
129-
130- using Catch::Matchers::Contains;
131139 const auto [vertex0, distance0] = dial.pop_next_unvisited_vertex ();
132- CATCH_CHECK_THAT (sources, Contains (vertex0));
140+ CATCH_CHECK_THAT (sources, CM:: Contains (vertex0));
133141 CATCH_CHECK (distance0 == 0 );
134142
135143 const auto [vertex1, distance1] = dial.pop_next_unvisited_vertex ();
136- CATCH_CHECK_THAT (sources, Contains (vertex1));
144+ CATCH_CHECK_THAT (sources, CM:: Contains (vertex1));
137145 CATCH_CHECK (distance1 == 0 );
138146
139147 CATCH_CHECK (dial.current_bucket_id () == 0U );
140- CATCH_CHECK_THAT (dial.current_bucket (), Catch::Matchers ::IsEmpty ());
148+ CATCH_CHECK_THAT (dial.current_bucket (), CM ::IsEmpty ());
141149 CATCH_CHECK (vertex0 != vertex1);
142150 }
143151
@@ -147,19 +155,20 @@ CATCH_TEST_CASE("Dial", "[graph]")
147155 const auto distance0 = 0 ;
148156 dial.add_source (vertex0);
149157
150- CATCH_CHECK_FALSE (dial.has_visited_vertex (vertex0));
158+ using ww::testing::WasVisitedBy;
159+ CATCH_CHECK_THAT (vertex0, !WasVisitedBy (dial));
151160 dial.visit_vertex (vertex0, distance0);
152- CATCH_CHECK (dial. has_visited_vertex ( vertex0));
161+ CATCH_CHECK_THAT ( vertex0, WasVisitedBy (dial ));
153162 CATCH_CHECK (dial.distance_to_vertex (vertex0) == distance0);
154163
155164 const auto edge = 0U ;
156165 const auto vertex1 = 1U ;
157166 const auto distance1 = 10 ;
158167 dial.relax_edge (edge, vertex0, vertex1, distance1);
159- CATCH_CHECK_FALSE (dial. has_visited_vertex ( vertex1));
168+ CATCH_CHECK_THAT ( vertex1, ! WasVisitedBy (dial ));
160169
161170 dial.visit_vertex (vertex1, distance1);
162- CATCH_CHECK (dial. has_visited_vertex ( vertex1));
171+ CATCH_CHECK_THAT ( vertex1, WasVisitedBy (dial ));
163172 CATCH_CHECK (dial.distance_to_vertex (vertex1) == distance1);
164173 }
165174
@@ -178,8 +187,8 @@ CATCH_TEST_CASE("Dial", "[graph]")
178187 const auto length = 10 ;
179188 dial.relax_edge (edge, tail, head, distance + length);
180189
181- CATCH_CHECK (dial. has_reached_vertex ( head));
182- CATCH_CHECK_FALSE (dial. has_visited_vertex ( head));
190+ CATCH_CHECK_THAT ( head, ww::testing::WasReachedBy (dial ));
191+ CATCH_CHECK_THAT ( head, ! ww::testing::WasVisitedBy (dial ));
183192 CATCH_CHECK (dial.distance_to_vertex (head) == distance + length);
184193
185194 const auto bucket_id = dial.get_bucket_id (distance + length);
@@ -216,11 +225,19 @@ CATCH_TEST_CASE("Dial", "[graph]")
216225 }
217226
218227 dial.reset ();
219- using Catch::Matchers::AllMatch;
220- using Catch::Matchers::IsEmpty;
221- CATCH_CHECK_THAT (dial.buckets (), AllMatch (IsEmpty ()));
228+
229+ CATCH_CHECK_THAT (dial.buckets (), CM::AllMatch (CM::IsEmpty ()));
222230 CATCH_CHECK (dial.current_bucket_id () == 0U );
223231 CATCH_CHECK (dial.done ());
232+
233+ using ww::testing::WasReachedBy;
234+ CATCH_CHECK_THAT (graph.vertices (), CM::NoneMatch (WasReachedBy (dial)));
235+
236+ const auto distances =
237+ graph.vertices () | ranges::views::transform ([&](const auto & vertex) {
238+ return dial.distance_to_vertex (vertex);
239+ });
240+ CATCH_CHECK_THAT (distances, ww::testing::AllEqualTo (max_distance));
224241 }
225242}
226243
0 commit comments