43#include <gtest/gtest.h>
56using namespace testing;
102 n1 =
g.insert_node(1);
103 n2 =
g.insert_node(2);
104 n3 =
g.insert_node(3);
105 g.insert_arc(
n1,
n2, 10);
106 g.insert_arc(
n2,
n3, 20);
107 g.insert_arc(
n1,
n3, 30);
152 string result =
out.str();
155 EXPECT_NE(result.find(
"graph {"), string::npos);
157 EXPECT_EQ(result.find(
"digraph {"), string::npos);
164 string result =
out.str();
167 EXPECT_NE(result.find(
"digraph {"), string::npos);
174 string result =
out.str();
177 EXPECT_NE(result.find(
"label = \"1\""), string::npos);
178 EXPECT_NE(result.find(
"label = \"2\""), string::npos);
179 EXPECT_NE(result.find(
"label = \"3\""), string::npos);
186 string result =
out.str();
189 EXPECT_NE(result.find(
"--"), string::npos);
196 string result =
out.str();
199 EXPECT_NE(result.find(
"->"), string::npos);
206 string result =
out.str();
208 EXPECT_NE(result.find(
"rankdir = TB"), string::npos);
215 string result =
out.str();
227 string result =
out.str();
229 EXPECT_NE(result.find(
"label"), string::npos);
230 EXPECT_NE(result.find(
"1"), string::npos);
235 auto arc = g.get_first_arc();
238 string result =
out.str();
240 EXPECT_NE(result.find(
"label"), string::npos);
271 auto arc = g.get_first_arc();
279 auto arc = g.get_first_arc();
321 for (
auto* child =
firstChild; child !=
nullptr;
322 child = child->get_right_sibling())
338 if (node ==
nullptr)
return;
339 values.insert(node->get_key());
340 for (
auto* child = node->get_left_child(); child !=
nullptr;
341 child = child->get_right_sibling())
360 tree.insert_arc(grandchild,
root, 0);
377 string result =
out.str();
392 string result =
out.str();
395 EXPECT_NE(result.find(
"Node "), string::npos);
412 const string result =
out.str();
414 EXPECT_NE(result.find(
"label=\"say \\\"hi\\\"\\npath\\\\leaf\""), string::npos);
415 EXPECT_EQ(result.find(
"label=\"say \"hi\""), string::npos);
433 string result =
out.str();
437 EXPECT_NE(result.find(
"Root"), string::npos);
438 EXPECT_NE(result.find(
"\"1\""), string::npos);
453 string result =
out.str();
456 EXPECT_NE(result.find(
"graph {"), string::npos);
457 EXPECT_NE(result.find(
"}"), string::npos);
467 string result =
out.str();
469 EXPECT_NE(result.find(
"42"), string::npos);
479 tn->get_key() =
gn->get_info();
503 string result =
writer(&node);
518 out <<
"label=\"" << n->get_info() <<
"\"";
522 void operator()(
const Graph&,
Arc* a, ostream&
out) {
523 out <<
"label=\"" << a->get_info() <<
"\"";
530 string result =
out.str();
533 EXPECT_NE(result.find(
"digraph {"), string::npos);
534 EXPECT_NE(result.find(
"->"), string::npos);
544 string operator()(
Arc* a)
const {
return to_string(a->get_info()); }
549 string result =
out.str();
551 EXPECT_NE(result.find(
"graph {"), string::npos);
552 EXPECT_NE(result.find(
"rankdir = TB"), string::npos);
563 string result =
out.str();
564 EXPECT_NE(result.find(
"rankdir = " + dir), string::npos)
565 <<
"Failed for rankdir: " << dir;
580 string result =
out.str();
582 EXPECT_NE(result.find(
"Alpha"), string::npos);
583 EXPECT_NE(result.find(
"Beta"), string::npos);
591 auto* a = g.insert_node(1);
592 auto* b = g.insert_node(2);
593 g.insert_arc(a, b, 3.14159);
597 string result =
out.str();
599 EXPECT_NE(result.find(
"3.14"), string::npos);
609 auto* n1 = g.insert_node(1);
610 auto* n2 = g.insert_node(2);
611 auto* n3 = g.insert_node(3);
612 g.insert_arc(n1, n2, 0);
613 g.insert_arc(n2, n3, 0);
616 void operator()(
const DAG&, DAG::Node* n, ostream&
out) {
621 void operator()(
const DAG&, DAG::Arc*, ostream&
out) {
630 string result =
out.str();
635 EXPECT_NE(result.find(
"subgraph"), string::npos);
636 EXPECT_NE(result.find(
"rank"), string::npos);
652 tree2->get_key() = 200;
653 tree3->get_key() = 300;
661 string result =
out.str();
664 EXPECT_NE(result.find(
"100"), string::npos);
665 EXPECT_NE(result.find(
"200"), string::npos);
666 EXPECT_NE(result.find(
"300"), string::npos);
699 string result =
out.str();
701 EXPECT_NE(result.find(
"0xff"), string::npos);
709 const int DEPTH = 10;
714 for (
int i = 1; i <
DEPTH; ++i) {
723 string result =
out.str();
726 for (
int i = 0; i <
DEPTH; ++i) {
728 <<
"Missing node " << i;
733 EXPECT_NE(result.find(
"Node 0.0.0.0"), string::npos);
741 const int WIDTH = 10;
745 for (
int i = 1; i <=
WIDTH; ++i) {
748 root->insert_rightmost_child(child);
753 string result =
out.str();
756 for (
int i = 1; i <=
WIDTH; ++i) {
758 <<
"Missing child " << i;
838template <
typename GT>
855 out <<
"label=\"" << n->get_info() <<
"\"";
859 void operator()(
const Graph&,
Arc* a, ostream&
out) {
860 out <<
"label=\"" << a->get_info() <<
"\"";
867 string result =
out.str();
870 EXPECT_NE(result.find(
"20"), string::npos);
871 EXPECT_NE(result.find(
"30"), string::npos);
873 EXPECT_EQ(result.find(
"\"10\""), string::npos);
885 const int NUM_NODES = 100;
889 for (
int i = 0; i < NUM_NODES; ++i) {
890 nodes.push_back(g.insert_node(i));
894 for (
int i = 0; i < NUM_NODES - 1; ++i) {
900 string result =
out.str();
903 EXPECT_NE(result.find(
"graph {"), string::npos);
904 EXPECT_NE(result.find(
"}"), string::npos);
907 EXPECT_NE(result.find(
"\"0\""), string::npos);
908 EXPECT_NE(result.find(
"\"99\""), string::npos);
916 const int NUM_NODES = 100;
920 for (
int i = 0; i < NUM_NODES; ++i) {
921 nodes.push_back(tree.insert_node(i));
925 for (
int i = 1; i < NUM_NODES; ++i) {
926 int parent = (i - 1) / 2;
945 if (node ==
nullptr)
return;
947 for (
auto* child = node->get_left_child(); child !=
nullptr;
948 child = child->get_right_sibling())
WeightedDigraph::Node Node
Generic directed graph (digraph) wrapper template.
typename BaseGraph::Arc Arc
typename BaseGraph::Node Node
Functor class to convert a tree graph to Tree_Node structure.
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)
Graph class implemented with singly-linked adjacency lists.
Arc * insert_arc(Node *src, Node *tgt, void *a)
virtual Node * insert_node(Node *p)
Insertion of a node whose memory has already been allocated.
Tree_Node * get_left_child() const noexcept
Returns the leftmost child of this.
void insert_leftmost_child(Tree_Node *p) noexcept
Inserts p as the leftmost child of this.
T & get_key() noexcept
Returns a modifiable reference to the node contents.
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
Simple digraph for testing.
Simple graph for testing.
Tree graph for graph_to_tree conversion testing.
Graph visualization and output generation utilities.
Spanning tree visualization with highlighted tree/non-tree edges.
Tree visualization and output generation.
__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)
Convert spanning tree graphs to Tree_Node structures.
TEST_F(SimpleGraphTest, GenerateGraphvizContainsGraphKeyword)
DynArray< Graph::Node * > nodes
size_t rank_graphviz(const GT &g, std::ostream &out, Node_Attr node_attr=Node_Attr(), Arc_Attr arc_attr=Arc_Attr(), const std::string &rankdir="LR")
Generate Graphviz DOT output with topological ranking.
#define ARC_COOKIE(p)
Return the arc cookie
#define NODE_COOKIE(p)
Return the node cookie
void generate_forest(Node *root, std::ostream &out)
Generate a forest specification for the ntreepic drawing tool.
void generate_tree(Node *root, std::ostream &out, const int &tree_number=0)
Generate a tree specification for the ntreepic drawing tool.
void destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
Main namespace for Aleph-w library functions.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Default filter for filtered iterators on arcs.
Default filter for the graph nodes.
Arc of graph implemented with double-linked adjacency lists.
Functor class for generating Graphviz DOT specifications.
Converter from Graph::Node to int for Tree_Node.
List_Graph< Graph_Node< int >, Graph_Arc< int > >::Node GraphNode
void operator()(GraphNode *gnode, Tree_Node< int > *tnode)
Shading functor for spanning tree arcs.
Shading functor for spanning tree nodes.
bool operator()(typename GT::Arc *a) const
Functor to convert tree node to string for output.
string operator()(Tree_Node< int > *p)
Generic graph and digraph implementations.
Utility algorithms and operations for graphs.
General tree (n-ary tree) node.