Sequoia
Loading...
Searching...
No Matches
DynamicUndirectedGraphUnsortableWeightTestingUtilities.hpp
Go to the documentation of this file.
1
2// Copyright Oliver J. Rosten 2023. //
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
13
14namespace sequoia::testing
15{
16 namespace undirected_graph{
19 // x
20 nodew = graph_description::end,
21
22 // /\
23 // \/
24 // x
25 node_0w,
26
27 // /\ /\
28 // \/ \/
29 // x
30 node_0w_0w,
31
32 // /\ /\
33 // \/ \/
34 // x
35 node_0_0w,
36
37 // /\ /\
38 // \/ \/
39 // x
40 node_0w_0,
41
42 // /\
43 // \/
44 // x --- x
45 node_0w_1_node_0,
46
47 // /\
48 // \/
49 // x --- x
50 node_0_1w_node_0w,
51
52 // /\
53 // \/
54 // x --- x
55 node_1_node_1w_0,
56
57 // x ==== x
58 node_1_1w_node_0_0w,
59
60 // x ==== x
61 node_1w_1_node_0_0w,
62
63 // ====
64 // x ==== x
65 node_1_1_1w_1w_node_0w_0w_0_0,
66
67 // /-\
68 // \ /
69 // x ==== x
70 // ====
71 node_0w_1_1_1w_1w_node_0w_0w_0_0
72 };
73 }
74
75 template
76 <
77 class EdgeWeight,
78 class NodeWeight,
79 class EdgeStorageConfig,
80 class NodeWeightStorage
81 >
83 {
84 public:
86 using edge_t = typename graph_t::edge_init_type;
87 using node_weight_type = typename graph_t::node_weight_type;
88 using edges_equivalent_t = std::initializer_list<std::initializer_list<edge_t>>;
89 using transition_graph = typename transition_checker<graph_t>::transition_graph;
90
91 static void execute_operations(regular_test& t)
92 {
93 auto trg{make_weighted_transition_graph(t)};
94
95 auto checker{
96 [&t](std::string_view description, const graph_t& obtained, const graph_t& prediction, const graph_t& parent, std::size_t host, std::size_t target) {
97 t.check(equality, {description, no_source_location}, obtained, prediction);
98 if(host != target) t.check_semantics({description, no_source_location}, prediction, parent);
99 }
100 };
101
103 }
104
105 [[nodiscard]]
106 static graph_t make_and_check(regular_test& t, std::string_view description, edges_equivalent_t edgeInit, std::initializer_list<node_weight_type> nodeInit)
107 {
108 return graph_initialization_checker<graph_t>::make_and_check(t, description, edgeInit, nodeInit);
109 }
110
111 static void check_initialization_exceptions(regular_test& t)
112 {
113 using nodes = std::initializer_list<node_weight_type>;
114
115 // One node
116 t.check_exception_thrown<std::logic_error>("Mismatched loop weights", [](){ return graph_t{{edge_t{0, 1.0, 1.0}, edge_t{0, 1.0, 2.0}}}; });
117
118 // Two nodes
119 t.check_exception_thrown<std::logic_error>("Mismatched weights", [](){ return graph_t{{edge_t{1, 1.0, 2.0}}, {edge_t{0, 2.0, 1.0}}}; });
120
121 t.check_exception_thrown<std::logic_error>("Mismatched edge/node initialization", [](){ return graph_t{{}, nodes{1.0}}; });
122 t.check_exception_thrown<std::logic_error>("Mismatched edge/node initialization", [](){ return graph_t{{{}}, nodes{1.0, 2.0}}; });
123 t.check_exception_thrown<std::logic_error>("Mismatched edge/node initialization", [](){ return graph_t{{{edge_t{0, 1.0, -1.2}, edge_t{0, 1.0, -1.2}}}, nodes{1.0, 2.0}}; });
124 t.check_exception_thrown<std::logic_error>("Mismatched edge/node initialization", [](){ return graph_t{{{}, {}}, nodes{1.0}}; });
125 t.check_exception_thrown<std::logic_error>("Mismatched edge/node initialization", [](){ return graph_t{{{edge_t{1}}, {edge_t{0}}}, nodes{1.0}}; });
126 }
127
128 [[nodiscard]]
129 static transition_graph make_weighted_transition_graph(regular_test& t)
130 {
132 using namespace undirected_graph;
133
134 auto trg{base_ops::make_transition_graph(t)};
135
136 check_initialization_exceptions(t);
137
138 // 'unsortable_weight_graph_description::nodew'
139 trg.add_node(make_and_check(t, t.report(""), {{}}, {{1.0, -1.0}}));
140
141 // 'unsortable_weight_graph_description::node_0w'
142 trg.add_node(make_and_check(t, t.report(""), {{{0, 1.0, -1.0}, {0, 1.0, -1.0}}}, {{0.0}}));
143
144 // 'unsortable_weight_graph_description::node_0w_0w'
145 trg.add_node(make_and_check(t, t.report(""), {{{0, 1.0, -1.0}, {0, 1.0, -1.0}, {0, 1.0, -1.0}, {0, 1.0, -1.0}}}, {{0.0}}));
146
147 // 'unsortable_weight_graph_description::node_0_0w'
148 trg.add_node(
149 [&t](){
150 auto g{make_and_check(t, t.report(""), {{{0, 0.0, 0.0}, {0, 0.0, 0.0}, {0, 1.0, -1.0}, {0, 1.0, -1.0}}}, {{0.0}})};
151 t.check(equality, "Canonical ordering of weighted edges", graph_t{{{{0, 0.0, 0.0}, {0, 1.0, -1.0}, {0, 0.0, 0.0}, {0, 1.0, -1.0}}}, {{0.0}}}, g);
152 return g;
153 }());
154
155 // 'unsortable_weight_graph_description::node_0w_0'
156 trg.add_node(
157 [&t](){
158 auto g{make_and_check(t, t.report(""), {{{0, 1.0, -1.0}, {0, 1.0, -1.0}, {0, 0.0, 0.0}, {0, 0.0, 0.0}}}, {{0.0}})};
159 t.check(equality, "Canonical ordering of weighted edges", graph_t{{{{0, 1.0, -1.0}, {0, 0.0, 0.0}, {0, 0.0, 0.0}, {0, 1.0, -1.0}}}, {{0.0}}}, g);
160 return g;
161 }());
162
163 // 'unsortable_weight_graph_description::node_0w_1_node_0'
164 trg.add_node(make_and_check(t, t.report(""), {{{0, 1.0, -1.0}, {0, 1.0, -1.0}, {1, 0.0, 0.0}}, {{0, 0.0, 0.0}}}, {{}, {}}));
165
166 // 'unsortable_weight_graph_description::node_0_1w_node_0w'
167 trg.add_node(
168 [&t](){
169 auto g{make_and_check(t, t.report(""), {{{0, 1.0, -1.0}, {0, 1.0, -1.0}, {1, 0.0, 0.0}}, {{0, 0.0, 0.0}}}, {{}, {}})};
170 t.check(equality, "Canonical ordering of weighted edges", graph_t{{{{0, 1.0, -1.0}, {1, 0.0, 0.0}, {0, 1.0, -1.0}}, {{0, 0.0, 0.0}}}, {{}, {}}}, g);
171 return g;
172 }());
173
174 // 'unsortable_weight_graph_description::node_1_node_1w_0,'
175 trg.add_node(
176 [&t](){
177 auto g{make_and_check(t, t.report(""), {{{1, 0.0, 0.0}}, {{0, 0.0, 0.0}, {1, 1.0, -1.0}, {1, 1.0, -1.0}}}, {{}, {}})};
178 t.check(equality, "Canonical ordering of weighted edges", graph_t{{{{1, 0.0, 0.0}}, {{1, 1.0, -1.0}, {0, 0.0, 0.0}, {1, 1.0, -1.0}}}, {{}, {}}}, g);
179 return g;
180 }());
181
182 // 'unsortable_weight_graph_description::node_1_1w_node_0_0w'
183 trg.add_node(make_and_check(t, t.report(""), {{{1, 0.0, 0.0}, {1, 1.0, -1.0}}, {{0, 0.0, 0.0}, {0, 1.0, -1.0}}}, {{}, {}}));
184
185 // 'unsortable_weight_graph_description::node_1w_1_node_0_0w'
186 trg.add_node(make_and_check(t, t.report(""), {{{1, 1.0, -1.0}, {1, 0.0, 0.0}}, {{0, 0.0, 0.0}, {0, 1.0, -1.0}}}, {{}, {}}));
187
188 // 'unsortable_weight_graph_description::node_1_1_1w_1w_node_0w_0w_0_0,'
189 trg.add_node(
190 [&t](){
191 auto g{make_and_check(t, t.report(""), {{{1, 0.0, 0.0}, {1, 0.0, 0.0}, {1, 1.0, -1.0}, {1, 1.0, -1.0}}, {{0, 1.0, -1.0}, {0, 1.0, -1.0}, {0, 0.0, 0.0}, {0, 0.0, 0.0}}}, {{}, {}})};
192 t.check(equality,
193 t.report("Canonical ordering of weighted edges"),
194 graph_t{{{{1, 0.0, 0.0}, {1, 1.0, -1.0}, {1, 1.0, -1.0}, {1, 0.0, 0.0}},
195 {{0, 1.0, -1.0}, {0, 0.0, 0.0}, {0, 1.0, -1.0}, {0, 0.0, 0.0}}}, {{}, {}}},
196 g);
197
198 return g;
199 }());
200
201 // 'unsortable_weight_graph_description::node_0w_1_1_1w_1w_node_0w_0w_0_0,'
202 trg.add_node(
203 [&t](){
204 auto g{make_and_check(t,
205 t.report(""),
206 {{{0, 1.0, -1.0}, {0, 1.0, -1.0}, {1, 0.0, 0.0}, {1, 0.0, 0.0}, {1, 1.0, -1.0}, {1, 1.0, -1.0}},
207 {{0, 1.0, -1.0}, {0, 1.0, -1.0}, {0, 0.0, 0.0}, {0, 0.0, 0.0}}},
208 {{}, {}})};
209 t.check(equality,
210 t.report("Canonical ordering of weighted edges"),
211 graph_t{{{{1, 0.0, 0.0}, {0, 1.0, -1.0}, {1, 1.0, -1.0}, {1, 1.0, -1.0}, {1, 0.0, 0.0}, {0, 1.0, -1.0}},
212 {{0, 1.0, -1.0}, {0, 0.0, 0.0}, {0, 1.0, -1.0}, {0, 0.0, 0.0}}}, {{}, {}}},
213 g);
214
215 return g;
216 }());
217
218 return trg;
219 }
220 };
221
222
223}
unsortable_weight_graph_description
Convention: the indices following 'node' - separated by underscores - give the target node of the ass...
Definition: DynamicUndirectedGraphUnsortableWeightTestingUtilities.hpp:18
Definition: DynamicGraph.hpp:303
Definition: DynamicGraph.hpp:360
class template from which all concrete tests should derive.
Definition: FreeTestCore.hpp:144
Exposes elementary check methods, with the option to plug in arbitrary Extenders to compose functiona...
Definition: FreeCheckers.hpp:708
Definition: DynamicUndirectedGraphTestingUtilities.hpp:138
Definition: DynamicUndirectedGraphUnsortableWeightTestingUtilities.hpp:83
Definition: DynamicGraphTestingUtilities.hpp:173
Definition: StateTransitionUtilities.hpp:77