59#include <gtest/gtest.h>
74 std::string text(
const std::multiset<int> & s)
82 std::string text(
const std::vector<int> & v)
85 for (
size_t i = 0; i < v.size(); ++i)
93 std::vector<bool>
nodes;
94 std::vector<bool>
arcs;
96 explicit Alive(
const Spec & s)
100 void remove_node(
const Spec & s,
int x)
102 nodes[size_t(x)] =
false;
103 for (
size_t i = 0; i < s.
arcs.size(); ++i)
104 if (s.
arcs[i][0] == x or s.
arcs[i][1] == x)
110 std::multiset<int> model_list(
const Spec & s,
const Alive & alive,
int x,
bool digraph)
112 std::multiset<int>
r;
113 for (
size_t i = 0; i < s.
arcs.size(); ++i)
114 if (alive.arcs[i]
and (s.
arcs[i][0] == x or (not digraph
and s.
arcs[i][1] == x)))
120 std::multiset<int> model_end(
const Spec & s,
const Alive & alive,
int x,
int e)
122 std::multiset<int>
r;
123 for (
size_t i = 0; i < s.
arcs.size(); ++i)
124 if (alive.arcs[i]
and s.
arcs[i][
size_t(e)] == x)
130 int other_end(
const Spec & s,
int i,
int x)
132 return s.
arcs[size_t(i)][0] == x ? s.
arcs[size_t(i)][1] : s.
arcs[size_t(i)][0];
137 std::vector<int> forward(
It it)
152 std::string incidence_error(
const GT & g,
const Spec & s,
const Alive & alive)
155 const size_t n = size_t(std::count(alive.nodes.begin(), alive.nodes.end(),
true));
156 const size_t m = size_t(std::count(alive.arcs.begin(), alive.arcs.end(),
true));
159 +
" arcs, not " + std::to_string(n) +
" and " + std::to_string(
m);
161 std::vector<typename GT::Node *> node(
size_t(s.
n),
nullptr);
166 const int x =
num(p);
167 if (x < 0 or x >= s.
n or not alive.nodes[
size_t(x)] or node[
size_t(x)] !=
nullptr)
168 return "the node " + std::to_string(x) +
" is not of the graph, or is twice";
172 return "the node iterator gives " + std::to_string(seen) +
" nodes";
174 std::vector<bool> arc_seen(s.
arcs.size(),
false);
178 const int i =
num(a);
179 if (i < 0 or
size_t(i) >= s.
arcs.size() or not alive.arcs[
size_t(i)] or arc_seen[
size_t(i)])
180 return "the arc " + std::to_string(i) +
" is not of the graph, or is twice";
181 arc_seen[size_t(i)] =
true;
184 return "the ends of the arc " + std::to_string(i) +
" are wrong";
186 if (std::count(arc_seen.begin(), arc_seen.end(),
true) != std::ptrdiff_t(
m))
187 return "the arc iterator misses arcs";
189 for (
int x = 0; x < s.
n; ++x)
191 if (not alive.nodes[
size_t(x)])
193 auto * p = node[size_t(x)];
194 const auto want = model_list(s, alive, x, digraph);
196 return "get_num_arcs(" + std::to_string(x) +
") is " + std::to_string(g.
get_num_arcs(p))
197 +
", not " + std::to_string(want.size());
198 std::multiset<int> got;
199 for (
typename GT::Node_Arc_Iterator it(p); it.
has_curr(); it.
next_ne())
203 const int i =
num(a);
205 or
num(it.get_tgt_node_ne()) != other_end(s, i, x))
206 return "the arc " + std::to_string(i) +
" from " + std::to_string(x)
207 +
" goes to the wrong node";
210 return "the list of " + std::to_string(x) +
" is " + text(got) +
", not " + text(want);
223 using GT = TypeParam;
227 Check incidence(
"the counts, the iterators and the lists of the nodes");
228 Check out(
"Out_Iterator and the out_ methods");
229 Check in(
"In_Iterator(g, p) and the in_ methods");
230 Check in_free(
"GT::In_Iterator(g, p) and the in_ functions that take the graph");
231 Check in_list(
"In_Iterator(p) and the in_ functions of the node, if not directed");
232 Check index(
"In_Arcs_Index");
234 Check directed(
"search_directed_arc(u, v)");
239 const Alive alive(s);
243 if (
auto e = incidence_error(b.
g, s, alive); not e.empty())
244 incidence.
fail(s, e);
246 for (
int x = 0; x < s.
n; ++x)
249 const std::string at =
"at " + std::to_string(x) +
": ";
255 size_t traversed,
bool all_ok)
258 const auto want = model_end(s, alive, x, e);
259 std::multiset<int> want_nodes;
261 want_nodes.insert(s.
arcs[
size_t(i)][size_t(1 - e)]);
262 std::multiset<int> got_it(it_arcs.begin(), it_arcs.end()), got_arcs, got_nodes,
263 pair_arcs, pair_nodes;
271 pair_nodes.insert(
num(std::get<1>(it.
get_curr())));
274 check.fail(s, at +
"the iterator gives " + text(got_it) +
", not " + text(want));
275 else if (got_arcs != want or pair_arcs != want)
276 check.fail(s, at +
"the arcs are " + text(got_arcs) +
", not " + text(want));
277 else if (got_nodes != want_nodes or pair_nodes != want_nodes)
278 check.fail(s, at +
"the nodes are " + text(got_nodes) +
", not " + text(want_nodes));
279 else if (degree != want.size() or traversed != want.size() or not all_ok)
280 check.fail(s, at +
"the degree is " + std::to_string(degree) +
", not "
281 + std::to_string(want.size()));
285 size_t traversed = 0;
293 size_t traversed = 0;
300 size_t traversed = 0;
307 if constexpr (not DigraphType<GT>)
309 size_t traversed = 0;
310 for_each_in_arc<GT>(p, [&] (
Arc *) { ++traversed; });
311 const bool all_ok = all_in_arc<GT>(p, into_p)
and traverse_in_arcs<GT>(p, into_p);
312 check_end(in_list, 1, forward(
In_Iterator<GT>(p)), in_arcs<GT>(p), in_nodes<GT>(p),
313 in_pairs<GT>(p), in_degree<GT>(p), traversed, all_ok);
318 const auto want = model_end(s, alive, x, 1);
319 const auto got = forward(in_arcs_index.
get_it(p));
320 if (std::multiset<int>(got.begin(), got.end()) != want
321 or in_arcs_index.
in_degree(p) != want.size())
322 index.
fail(s, at +
"gives " + text(got) +
", not " + text(want));
327 index.
fail(s, at +
"the node of an arc is not its source");
332 for (
int y = 0;
y < s.
n; ++
y)
335 bool joined =
false, from_to =
false;
336 for (
const auto & a : s.
arcs)
338 from_to = from_to or (a[0] == x
and a[1] ==
y);
339 joined = joined or (a[0] == x
and a[1] ==
y) or (a[0] ==
y and a[1] == x);
345 const bool want = digraph ? from_to : joined;
346 if ((a !=
nullptr) != want)
347 search.fail(s, at +
"to " + std::to_string(
y) + (want ?
" finds no arc" :
" finds an arc"));
351 search.fail(s, at +
"to " + std::to_string(
y) +
" finds an arc between other nodes");
357 if ((a !=
nullptr) != from_to)
358 directed.
fail(s, at +
"to " + std::to_string(
y)
359 + (from_to ?
" finds no arc" :
" finds an arc"));
361 directed.
fail(s, at +
"to " + std::to_string(
y) +
" finds an arc of other ends");
386 template <
class GT,
class It>
387 std::string walk_error(
const Spec & s,
Built<GT> & b,
int x,
int e,
unsigned long hidden,
It it)
390 const Alive alive(s);
391 std::multiset<int> want = e < 0 ? model_list(s, alive, x, digraph) : model_end(s, alive, x, e);
392 for (
auto i = want.begin(); i != want.end(); )
395 const auto first = forward(it);
396 if (std::multiset<int>(first.begin(), first.end()) != want)
397 return "forward it gives " + text(first) +
", not " + text(want);
402 if (
const auto again = forward(it); again != first)
403 return "after reset_first() it gives " + text(again) +
", not " + text(first);
409 std::vector<int> back;
412 std::reverse(back.begin(), back.end());
414 return "backward it gives " + text(back) +
" reversed, not " + text(first);
421 template <
class GT,
template <
class,
class>
class It>
422 std::string iterator_error(
const Spec & s,
Built<GT> & b,
int x,
int e,
unsigned long hidden)
431 using GT = TypeParam;
435 Check node_arc(
"Node_Arc_Iterator");
437 Check in(
"In_Iterator(g, p)");
438 Check in_list(
"In_Iterator(p), if not directed");
439 Check index(
"In_Arcs_Index::Iterator");
444 for (
unsigned long hidden = 0; hidden < (1UL << s.
num_arcs()); ++hidden)
447 for (
int x = 0; x < s.
n; ++x)
450 const std::string at =
"at " + std::to_string(x) +
" hiding "
451 + std::to_string(hidden) +
": ";
453 if (
auto e = iterator_error<GT, Node_Arc_Iterator>(s, b, x, -1, hidden);
455 node_arc.
fail(s, at + e);
457 if (
auto e = iterator_error<GT, Out_Iterator>(s, b, x, 0, hidden); not e.empty())
461 if (
auto e = walk_error(s, b, x, 1, hidden, in_it); not e.empty())
463 if constexpr (not DigraphType<GT>)
466 if (
auto e = iterator_error<GT, In_Iterator>(s, b, x, 1, hidden); not e.empty())
467 in_list.
fail(s, at + e);
470 if (
auto e = walk_error(s, b, x, 1, hidden, in_arcs_index.
get_it(p)); not e.empty())
471 index.
fail(s, at + e);
485 using GT = TypeParam;
491 Check lists(
"the counts, the iterators and the lists of the nodes");
492 Check in(
"the in_ methods and the in_ functions that take the graph");
493 Check index(
"In_Arcs_Index");
494 Check refused(
"In_Iterator(g, p) and GT::In_Iterator(g, p) throw domain_error");
496 if constexpr (not DigraphType<GT>)
501 std::vector<typename GT::Node *> node;
502 for (
int i = 0; i < s.
n; ++i)
504 for (
size_t i = 0; i < s.
arcs.size(); ++i)
506 const Alive alive(s);
509 if (
auto e = incidence_error(g, s, alive); not e.empty())
513 for (
int x = 0; x < s.
n; ++x)
515 auto * p = node[size_t(x)];
516 const std::string at =
"at " + std::to_string(x) +
": ";
517 const auto want = model_end(s, alive, x, 1);
520 std::multiset<int>
r;
527 size_t traversed = 0;
529 if (numbers(g.
in_arcs(p)) != want or numbers(
in_arcs(g, p)) != want
532 or traversed != want.size())
533 in.
fail(s, at +
"the arcs into it are not " + text(want));
536 const auto got = forward(in_arcs_index.
get_it(p));
537 if (std::multiset<int>(got.begin(), got.end()) != want
538 or in_arcs_index.
in_degree(p) != want.size())
539 index.
fail(s, at +
"gives " + text(got) +
", not " + text(want));
542 bool by_free =
false, by_member =
false;
544 catch (
const std::domain_error &) { by_free =
true; }
546 catch (
const std::domain_error &) { by_member =
true; }
547 if (not by_free or not by_member)
548 refused.
fail(s, at +
"an In_Iterator(g, p) walks the list");
560 using GT = TypeParam;
568 for (
size_t i = 0; i < s.
arcs.size(); ++i)
574 alive.arcs[i] =
false;
575 if (
auto e = incidence_error(b.
g, s, alive); not e.empty())
576 arcs.fail(s,
"without the arc " + std::to_string(i) +
": " + e);
579 for (
int x = 0; x < s.
n; ++x)
585 alive.remove_node(s, x);
586 if (
auto e = incidence_error(b.
g, s, alive); not e.empty())
587 nodes.fail(s,
"without the node " + std::to_string(x) +
": " + e);
594 for (
int x = 0; x < s.
n; ++x)
597 alive.remove_node(s, x);
598 if (
auto e = incidence_error(b.
g, s, alive); not e.empty())
600 all.fail(s,
"after the node " + std::to_string(x) +
": " + e);
613 using GT = TypeParam;
617 Check move(
"the move constructor and assignment");
619 Check mapped(
"copy_graph() with the cookies");
633 const Alive alive(s);
635 const Alive nothing(
none);
640 if (
auto e = incidence_error(c, s, alive); not e.empty())
641 copy.fail(s,
"the copy: " + e);
642 else if (
auto e2 = incidence_error(b.
g, s, alive); not e2.empty())
643 copy.fail(s,
"the original: " + e2);
650 if (
auto e = incidence_error(c, s, alive); not e.empty())
651 assign.fail(s,
"the copy: " + e);
652 else if (
auto e2 = incidence_error(b.
g, s, alive); not e2.empty())
653 assign.fail(s,
"the original: " + e2);
659 GT moved(std::move(c));
660 GT assigned = other();
661 assigned = std::move(moved);
662 if (
auto e = incidence_error(assigned, s, alive); not e.empty())
663 move.
fail(s,
"the result: " + e);
670 move.
fail(s,
"a graph moved from does not take nodes");
678 if (
auto e = incidence_error(d, s, alive); not e.empty())
679 swap.fail(s,
"the swapped graph: " + e);
680 else if (
auto e2 = incidence_error(c,
none, nothing); not e2.empty())
681 swap.fail(s,
"the empty one: " + e2);
688 bool ok = incidence_error(c, s, alive).empty();
692 auto * q = mapped_node<GT>(p);
693 ok = q !=
nullptr and num(q) ==
num(p)
and mapped_node<GT>(q) == p;
698 auto * ca = mapped_arc<GT>(a);
699 ok = ca !=
nullptr and num(ca) ==
num(a)
and mapped_arc<GT>(ca) == a;
702 mapped.
fail(s,
"a wrong copy or map");
720 std::vector<int>
arcs;
721 std::vector<int>
nodes;
726 void for_each_walk(
const Spec & s,
size_t len,
bool directed,
F && f)
728 std::vector<Spec_Walk> todo;
729 for (
int x = 0; x < s.
n; ++x)
730 todo.push_back({x, {}, {x}});
731 while (not todo.empty())
733 Spec_Walk
w = todo.back();
735 f(
static_cast<const Spec_Walk &
>(
w));
736 if (
w.arcs.size() == len)
738 const int at =
w.nodes.back();
739 for (
size_t i = 0; i < s.
arcs.size(); ++i)
740 for (
int e = 0; e < (directed ? 1 : 2); ++e)
742 const auto & a = s.
arcs[i];
743 if (a[
size_t(e)] != at or (e == 1
and a[0] == a[1]))
746 next.arcs.push_back(
int(i));
747 next.nodes.push_back(a[
size_t(1 - e)]);
748 todo.push_back(std::move(
next));
755 typename GT::Arc * arc_of(
const GT & g,
int i)
764 std::vector<int> path_nodes(
const Path<GT> & p)
768 r.push_back(
num(it.get_current_node_ne()));
773 std::vector<int> path_arcs(
const Path<GT> & p)
777 r.push_back(
num(it.get_current_arc_ne()));
784 std::string path_error(
const Spec & s,
const Path<GT> & p,
const Spec_Walk &
w,
785 bool any_arc,
bool directed)
787 const auto nodes = path_nodes(p);
788 const auto arcs = path_arcs(p);
790 return "the nodes are " + text(
nodes) +
", not " + text(
w.nodes);
791 if (
arcs.size() !=
w.arcs.size() or p.
size() !=
w.nodes.size())
792 return "the path has " + std::to_string(
arcs.size()) +
" arcs";
793 for (
size_t i = 0; i <
arcs.size(); ++i)
795 if (not any_arc
and arcs[i] !=
w.arcs[i])
796 return "the arcs are " + text(
arcs) +
", not " + text(
w.arcs);
797 const auto & a = s.
arcs[size_t(
arcs[i])];
798 const bool along = a[0] ==
w.nodes[i]
and a[1] ==
w.nodes[i + 1];
799 const bool against = a[1] ==
w.nodes[i]
and a[0] ==
w.nodes[i + 1];
800 if (not along
and (directed or not against))
801 return "the arc " + std::to_string(
arcs[i]) +
" does not join "
802 + std::to_string(
w.nodes[i]) +
" and " + std::to_string(
w.nodes[i + 1]);
805 return "wrong first or last node";
808 return "wrong first or last arc";
809 if (p.
is_cycle() != (
w.nodes.front() ==
w.nodes.back()))
810 return "is_cycle() is wrong";
814 std::vector<int> listed_nodes, listed_arcs;
815 const auto node_list = p.
nodes();
816 const auto arc_list = p.
arcs();
821 if (listed_nodes !=
nodes or listed_arcs !=
arcs)
822 return "nodes() or arcs() differ from the iterator";
824 if (not p.contains_node(
node_of(g, x)))
827 if (not p.contains_arc(arc_of(g, i)))
835 using GT = TypeParam;
838 Check by_arcs(
"Path::append(Arc *)");
839 Check by_nodes(
"Path::append(Node *)");
840 Check ins_arcs(
"Path::insert(Arc *)");
841 Check ins_nodes(
"Path::insert(Node *)");
842 Check dir_arcs(
"Path::append_directed(Arc *) and insert_directed(Arc *)");
843 Check dir_nodes(
"Path::append_directed(Node *) and insert_directed(Node *)");
844 Check removals(
"Path::remove_last_node() and remove_first_node()");
845 Check copies(
"the copies, moves and swaps of a path");
847 Check check_directed(
"Path::check_directed()");
852 auto node = [&] (
int x) ->
Node * {
return b.
nodes[size_t(x)]; };
855 for_each_walk(s, 3, digraph, [&] (
const Spec_Walk &
w)
861 if (
auto e = path_error(s, p,
w,
false, digraph); not e.empty())
866 for (
int x :
w.nodes)
868 if (
auto e = path_error(s, q,
w,
true, digraph); not e.empty())
873 for (
size_t i =
w.arcs.size(); i-- > 0; )
874 r.insert(b.
arcs[
size_t(
w.arcs[i])]);
875 if (
auto e = path_error(s,
r,
w,
false, digraph); not e.empty())
880 for (
size_t i =
w.nodes.size(); i-- > 0; )
882 if (
auto e = path_error(s, t,
w,
true, digraph); not e.empty())
883 ins_nodes.
fail(s, e);
887 check.fail(s,
"says that the path " + text(
w.nodes) +
" is not consistent");
894 while (ok
and not rest.nodes.empty())
896 const bool last = rest.nodes.size() % 2 == 0;
898 ok = x == (last ? rest.nodes.back() : rest.nodes.front());
901 rest.nodes.pop_back();
902 if (not rest.arcs.empty())
903 rest.arcs.pop_back();
907 rest.nodes.erase(rest.nodes.begin());
908 if (not rest.arcs.empty())
909 rest.arcs.erase(rest.arcs.begin());
912 : path_error(s, c, rest,
false, digraph).empty());
915 removals.
fail(s,
"taking out the nodes of " + text(
w.nodes));
925 if (not path_error(s, moved,
w,
false, digraph).empty()
926 or not path_error(s, e,
w,
false, digraph).empty() or not d.
is_empty())
927 copies.
fail(s,
"of " + text(
w.nodes));
931 check_directed.
run();
933 for (
size_t i = 0; i <
w.arcs.size(); ++i)
934 along = along
and s.
arcs[
size_t(
w.arcs[i])][0] ==
w.nodes[i]
935 and s.
arcs[size_t(
w.arcs[i])][1] ==
w.nodes[i + 1];
937 check_directed.
fail(s,
"says that the path " + text(
w.nodes)
938 + (along ?
" is not" :
" is") +
" directed");
942 for_each_walk(s, 3,
true, [&] (
const Spec_Walk &
w)
949 for (
size_t i =
w.arcs.size(); i-- > 0; )
950 r.insert_directed(b.
arcs[
size_t(
w.arcs[i])]);
951 if (
auto e = path_error(s, p,
w,
false,
true); not e.empty())
952 dir_arcs.
fail(s,
"appending: " + e);
953 else if (
auto e2 = path_error(s,
r,
w,
false,
true); not e2.empty())
954 dir_arcs.
fail(s,
"inserting: " + e2);
958 for (
int x :
w.nodes)
959 q.append_directed(node(x));
960 for (
size_t i =
w.nodes.size(); i-- > 0; )
962 if (
auto e = path_error(s, q,
w,
true,
true); not e.empty())
963 dir_nodes.
fail(s,
"appending: " + e);
964 else if (
auto e2 = path_error(s, t,
w,
true,
true); not e2.empty())
965 dir_nodes.
fail(s,
"inserting: " + e2);
983 using GT = TypeParam;
985 Check arc(
"Path::append(Arc *) with an arc away from the last node");
986 Check node(
"Path::append(Node *) toward a node without an arc");
987 Check inserted(
"Path::insert(Node *) from a node without an arc");
988 Check inserted_directed(
"Path::insert_directed(Node *) from a node without an arc to the first");
989 Check directed(
"Path::append_directed(Arc *) with an arc that does not leave the last node");
994 for (
int x = 0; x < s.
n; ++x)
996 const std::string at =
"from " + std::to_string(x) +
": ";
997 for (
size_t i = 0; i < s.
arcs.size(); ++i)
999 const auto & a = s.
arcs[i];
1001 if (a[0] != x
and a[1] != x)
1007 arc.
fail(s, at +
"takes the arc " + std::to_string(i));
1009 catch (
const std::invalid_argument &) {}
1018 directed.
fail(s, at +
"takes the arc " + std::to_string(i));
1020 catch (
const std::invalid_argument &) {}
1027 for (
int y = 0;
y < s.
n; ++
y)
1029 bool to_y =
false, from_y =
false;
1030 for (
const auto & a : s.
arcs)
1032 const bool x_y = a[0] == x
and a[1] ==
y, y_x = a[0] ==
y and a[1] == x;
1033 to_y = to_y or x_y or (not digraph
and y_x);
1034 from_y = from_y or y_x or (not digraph
and x_y);
1044 node.
fail(s, at +
"goes to " + std::to_string(
y));
1046 catch (
const std::invalid_argument &) {}
1056 inserted.
fail(s, at +
"comes from " + std::to_string(
y));
1058 catch (
const std::invalid_argument &)
1061 inserted.
fail(s, at +
"changes the path");
1063 catch (
const std::exception & e)
1065 inserted.
fail(s, at +
"throws " + std::string(
typeid(e).name()));
1072 for (
int y = 0;
y < s.
n; ++
y)
1074 bool from_y =
false;
1075 for (
const auto & a : s.
arcs)
1076 from_y = from_y or (a[0] ==
y and a[1] == x);
1080 inserted_directed.
run();
1085 inserted_directed.
fail(s, at +
"comes from " + std::to_string(
y));
1087 catch (
const std::invalid_argument &)
1090 inserted_directed.
fail(s, at +
"changes the path");
1092 catch (
const std::exception & e)
1094 inserted_directed.
fail(s, at +
"throws " + std::string(
typeid(e).name()));
1103 inserted_directed.
expect();
1109 using GT = TypeParam;
1111 Check disconnect(
"disconnect_arc()");
1112 Check connect(
"connect_arc() after disconnect_arc()");
1119 for (
size_t i = 0; i < s.
arcs.size(); ++i)
1122 auto * a = b.
arcs[i];
1126 alive.arcs[i] =
false;
1127 if (
auto e = incidence_error(b.
g, s, alive); not e.empty())
1128 disconnect.
fail(s,
"without the arc " + std::to_string(i) +
": " + e);
1132 if (
auto e = incidence_error(b.
g, s, Alive(s)); not e.empty())
1133 connect.
fail(s,
"with the arc " + std::to_string(i) +
" back: " + e);
1143 using GT = TypeParam;
1145 Check clear(
"clear_graph()");
1153 if (
auto e = incidence_error(b.
g,
none, Alive(
none)); not e.empty())
1154 clear.
fail(s,
"after clear_graph(): " + e);
1159 if (
auto e = incidence_error(b.
g, s, Alive(s)); not e.empty())
1160 clear.
fail(s,
"a cleared graph does not take a graph: " + e);
1169 using GT = TypeParam;
1175 auto arc_key = [] (
int i) {
return (7 - i) % 3; };
1176 auto node_key = [] (
int x) {
return (5 - x) % 2; };
1181 if constexpr (
requires { b.
g.
sort_arcs([] (
auto *,
auto *) {
return false; }); })
1185 {
return arc_key(
num(x)) < arc_key(
num(
y)); });
1186 std::vector<int> order;
1189 if (not std::is_sorted(order.begin(), order.end()))
1190 arcs.fail(s,
"the arcs are not sorted");
1191 else if (
auto e = incidence_error(b.
g, s, Alive(s)); not e.empty())
1196 {
return node_key(
num(x)) < node_key(
num(
y)); });
1197 std::vector<int> node_order;
1199 node_order.push_back(node_key(
num(it.
get_curr())));
1200 if (not std::is_sorted(node_order.begin(), node_order.end()))
1201 nodes.fail(s,
"the nodes are not sorted");
1202 else if (
auto e = incidence_error(b.
g, s, Alive(s)); not e.empty())
1213 using GT = TypeParam;
1215 Check single(
"Test_Single_Graph");
1223 std::set<std::pair<int, int>> seen;
1225 for (
const auto & a : s.
arcs)
1227 const auto key = digraph ? std::pair(a[0], a[1])
1228 : std::pair(std::min(a[0], a[1]), std::max(a[0], a[1]));
1229 simple = simple
and a[0] != a[1]
and seen.insert(key).second;
1232 single.
fail(s, simple ?
"says that a simple graph is not" :
"says that it is simple");
WeightedDigraph::Node Node
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
size_t size_t int32_t * out
T & get_curr() const
Return the current item.
T & get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Doubly-linked list (defined in tpl_dynList.H).
size_t size() const noexcept
Return the number of items of the list, in constant time.
void reset_last()
Resets the iterator to the last filtered element.
void next()
Advances the iterator to the next filtered element.
void prev()
Moves the iterator backward to the previous filtered element.
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
void reset_first()
Resets the iterator to the first filtered element.
bool has_curr() const noexcept
Index of the arcs that go into each node of a graph.
size_t in_degree(const Node *p) const
Return the number of arcs into p that the filter showed.
Iterator get_it(const Node *p) const
Return an iterator on the arcs into p that the filter showed.
Filtered iterator for incoming arcs of a node.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
void swap(List_Graph &g) noexcept
Swap in constant time this with g
virtual Arc * connect_arc(Arc *arc) noexcept
Connect a previously disconnected arc to the graph.
virtual void remove_arc(Arc *arc) noexcept
Remove an arc from the graph and free it.
virtual void remove_node(Node *node)
Remove a node from the graph and free its memory.
Graph_Node< Node_Info > Node
The graph type.
virtual void disconnect_arc(Arc *arc) noexcept
Disconnect an arc from graph.
Graph_Arc< Arc_Info > Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Filtered iterator for outcoming arcs of a node.
Iterator on nodes and arcs of a path.
bool is_cycle() const
Return true if this is a cycle; throws if path is empty.
void insert(Arc *arc)
Insert an arc as the first of a path.
DynList< Arc * > arcs() const
Return a list with the arcs of a path (order, according to the path)
size_t size() const noexcept
Return the path length in nodes.
bool check_directed() const
Return true if the directed path is consistent: each arc goes from its node to the next one,...
void insert_directed(Node *p)
Insert a node at the beginning of a directed path.
Node * get_first_node() const
Return the first node of path; throws overflow_error if path is empty.
bool is_empty() const noexcept
Return true if the path is empty.
bool check() const
Return true if the path is consistent: each arc joins its node with the next one, either way,...
Arc * get_last_arc() const
Return the last arc of a path; throws overflow_error if the path is empty.
void swap(Path &path) noexcept
Fast swap between two paths (constant time)
Node * remove_first_node()
Remove the first node of a path.
Arc * get_first_arc() const
Return the first arc of path; throws overflow_error if path is empty.
void append(Arc *arc)
Append an arc to the path.
void append_directed(Node *p)
Append a node to a directed path.
DynList< Node * > nodes() const
Return a list with the nodes of path (order according to the path)
Node * get_last_node() const
Return the last node of path; throws overflow_error if path is empty.
Node * remove_last_node()
Remove the last node of path.
const GT & get_graph() const noexcept
Get a constant reference to the graph.
Determines whether a graph or digraph is simple.
void sort_arcs(Compare &cmp) noexcept(nothrow_cmp_v< Compare, Arc >)
Sort all the arcs of the graph according to a specific criteria.
void sort_nodes(Compare &cmp) noexcept(nothrow_cmp_v< Compare, Node >)
Sort all the nodes of the graph according to a specific criteria.
void for_each_out_arc(Node *p, Op &op) const
Perform op on each outcoming arc of node p
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
void for_each_in_arc(Node *p, Op &op) const
Perform op on each incoming arc of node p; on a digraph, among the arcs of the graph,...
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
DynList< Node * > in_nodes(Node *p) const
Return a list with the incoming nodes to p
DynList< Arc * > out_arcs(Node *p) const
Return a list with the outcoming arcs to p`.
bool is_digraph() const noexcept
Return true if the graph this is directed.
void set_digraph(bool val)
Temporal indication for preventing to other algorithms that an graph must be treated as a directed gr...
bool all_in_arcs(Node *p, Op &op) const
Return true if op is true for all the incoming arcs to node p
auto in_pairs(Node *p) const
Return a list of pair incoming arcs and nodes.
DynList< Arc * > in_arcs(Node *p) const
Return a list with the incoming arcs to p
Node * get_connected_node(Arc *arc, Node *node) const noexcept
Return the adjacent node to node through arc.
bool all_out_arcs(Node *p, Op &op) const
Return true if op is true for all the outcoming arcs to node p
size_t out_degree(Node *p) const noexcept
Compute the output degree of a node.
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
Arc * search_arc(Op &op) const
Linear search of an arc.
Arc * search_directed_arc(Node *src, Node *tgt) const noexcept
Search a directed arc linking two nodes.
size_t in_degree(Node *p) const noexcept
Compute the input degree of a node.
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
DynList< Node * > out_nodes(Node *p) const
Return a list with the outcoming nodes to p
auto out_pairs(Node *p) const
Return a list of pair outcoming arcs and nodes.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
The failures of one property over a domain.
void expect() const
Expects what the mark says, and prints the first failures.
void fail(const Spec &s, const std::string &what)
Counts a failure on spec, with what went wrong.
void run() noexcept
Counts a run of the property.
TYPED_TEST_SUITE(ExhaustiveStructure, All_Kinds)
TYPED_TEST(ExhaustiveStructure, IncidenceMatchesTheModel)
The kinds of arc filter and of distance that the graph algorithms must accept.
Every small multigraph, on every kind of graph, for the tests.
Answers computed from a Spec of graph_harness.H, without Aleph.
DynArray< Graph::Node * > nodes
DynArray< Graph::Arc * > arcs
DynList< typename GT::Node * > in_nodes(typename GT::Node *p, SA sa=SA())
Return the nodes connected to the filtered incoming arcs to p.
bool traverse_in_arcs(typename GT::Node *p, Op op=Op())
Conditioned traversal of incoming arcs of a node.
size_t in_degree(typename GT::Node *p, SA sa=SA())
Compute the filtered in degree of node p.
void clear_graph(GT &g)
Clean a graph: all its nodes and arcs are removed and freed.
DynList< typename GT::Arc * > in_arcs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming arcs of p.
void for_each_in_arc(typename GT::Node *p, Op op=Op())
Traverse the incoming arcs of a node and executes an operation.
void copy_graph(GT >gt, const GT &gsrc, bool cookie_map=false)
Explicit copy of graph.
DynList< ArcPair< GT > > in_pairs(typename GT::Node *p, SA sa=SA())
Return the filtered incoming pairs of (arc,node) related to node p
Main namespace for Aleph-w library functions.
T & swap(T &t1, T &t2)
Generic swap using object's swap method.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
bool all(Container &container, Operation &operation)
Return true if all elements satisfy a predicate.
and
Check uniqueness with explicit hash + equality functors.
Itor1 search(Itor1 beg, const Itor1 &end, Itor2 searchBeg, const Itor2 &searchEnd, BinaryPredicate op=BinaryPredicate())
Search for a subrange within a range.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
bool all_in_arc(typename GT::Node *p, Op op=Op())
Test if the incoming arcs meet a condition.
void next()
Advance all underlying iterators (bounds-checked).
bool exists_in_arc(typename GT::Node *p, Op op=Op())
Test if it exists an incoming arc satisfying an operation.
bool none(const Container &container, Operation &operation)
Return true if no element satisfies operation.
constexpr bool shown(unsigned long hidden, int i) noexcept
Whether the arc number i is shown by the mask hidden.
GT::Node * node_of(const GT &g, int i)
The node of a graph whose number is i.
size_t for_each_spec(const Domain &d, bool directed, F &&f)
Calls f(spec) with every spec of d, smallest first, and returns how many there were.
int num(Node *p)
The number of a node of a built graph.
Domain domain(int max_nodes, int max_arcs)
The domain of max_nodes nodes and max_arcs arcs, of one more of each in heavy mode,...
::testing::Types< Aleph::List_Graph< Aleph::Graph_Node< int >, Aleph::Graph_Arc< int > >, Aleph::List_SGraph< Aleph::Graph_Snode< int >, Aleph::Graph_Sarc< int > >, Aleph::Array_Graph< Aleph::Graph_Anode< int >, Aleph::Graph_Aarc< int > >, Aleph::List_Digraph< Aleph::Graph_Node< int >, Aleph::Graph_Arc< int > >, Aleph::List_SDigraph< Aleph::Graph_Snode< int >, Aleph::Graph_Sarc< int > >, Aleph::Array_Digraph< Aleph::Graph_Anode< int >, Aleph::Graph_Aarc< int > > > All_Kinds
The six kinds, with int infos.
Alias for Digraph_Iterator
Hides the arcs of a mask; copyable, assignable, noexcept.
A graph made from a spec, with its nodes and arcs by number.
std::vector< typename GT::Node * > nodes
std::vector< typename GT::Arc * > arcs
A small multigraph: its nodes are 0 .
size_t num_arcs() const noexcept
std::vector< std::array< int, 2 > > arcs
FooMap m(5, fst_unit_pair_hash, snd_unit_pair_hash)
void assign(BinTree< int >::Node *node, int, int)
Generic graph and digraph implementations.