Sequoia
Loading...
Searching...
No Matches
EdgeTestingUtilities.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2019. //
3// Distributed under the GNU GENERAL PUBLIC LICENSE, Version 3.0. //
4// (See accompanying file LICENSE.md or copy at //
5// https://www.gnu.org/licenses/gpl-3.0.en.html) //
7
8#pragma once
9
14
15namespace sequoia::testing
16{
17 namespace impl
18 {
19 template<class CheckerType, test_mode Mode, class Edge, class Prediction>
20 void check_partial([[maybe_unused]] CheckerType flavour, test_logger<Mode>& logger, const Edge& edge, const Prediction& prediction)
21 {
22 check(equality, "Target node incorrect", logger, edge.target_node(), prediction.target_node());
23
24 if constexpr (!std::is_empty_v<typename Edge::weight_type>)
25 {
26 check(flavour, "Weight incorrect", logger, edge.weight(), prediction.weight());
27 }
28
29 if constexpr(!std::is_empty_v<typename Edge::meta_data_type>)
30 {
31 check(flavour, "Meta data incorrect", logger, edge.meta_data(), prediction.meta_data());
32 }
33 }
34
35 template<test_mode Mode, class Edge, class Prediction>
36 void check_complementary(test_logger<Mode>& logger, const Edge& edge, const Prediction& prediction)
37 {
38 check(equality, "Complementary index incorrect", logger, edge.complementary_index(), prediction.complementary_index());
39 }
40 }
41
42 template<class WeightHandler, class MetaData, std::integral IndexType>
43 requires object::handler<WeightHandler>
44 struct value_tester<maths::partial_edge<WeightHandler, MetaData, IndexType>>
45 {
47 using weight_type = typename type::weight_type;
48
49 template<class CheckerType, test_mode Mode>
50 static void test(CheckerType flavour, test_logger<Mode>& logger, const type& edge, const type& prediction)
51 {
52 impl::check_partial(flavour, logger, edge, prediction);
53 }
54
55 template<test_mode Mode, class OtherHandler>
56 requires (object::handler<OtherHandler> && !std::is_same_v<WeightHandler, OtherHandler>)
57 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& edge, const maths::partial_edge<OtherHandler, MetaData, IndexType>& prediction)
58 {
59 impl::check_partial(with_best_available, logger, edge, prediction);
60 }
61
62 template<test_mode Mode>
63 requires std::is_empty_v<weight_type> && std::is_empty_v<MetaData>
64 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& edge, const IndexType& target)
65 {
66 check(equality, "Target node incorrect", logger, edge.target_node(), target);
67 }
68
69 template<test_mode Mode>
70 requires (!std::is_empty_v<weight_type>) && std::is_empty_v<MetaData>
71 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& edge, const std::pair<IndexType, weight_type>& prediction)
72 {
73 check(equality, "Target node incorrect", logger, edge.target_node(), prediction.first);
74 check(equality, "Weight incorrect", logger, edge.weight(), prediction.second);
75 }
76
77 template<test_mode Mode>
78 requires std::is_empty_v<weight_type> && (!std::is_empty_v<MetaData>)
79 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& edge, const std::pair<IndexType, MetaData>& prediction)
80 {
81 check(equality, "Target node incorrect", logger, edge.target_node(), prediction.first);
82 check(equality, "Weight incorrect", logger, edge.meta_data(), prediction.second);
83 }
84
85 template<test_mode Mode>
86 requires (!std::is_empty_v<weight_type>) && (!std::is_empty_v<MetaData>)
87 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& edge, const std::tuple<IndexType, MetaData, weight_type>& prediction)
88 {
89 check(equality, "Target node incorrect", logger, edge.target_node(), std::get<0>(prediction));
90 check(equality, "Weight incorrect", logger, edge.weight(), std::get<2>(prediction));
91 check(equality, "Meta data incorrect", logger, edge.meta_data(), std::get<1>(prediction));
92 }
93 };
94
95 template<class WeightHandler, class MetaData, std::integral IndexType>
97 struct value_tester<maths::embedded_partial_edge<WeightHandler, MetaData, IndexType>>
98 {
100 using weight_type = typename type::weight_type;
101
102 template<class CheckerType, test_mode Mode>
103 static void test(CheckerType flavour, test_logger<Mode>& logger, const type& edge, const type& prediction)
104 {
105 impl::check_partial(flavour, logger, edge, prediction);
106 impl::check_complementary(logger, edge, prediction);
107 }
108
109 template<test_mode Mode, class OtherHandler>
110 requires (object::handler<OtherHandler> && !std::is_same_v<WeightHandler, OtherHandler>)
112 {
113 impl::check_partial(with_best_available, logger, edge, prediction);
114 impl::check_complementary(logger, edge, prediction);
115 }
116
117 template<test_mode Mode>
118 requires std::is_empty_v<weight_type>&& std::is_empty_v<MetaData>
119 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& edge, const std::pair<IndexType, IndexType>& prediction)
120 {
121 check(equality, "Target node incorrect", logger, edge.target_node(), prediction.first);
122 check(equality, "Complementary index incorrect", logger, edge.complementary_index(), prediction.second);
123 }
124
125 template<test_mode Mode>
126 requires (!std::is_empty_v<weight_type>) && std::is_empty_v<MetaData>
127 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& edge, const std::tuple<IndexType, IndexType, weight_type>& prediction)
128 {
129 check(equality, "Target node incorrect", logger, edge.target_node(), std::get<0>(prediction));
130 check(equality, "Complementary index incorrect", logger, edge.complementary_index(), std::get<1>(prediction));
131 check(equality, "Weight incorrect", logger, edge.weight(), std::get<2>(prediction));
132 }
133
134 template<test_mode Mode>
135 requires std::is_empty_v<weight_type> && (!std::is_empty_v<MetaData>)
136 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& edge, const std::tuple<IndexType, IndexType, MetaData>& prediction)
137 {
138 check(equality, "Target node incorrect", logger, edge.target_node(), std::get<0>(prediction));
139 check(equality, "Complementary index incorrect", logger, edge.complementary_index(), std::get<1>(prediction));
140 check(equality, "Weight incorrect", logger, edge.meta_data(), std::get<2>(prediction));
141 }
142
143 template<test_mode Mode>
144 requires (!std::is_empty_v<weight_type>) && (!std::is_empty_v<MetaData>)
145 static void test(equivalence_check_t, test_logger<Mode>& logger, const type& edge, const std::tuple<IndexType, IndexType, MetaData, weight_type>& prediction)
146 {
147 check(equality, "Target node incorrect", logger, edge.target_node(), std::get<0>(prediction));
148 check(equality, "Complementary index incorrect", logger, edge.complementary_index(), std::get<1>(prediction));
149 check(equality, "Weight incorrect", logger, edge.weight(), std::get<3>(prediction));
150 check(equality, "Meta data incorrect", logger, edge.meta_data(), std::get<2>(prediction));
151 }
152 };
153}
Various edge types for use by graphs.
bool check(CheckType flavour, std::string description, test_logger< Mode > &logger, Iter first, Sentinel last, PredictionIter predictionFirst, PredictionSentinel predictionLast, tutor< Advisor > advisor={})
The workhorse for comparing the contents of ranges.
Definition: FreeCheckers.hpp:377
Utilities for checking regular semantics.
Decoration of a partial_edge to record the location on the target node into which the edge is embedde...
Definition: Edge.hpp:328
A concrete edge containing a target index and, optionally, a weight.
Definition: Edge.hpp:303
Definition: TestLogger.hpp:183
Definition: HandlerTraits.hpp:20
Definition: FreeCheckers.hpp:87
class template, specializations of which implement various comparisons for the specified type.
Definition: FreeCheckers.hpp:78