38#include <gtest/gtest.h>
53 std::map<TestDigraph::Node*, size_t> pos;
55 for (
auto it =
order.
get_it(); it.has_curr(); it.next_ne(), ++idx)
56 pos[it.get_curr()] = idx;
61 auto arc = it.get_curr();
62 auto src = g.get_src_node(arc);
63 auto tgt = g.get_tgt_node(arc);
65 if (pos.find(src) == pos.end() || pos.find(tgt) == pos.end())
68 if (pos[src] >= pos[tgt])
89 auto n = g.insert_node(
"A");
101 auto a = g.insert_node(
"A");
102 auto b = g.insert_node(
"B");
118 auto a = g.insert_node(
"A");
119 auto b = g.insert_node(
"B");
120 auto c = g.insert_node(
"C");
121 auto d = g.insert_node(
"D");
144 auto a = g.insert_node(
"A");
145 auto b = g.insert_node(
"B");
146 auto c = g.insert_node(
"C");
147 auto d = g.insert_node(
"D");
164 auto a = g.insert_node(
"A");
165 auto b = g.insert_node(
"B");
166 auto c = g.insert_node(
"C");
167 auto d = g.insert_node(
"D");
186 auto a = g.insert_node(
"A");
187 auto b = g.insert_node(
"B");
188 auto c = g.insert_node(
"C");
189 auto d = g.insert_node(
"D");
190 auto e = g.insert_node(
"E");
191 auto f = g.insert_node(
"F");
211 auto a = g.insert_node(
"A");
212 auto b = g.insert_node(
"B");
237 auto n = g.insert_node(
"A");
249 auto a = g.insert_node(
"A");
250 auto b = g.insert_node(
"B");
263 auto a = g.insert_node(
"A");
264 auto b = g.insert_node(
"B");
265 auto c = g.insert_node(
"C");
266 auto d = g.insert_node(
"D");
282 auto a = g.insert_node(
"A");
283 auto b = g.insert_node(
"B");
284 auto c = g.insert_node(
"C");
285 auto d = g.insert_node(
"D");
306 auto result =
sorter.ranks(g);
313 auto n = g.insert_node(
"A");
316 auto result =
sorter.ranks(g);
320 EXPECT_EQ(result.get_first().get_first(), n);
330 auto nodes = g.nodes();
335 auto result =
sorter.ranks(g);
339 for (
auto it = result.get_it(); it.has_curr(); it.next_ne())
351 auto a = g.insert_node(
"A");
352 auto b = g.insert_node(
"B");
353 auto c = g.insert_node(
"C");
354 auto d = g.insert_node(
"D");
361 auto result =
sorter.ranks(g);
367 EXPECT_EQ(result.get_first().get_first(), a);
383 auto a = g.insert_node(
"A");
384 auto b = g.insert_node(
"B");
385 auto c = g.insert_node(
"C");
386 auto d = g.insert_node(
"D");
394 auto result =
sorter.ranks(g);
398 auto it = result.get_it();
418 auto a = g.insert_node(
"A");
419 auto b = g.insert_node(
"B");
420 auto c = g.insert_node(
"C");
421 auto d = g.insert_node(
"D");
427 auto result =
sorter.ranks(g);
443 auto a = g.insert_node(
"A");
444 auto b = g.insert_node(
"B");
457 auto a = g.insert_node(
"A");
458 auto b = g.insert_node(
"B");
471 auto a = g.insert_node(
"A");
472 auto b = g.insert_node(
"B");
487 constexpr size_t N = 1000;
491 for (
size_t i = 0; i <
N; ++i)
494 for (
size_t i = 0; i <
N - 1; ++i)
517 constexpr size_t WIDTH = 100;
520 auto source = g.insert_node(
"source");
521 for (
size_t i = 0; i <
WIDTH; ++i)
523 auto sink = g.insert_node(std::to_string(i));
524 g.insert_arc(source, sink);
541 auto a = g.insert_node(
"A");
542 auto b = g.insert_node(
"B");
543 auto c = g.insert_node(
"C");
544 auto d = g.insert_node(
"D");
545 auto e = g.insert_node(
"E");
546 auto f = g.insert_node(
"F");
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
T & get_first() noexcept
return a modifiable reference to the first element.
T & get_last() noexcept
return a modifiable reference to the last element.
Generic directed graph (digraph) wrapper template.
T & append()
Allocate a new entry to the end of array.
Dynamic doubly linked list with O(1) size and bidirectional access.
const size_t & size() const noexcept
Return the number of elements (constant time)
Dynamic singly linked list with functional programming support.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
size_t size() const noexcept
Count the number of elements of the list.
Computes topological ordering using breadth-first search (Kahn's algorithm).
Computes topological ordering using depth-first search.
auto get_it() const
Return a properly initialized iterator positioned at the first item on the container.
DynArray< Graph::Node * > nodes
Array< size_t > ranks(const Array< T > &array)
Computes the rank of each element in an Array.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Filtered iterator on all the arcs of a graph.
Arc of graph implemented with double-linked adjacency lists.
Topological sorting algorithms for directed acyclic graphs (DAGs).
bool is_valid_topological_order(const TestDigraph &g, const List &order)
Generic graph and digraph implementations.