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);
413 string result =
out.str();
417 EXPECT_NE(result.find(
"Root"), string::npos);
418 EXPECT_NE(result.find(
"\"1\""), string::npos);
433 string result =
out.str();
436 EXPECT_NE(result.find(
"graph {"), string::npos);
437 EXPECT_NE(result.find(
"}"), string::npos);
447 string result =
out.str();
449 EXPECT_NE(result.find(
"42"), string::npos);
459 tn->get_key() =
gn->get_info();
483 string result =
writer(&node);
498 out <<
"label=\"" << n->get_info() <<
"\"";
502 void operator()(
const Graph&,
Arc* a, ostream&
out) {
503 out <<
"label=\"" << a->get_info() <<
"\"";
510 string result =
out.str();
513 EXPECT_NE(result.find(
"digraph {"), string::npos);
514 EXPECT_NE(result.find(
"->"), string::npos);
524 string operator()(
Arc* a)
const {
return to_string(a->get_info()); }
529 string result =
out.str();
531 EXPECT_NE(result.find(
"graph {"), string::npos);
532 EXPECT_NE(result.find(
"rankdir = TB"), string::npos);
543 string result =
out.str();
544 EXPECT_NE(result.find(
"rankdir = " + dir), string::npos)
545 <<
"Failed for rankdir: " << dir;
560 string result =
out.str();
562 EXPECT_NE(result.find(
"Alpha"), string::npos);
563 EXPECT_NE(result.find(
"Beta"), string::npos);
571 auto* a = g.insert_node(1);
572 auto* b = g.insert_node(2);
573 g.insert_arc(a, b, 3.14159);
577 string result =
out.str();
579 EXPECT_NE(result.find(
"3.14"), string::npos);
589 auto* n1 = g.insert_node(1);
590 auto* n2 = g.insert_node(2);
591 auto* n3 = g.insert_node(3);
592 g.insert_arc(n1, n2, 0);
593 g.insert_arc(n2, n3, 0);
596 void operator()(
const DAG&, DAG::Node* n, ostream&
out) {
597 out <<
"label=\"" << n->get_info() <<
"\"";
601 void operator()(
const DAG&, DAG::Arc*, ostream&
out) {
610 string result =
out.str();
615 EXPECT_NE(result.find(
"subgraph"), string::npos);
616 EXPECT_NE(result.find(
"rank"), string::npos);
631 tree1->get_key() = 100;
632 tree2->get_key() = 200;
633 tree3->get_key() = 300;
641 string result =
out.str();
644 EXPECT_NE(result.find(
"100"), string::npos);
645 EXPECT_NE(result.find(
"200"), string::npos);
646 EXPECT_NE(result.find(
"300"), string::npos);
679 string result =
out.str();
681 EXPECT_NE(result.find(
"0xff"), string::npos);
689 const int DEPTH = 10;
694 for (
int i = 1; i <
DEPTH; ++i) {
703 string result =
out.str();
706 for (
int i = 0; i <
DEPTH; ++i) {
708 <<
"Missing node " << i;
713 EXPECT_NE(result.find(
"Node 0.0.0.0"), string::npos);
721 const int WIDTH = 10;
725 for (
int i = 1; i <=
WIDTH; ++i) {
728 root->insert_rightmost_child(child);
733 string result =
out.str();
736 for (
int i = 1; i <=
WIDTH; ++i) {
738 <<
"Missing child " << i;
818template <
typename GT>
835 out <<
"label=\"" << n->get_info() <<
"\"";
839 void operator()(
const Graph&,
Arc* a, ostream&
out) {
840 out <<
"label=\"" << a->get_info() <<
"\"";
847 string result =
out.str();
850 EXPECT_NE(result.find(
"20"), string::npos);
851 EXPECT_NE(result.find(
"30"), string::npos);
853 EXPECT_EQ(result.find(
"\"10\""), string::npos);
865 const int NUM_NODES = 100;
869 for (
int i = 0; i < NUM_NODES; ++i) {
870 nodes.push_back(g.insert_node(i));
874 for (
int i = 0; i < NUM_NODES - 1; ++i) {
880 string result =
out.str();
883 EXPECT_NE(result.find(
"graph {"), string::npos);
884 EXPECT_NE(result.find(
"}"), string::npos);
887 EXPECT_NE(result.find(
"\"0\""), string::npos);
888 EXPECT_NE(result.find(
"\"99\""), string::npos);
896 const int NUM_NODES = 100;
900 for (
int i = 0; i < NUM_NODES; ++i) {
901 nodes.push_back(tree.insert_node(i));
905 for (
int i = 1; i < NUM_NODES; ++i) {
906 int parent = (i - 1) / 2;
912 tn->get_key() =
gn->get_info();
925 if (node ==
nullptr)
return;
927 for (
auto* child = node->get_left_child(); child !=
nullptr;
928 child = child->get_right_sibling())
WeightedDigraph::Node Node
Generic directed graph (digraph) wrapper template.
typename BaseGraph::Arc Arc
typename BaseGraph::Node Node
T & insert(const T &item)
Insert a new item by copy.
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.
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.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
DynList< T > maps(const C &c, Op op)
Classic map operation.
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.