17namespace sequoia::testing
19 namespace undirected_embedded_graph{
22 enum meta_data_graph_description : std::size_t {
57 class EdgeStorageConfig,
58 class NodeWeightStorage
64 using edge_t =
typename graph_t::edge_init_type;
65 using node_weight_type =
typename graph_t::node_weight_type;
66 using edges_equivalent_t = std::initializer_list<std::initializer_list<edge_t>>;
71 auto trg{make_meta_data_transition_graph(t)};
74 [&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) {
75 t.check(equality, {description, no_source_location}, obtained, prediction);
76 if(host != target) t.check_semantics({description, no_source_location}, prediction, parent);
84 static graph_t make_and_check(
regular_test& t, std::string_view description, edges_equivalent_t init)
89 static void check_initialization_exceptions(
regular_test& t)
91 using namespace maths;
94 t.check_exception_thrown<std::out_of_range>(
"Target index of edge out of range", [](){
return graph_t{{{1, 0, 0.5f}}}; });
95 t.check_exception_thrown<std::out_of_range>(
"Complimentary index of edge out of range", [](){
return graph_t{{{0, 1, 0.5f}}}; });
96 t.check_exception_thrown<std::logic_error>(
"Self-referential complimentary index", [](){
return graph_t{{{0, 0, 0.5f}}}; });
97 t.check_exception_thrown<std::logic_error>(
"Mismatched complimentary indices", [](){
return graph_t{{{0, 1, 0.5f}, {0, 1, 0.5f}}}; });
98 t.check_exception_thrown<std::logic_error>(
"Mismatched complimentary indices", [](){
return graph_t{{{0, 1, 0.5f}, {0, 2, 0.5f}, {0, 0, 0.5f}}}; });
101 t.check_exception_thrown<std::logic_error>(
"Mismatched complimentary indices", [](){
return graph_t{{{1, 0, 0.5f}, {0, 2, 0.5f}, {0, 1, 0.5f}}, {{0, 1, 0.5f}}}; });
105 static transition_graph make_meta_data_transition_graph(
regular_test& t)
107 using meta_data_t = EdgeMetaData;
108 using namespace undirected_embedded_graph;
110 check_initialization_exceptions(t);
112 return transition_graph{
118 meta_data_graph_description::node_0a_0b,
119 t.report(
"Add loop"),
121 g.join(0, 0, 0.0f, 0.5f);
126 meta_data_graph_description::node_0b_0a,
127 t.report(
"Add loop"),
129 g.join(0, 0, 0.5f, 0.0f);
134 meta_data_graph_description::node_0a_0b,
135 t.report(
"Insert loop"),
137 g.insert_join(g.cbegin_edges(0), 1, 0.0f, 0.5f);
142 meta_data_graph_description::node_0b_0a,
143 t.report(
"Insert loop"),
145 g.insert_join(g.cbegin_edges(0), g.cbegin_edges(0), 0.0f, 0.5f);
152 meta_data_graph_description::node_0b_0a,
153 t.report(
"Set edge meta data"),
155 g.set_edge_meta_data(g.cbegin_edges(0), 0.5f);
160 meta_data_graph_description::node_0b_0a,
161 t.report(
"Set edge meta data"),
163 g.set_edge_meta_data(g.cbegin_edges(0), meta_data_t{0.5f});
168 meta_data_graph_description::node_0b_0a,
169 t.report(
"Mutate edge meta data"),
171 t.check(equality,
"Mutate return value", g.mutate_edge_meta_data(g.cbegin_edges(0), [](meta_data_t& m) { m += 0.5f;
return 42; }), 42);
176 meta_data_graph_description::node_0a_0b,
177 t.report(
"Set meta data via reverse iterator"),
179 g.set_edge_meta_data(g.crbegin_edges(0), 0.5f);
184 meta_data_graph_description::node_0a_0b,
185 t.report(
"Mutate edge meta data via reverse iterator"),
187 t.check(equality,
"Mutate return value", g.mutate_edge_meta_data(g.crbegin_edges(0), [](meta_data_t& m) { m += 0.5f;
return 42; }), 42);
198 meta_data_graph_description::node_1b_node_0a,
199 t.report(
"Join {0,1}"),
201 g.join(0, 1, 0.5f, 0.0f);
206 meta_data_graph_description::node_1b_node_0a,
207 t.report(
"Join {0,1}"),
209 g.insert_join(g.cbegin_edges(0), g.cbegin_edges(1), 0.5f, 0.0f);
214 meta_data_graph_description::node_1b_node_0a,
215 t.report(
"Join {0,1}"),
217 g.insert_join(g.cbegin_edges(1), g.cbegin_edges(0), 0.0f, 0.5f);
227 make_and_check(t, t.report(
""), {}),
230 make_and_check(t, t.report(
""), {{}}),
233 make_and_check(t, t.report(
""), {{{0, 1, 0.0f}, {0, 0, 0.0f}}}),
236 make_and_check(t, t.report(
""), {{{0, 1, 0.0f}, {0, 0, 0.5f}}}),
239 make_and_check(t, t.report(
""), {{{0, 1, 0.5f}, {0, 0, 0.0f}}}),
242 make_and_check(t, t.report(
""), {{}, {}}),
245 make_and_check(t, t.report(
""), {{{1, 0, 0.5f}}, {{0, 0, 0.0f}}})
Utilities for checking regular semantics.
Facility to define tests via a graph comprising states of an object and transitions between them.
Definition: DynamicGraph.hpp:303
Definition: DynamicGraph.hpp:473
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: DynamicGraphTestingUtilities.hpp:173
Definition: StateTransitionUtilities.hpp:77