38#include <gtest/gtest.h>
79 return g.insert_node(val);
84 return g.insert_arc(src, tgt, 1);
104 EXPECT_TRUE(
test(g));
124 EXPECT_TRUE(
test(g));
144 EXPECT_TRUE(
test(g));
165 EXPECT_FALSE(
test(g));
188 EXPECT_EQ(g.get_num_arcs(n1), 3) <<
"n1 should have degree 3";
189 EXPECT_EQ(g.get_num_arcs(n2), 3) <<
"n2 should have degree 3";
190 EXPECT_EQ(g.get_num_arcs(n3), 3) <<
"n3 should have degree 3";
191 EXPECT_EQ(g.get_num_arcs(n4), 3) <<
"n4 should have degree 3";
195 EXPECT_FALSE(
test(g));
210 EXPECT_FALSE(
test(g));
233 EXPECT_FALSE(
test(g));
256 EXPECT_FALSE(
test(g));
275 EXPECT_FALSE(
test(g));
293 EXPECT_TRUE(
test(g));
321 EXPECT_FALSE(
test(g));
331 EXPECT_TRUE(
test(g));
339 EXPECT_TRUE(
test(g));
355 EXPECT_TRUE(
test(g));
370 EXPECT_FALSE(
test(g));
387 EXPECT_TRUE(
test(g));
412 EXPECT_FALSE(
test(g));
414 EXPECT_TRUE(
test.test_degree_only(g));
435 EXPECT_FALSE(
test(g));
462 EXPECT_TRUE(
test(g));
478 EXPECT_TRUE(
test(g));
512 EXPECT_FALSE(
test(g));
514 EXPECT_TRUE(
test.test_degree_only(g));
532 EXPECT_EQ(
test.compute(g), Eulerian_Type::Cycle);
533 EXPECT_TRUE(
test.has_eulerian_path(g));
547 EXPECT_EQ(
test.compute(g), Eulerian_Type::Path);
548 EXPECT_TRUE(
test.has_eulerian_path(g));
549 EXPECT_FALSE(
test(g));
567 EXPECT_EQ(
test.compute(g), Eulerian_Type::None);
568 EXPECT_FALSE(
test.has_eulerian_path(g));
582 EXPECT_EQ(
test.compute(g), Eulerian_Type::Cycle);
595 EXPECT_EQ(
test.compute(g), Eulerian_Type::Path);
596 EXPECT_TRUE(
test.has_eulerian_path(g));
614 auto result = finder(g);
616 EXPECT_EQ(result.type, Eulerian_Type::Cycle);
617 EXPECT_EQ(result.path.size(), 3);
620 std::set<Graph::Arc*> edges_in_path;
621 for (
auto arc : result.path)
622 edges_in_path.insert(arc);
624 EXPECT_EQ(edges_in_path.size(), 3);
625 EXPECT_TRUE(edges_in_path.count(e1) > 0);
626 EXPECT_TRUE(edges_in_path.count(e2) > 0);
627 EXPECT_TRUE(edges_in_path.count(e3) > 0);
640 auto result = finder(g);
642 EXPECT_EQ(result.type, Eulerian_Type::Path);
643 EXPECT_EQ(result.path.size(), 2);
662 auto result = finder(g);
664 EXPECT_EQ(result.type, Eulerian_Type::None);
665 EXPECT_TRUE(result.path.is_empty());
688 auto result = finder(g);
690 EXPECT_EQ(result.type, Eulerian_Type::Cycle);
691 EXPECT_EQ(result.path.size(), 6);
708 EXPECT_EQ(
nodes.size(), 4);
709 EXPECT_EQ(
nodes.get_first(),
nodes.get_last());
726 auto result = finder(g);
728 EXPECT_EQ(result.type, Eulerian_Type::None);
729 EXPECT_TRUE(result.path.is_empty());
743 auto result = finder(g);
745 EXPECT_EQ(result.type, Eulerian_Type::Cycle);
746 EXPECT_EQ(result.path.size(), 3);
759 auto result = finder(g);
761 EXPECT_EQ(result.type, Eulerian_Type::Path);
762 EXPECT_EQ(result.path.size(), 2);
783 auto result = finder(g);
785 EXPECT_EQ(result.type, Eulerian_Type::Cycle);
786 EXPECT_EQ(result.path.size(), 6);
795 ::testing::InitGoogleTest(&argc, argv);
796 return RUN_ALL_TESTS();
Generic directed graph (digraph) wrapper template.
typename BaseGraph::Arc Arc
typename BaseGraph::Node Node
Finds and constructs an Eulerian path or cycle using Hierholzer's algorithm.
DynList< typename GT::Node * > find_node_sequence(GT &g)
Get the node sequence of the Eulerian path/cycle.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Graph_Node< int > Node
The graph type.
Graph_Arc< int > Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Tests whether a graph or digraph is Eulerian.
A non-degenerate triangle defined by three points.
Arc * add_arc(Node *src, Node *tgt)
Arc * add_edge(Node *n1, Node *n2)
Eulerian graph detection and path/cycle finding.
TEST_F(EulerianUndirectedTest, EmptyGraph)
void add_edge(GT &g, const string &src, const string &tgt, int weight=1)
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
Arc of graph implemented with double-linked adjacency lists.
TestDigraph::Arc * add_arc(TestDigraph &g, TestDigraph::Node *src, TestDigraph::Node *tgt, int value=0)
TestDigraph::Node * add_node(TestDigraph &g, int value)
Generic graph and digraph implementations.