50#include <gtest/gtest.h>
103 auto root = dfs(g, tree);
105 ASSERT_NE(
root,
nullptr);
106 EXPECT_EQ(tree.get_num_nodes(), 1);
107 EXPECT_EQ(tree.get_num_arcs(), 0);
112 [[maybe_unused]]
auto n1 = g.insert_node(1);
113 auto n2 = g.insert_node(2);
114 g.insert_arc(n1, n2);
117 auto root = dfs(g, tree);
119 ASSERT_NE(
root,
nullptr);
120 EXPECT_EQ(tree.get_num_nodes(), 2);
121 EXPECT_EQ(tree.get_num_arcs(), 1);
126 [[maybe_unused]]
auto n1 = g.insert_node(1);
127 auto n2 = g.insert_node(2);
128 auto n3 = g.insert_node(3);
129 g.insert_arc(n1, n2);
130 g.insert_arc(n2, n3);
131 g.insert_arc(n3, n1);
134 auto root = dfs(g, tree);
136 ASSERT_NE(
root,
nullptr);
137 EXPECT_EQ(tree.get_num_nodes(), 3);
138 EXPECT_EQ(tree.get_num_arcs(), 2);
143 [[maybe_unused]]
auto n1 = g.insert_node(1);
144 auto n2 = g.insert_node(2);
145 auto n3 = g.insert_node(3);
146 auto n4 = g.insert_node(4);
147 auto n5 = g.insert_node(5);
149 g.insert_arc(n1, n2);
150 g.insert_arc(n2, n3);
151 g.insert_arc(n3, n4);
152 g.insert_arc(n4, n5);
155 auto root = dfs(g, tree);
157 ASSERT_NE(
root,
nullptr);
158 EXPECT_EQ(tree.get_num_nodes(), 5);
159 EXPECT_EQ(tree.get_num_arcs(), 4);
167 for (
int i = 0; i <
N; ++i)
171 for (
int i = 0; i <
N; ++i)
172 for (
int j = i + 1; j <
N; ++j)
176 auto root = dfs(g, tree);
178 ASSERT_NE(
root,
nullptr);
179 EXPECT_EQ(tree.get_num_nodes(),
N);
180 EXPECT_EQ(tree.get_num_arcs(),
N - 1);
185 [[maybe_unused]]
auto n1 = g.insert_node(1);
186 auto n2 = g.insert_node(2);
187 auto n3 = g.insert_node(3);
188 g.insert_arc(n1, n2);
189 g.insert_arc(n2, n3);
192 auto tree_node = dfs(g, n2, tree);
194 ASSERT_NE(tree_node,
nullptr);
195 EXPECT_EQ(tree.get_num_nodes(), 3);
196 EXPECT_EQ(tree.get_num_arcs(), 2);
203 EXPECT_THROW(dfs(g, tree), std::domain_error);
208 [[maybe_unused]]
auto n1 = g.insert_node(1);
212 EXPECT_THROW(dfs(g,
nullptr, tree), std::invalid_argument);
217 [[maybe_unused]]
auto n1 = g.insert_node(10);
218 auto n2 = g.insert_node(20);
219 auto n3 = g.insert_node(30);
220 g.insert_arc(n1, n2);
221 g.insert_arc(n2, n3);
227 auto t1 = mapped_node<Graph>(n1);
228 auto t2 = mapped_node<Graph>(n2);
229 auto t3 = mapped_node<Graph>(n3);
231 EXPECT_NE(t1,
nullptr);
232 EXPECT_NE(t2,
nullptr);
233 EXPECT_NE(t3,
nullptr);
236 EXPECT_EQ(t1->get_info(), 10);
237 EXPECT_EQ(t2->get_info(), 20);
238 EXPECT_EQ(t3->get_info(), 30);
247 [[maybe_unused]]
auto n1 = g.insert_node(1);
250 auto root = bfs(g, tree);
252 ASSERT_NE(
root,
nullptr);
253 EXPECT_EQ(tree.get_num_nodes(), 1);
254 EXPECT_EQ(tree.get_num_arcs(), 0);
259 [[maybe_unused]]
auto n1 = g.insert_node(1);
260 auto n2 = g.insert_node(2);
261 g.insert_arc(n1, n2);
264 auto root = bfs(g, tree);
266 ASSERT_NE(
root,
nullptr);
267 EXPECT_EQ(tree.get_num_nodes(), 2);
268 EXPECT_EQ(tree.get_num_arcs(), 1);
273 [[maybe_unused]]
auto n1 = g.insert_node(1);
274 auto n2 = g.insert_node(2);
275 auto n3 = g.insert_node(3);
276 g.insert_arc(n1, n2);
277 g.insert_arc(n2, n3);
278 g.insert_arc(n3, n1);
281 auto root = bfs(g, tree);
283 ASSERT_NE(
root,
nullptr);
284 EXPECT_EQ(tree.get_num_nodes(), 3);
285 EXPECT_EQ(tree.get_num_arcs(), 2);
293 for (
int i = 0; i <
N; ++i)
296 for (
int i = 0; i <
N; ++i)
297 for (
int j = i + 1; j <
N; ++j)
301 auto root = bfs(g, tree);
303 ASSERT_NE(
root,
nullptr);
304 EXPECT_EQ(tree.get_num_nodes(),
N);
305 EXPECT_EQ(tree.get_num_arcs(),
N - 1);
310 [[maybe_unused]]
auto n1 = g.insert_node(1);
311 auto n2 = g.insert_node(2);
312 auto n3 = g.insert_node(3);
313 g.insert_arc(n1, n2);
314 g.insert_arc(n2, n3);
319 EXPECT_EQ(tree.get_num_nodes(), 3);
320 EXPECT_EQ(tree.get_num_arcs(), 2);
327 EXPECT_THROW(bfs(g, tree), std::domain_error);
332 [[maybe_unused]]
auto n1 = g.insert_node(1);
336 EXPECT_THROW(bfs(g,
nullptr, tree), std::invalid_argument);
341 [[maybe_unused]]
auto n1 = g.insert_node(10);
342 auto n2 = g.insert_node(20);
343 auto n3 = g.insert_node(30);
344 g.insert_arc(n1, n2);
345 g.insert_arc(n2, n3);
350 auto t1 = mapped_node<Graph>(n1);
351 auto t2 = mapped_node<Graph>(n2);
352 auto t3 = mapped_node<Graph>(n3);
354 EXPECT_NE(t1,
nullptr);
355 EXPECT_NE(t2,
nullptr);
356 EXPECT_NE(t3,
nullptr);
358 EXPECT_EQ(t1->get_info(), 10);
359 EXPECT_EQ(t2->get_info(), 20);
360 EXPECT_EQ(t3->get_info(), 30);
372 for (
int i = 0; i <
N; ++i)
376 for (
int i = 0; i <
N - 1; ++i)
380 for (
int i = 0; i <
N - 10; i += 10)
384 auto root = dfs(g, tree);
386 ASSERT_NE(
root,
nullptr);
387 EXPECT_EQ(tree.get_num_nodes(),
N);
388 EXPECT_EQ(tree.get_num_arcs(),
N - 1);
396 for (
int i = 0; i <
N; ++i)
399 for (
int i = 0; i <
N - 1; ++i)
402 for (
int i = 0; i <
N - 10; i += 10)
406 auto root = bfs(g, tree);
408 ASSERT_NE(
root,
nullptr);
409 EXPECT_EQ(tree.get_num_nodes(),
N);
410 EXPECT_EQ(tree.get_num_arcs(),
N - 1);
417template <
typename GraphType>
437template <
typename GraphType>
455 using Graph = TypeParam;
457 Graph & tree = this->tree;
462 auto root = dfs(g, tree);
464 ASSERT_NE(
root,
nullptr);
471 using Graph = TypeParam;
473 Graph & tree = this->tree;
483 auto root = dfs(g, tree);
485 ASSERT_NE(
root,
nullptr);
492 using Graph = TypeParam;
494 Graph & tree = this->tree;
498 EXPECT_THROW(dfs(g, tree), std::domain_error);
503 using Graph = TypeParam;
505 Graph & tree = this->tree;
511 EXPECT_THROW(dfs(g,
nullptr, tree), std::invalid_argument);
516 using Graph = TypeParam;
518 Graph & tree = this->tree;
523 auto root = bfs(g, tree);
525 ASSERT_NE(
root,
nullptr);
532 using Graph = TypeParam;
534 Graph & tree = this->tree;
544 auto root = bfs(g, tree);
546 ASSERT_NE(
root,
nullptr);
553 using Graph = TypeParam;
555 Graph & tree = this->tree;
559 EXPECT_THROW(bfs(g, tree), std::domain_error);
564 using Graph = TypeParam;
566 Graph & tree = this->tree;
572 EXPECT_THROW(bfs(g,
nullptr, tree), std::invalid_argument);
577 using Graph = TypeParam;
579 Graph & tree = this->tree;
593 auto root = dfs(g, tree);
595 ASSERT_NE(
root,
nullptr);
602 using Graph = TypeParam;
604 Graph & tree = this->tree;
618 auto root = bfs(g, tree);
620 ASSERT_NE(
root,
nullptr);
628 ::testing::InitGoogleTest(&argc, argv);
629 return RUN_ALL_TESTS();
Generic directed graph (digraph) wrapper template.
T & append()
Allocate a new entry to the end of array.
Compute a breadth-first spanning tree of a graph.
Compute a depth-first spanning tree of a graph.
Arc for graphs implemented with simple adjacency lists.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Graph class implemented with singly-linked adjacency lists.
Number Theoretic Transform over Z / MOD Z.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
__gmp_expr< T, __gmp_binary_expr< __gmp_expr< T, U >, unsigned long int, __gmp_root_function > > root(const __gmp_expr< T, U > &expr, unsigned long int l)
::testing::Types< ListGraph, SparseGraph, ArrayGraph > UndirectedGraphTypes
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
Arc of graph implemented with double-linked adjacency lists.
Array-based graph implementation.
::testing::Types< ListGraph, ListDigraph, SparseGraph, SparseDigraph, ArrayGraph, ArrayDigraph > GraphTypes
Generic graph and digraph implementations.
Simple graph implementation with adjacency lists.
Spanning tree generation algorithms.
List_Digraph< Graph_Node< int >, Graph_Arc< int > > ListDigraph
TEST_F(DFSSpanningTreeTest, SingleNode)
TYPED_TEST(SpanningTreeAllGraphs, DFSSingleNode)
List_Graph< Graph_Node< int >, Graph_Arc< int > > ListGraph
Array_Graph< Graph_Anode< int >, Graph_Aarc< int > > ArrayGraph
TYPED_TEST_SUITE(SpanningTreeAllGraphs, GraphTypes)
List_SDigraph< Graph_Snode< int >, Graph_Sarc< int > > SparseDigraph
List_SGraph< Graph_Snode< int >, Graph_Sarc< int > > SparseGraph