38#include <gtest/gtest.h>
51 "id|plazo|class|f3|nes|power|label\n"
52 "A|cp|it|x|12|5|Alpha\n"
53 "B|mp|ef|x|34|7|Beta\n"
54 "C|lp|pp|x|56|9|Gamma\n";
109 EXPECT_EQ(a->get_info().second[6],
"Alpha");
115 std::stringstream
nodes;
116 std::stringstream
arcs;
134 std::stringstream
nodes;
135 std::stringstream
arcs;
147 std::stringstream
nodes;
148 nodes <<
"id|plazo|class|f3|nes|power|label\n";
150 nodes <<
"E|cp|it|x|44|11|Echo\n";
152 std::stringstream
arcs;
167 EXPECT_EQ(e->get_info().second.size(), 7U);
185 std::stringstream
out;
187 const auto dot =
out.str();
189 EXPECT_NE(
dot.find(
"WARNING: Cycle detected"), std::string::npos);
190 EXPECT_NE(
dot.find(
"A [color=Green"), std::string::npos);
200 std::stringstream
arcs;
212 std::stringstream
out;
214 const auto dot =
out.str();
216 EXPECT_EQ(
dot.find(
"WARNING: Cycle detected"), std::string::npos);
217 EXPECT_NE(
dot.find(
"{ rank = same;"), std::string::npos);
226 std::stringstream
arcs;
237 std::stringstream
out;
239 const auto dot =
out.str();
245 EXPECT_NE(
dot.find(
"fontsize = 10"), std::string::npos);
253 split(
"a|b|c",
"|", words);
263 split(
"a,b c d",
" ,", words);
274 split(
"",
"|", words);
281 split(
"|||",
"|", words);
288 split(
"hello",
"|", words);
296 split(
"|a|b|",
"|", words);
320 std::stringstream
nodes;
321 std::stringstream
arcs;
336 std::stringstream
arcs;
349 auto *a = it.get_curr();
350 if (g.get_src_node(a) == g.get_tgt_node(a))
359 std::stringstream
nodes;
360 std::stringstream
arcs;
374 std::stringstream
nodes;
375 nodes <<
"id|plazo|class|f3|nes|power|label\n"
376 <<
"A|cp|it|x|10|1|Node1\n"
377 <<
"B|mp|ef|x|20|2|Node2\n"
378 <<
"C|lp|pp|x|30|3|Node3\n"
379 <<
"D|unknown|unknown|x|40|4|Node4\n";
381 std::stringstream
arcs;
395 std::stringstream
out;
397 const auto dot =
out.str();
400 EXPECT_NE(
dot.find(
"A [color=Green"), std::string::npos);
401 EXPECT_NE(
dot.find(
"B [color=Yellow"), std::string::npos);
406 EXPECT_NE(
dot.find(
"shape = ellipse"), std::string::npos);
407 EXPECT_NE(
dot.find(
"shape = hexagon"), std::string::npos);
419 std::stringstream
nodes;
420 nodes <<
"id|plazo|class|f3|nes|power|label\n"
421 <<
"X|cp|it|x|50|5|Single\n";
422 std::stringstream
arcs;
429 std::stringstream
out;
431 const auto dot =
out.str();
433 EXPECT_NE(
dot.find(
"X [color=Green"), std::string::npos);
441 std::stringstream
nodes;
442 nodes <<
"id|plazo|class|f3|nes|power|label\n"
443 <<
"A|cp|it|x|10|1|A\n"
444 <<
"B|mp|ef|x|20|2|B\n"
445 <<
"C|lp|pp|x|30|3|C\n"
446 <<
"D|cp|it|x|40|4|D\n";
447 std::stringstream
arcs;
456 std::stringstream
out;
458 const auto dot =
out.str();
460 EXPECT_EQ(
dot.find(
"WARNING: Cycle"), std::string::npos);
497 std::stringstream
nodes;
498 nodes <<
"id|plazo|class|f3|nes|power|label\n";
500 constexpr size_t NUM_NODES = 100;
501 for (
size_t i = 0; i < NUM_NODES; ++i)
503 nodes <<
"N" << i <<
"|cp|it|x|10|5|Node" << i <<
"\n";
506 std::stringstream
arcs;
507 for (
size_t i = 0; i < NUM_NODES - 1; ++i)
509 arcs <<
"N" << i <<
" N" << (i + 1) <<
"\n";
516 EXPECT_EQ(g.get_num_arcs(), NUM_NODES - 1);
519 std::stringstream
out;
521 const auto dot =
out.str();
522 EXPECT_EQ(
dot.find(
"WARNING: Cycle"), std::string::npos);
Generic directed graph (digraph) wrapper template.
Dynamic doubly linked list with O(1) size and bidirectional access.
const size_t & size() const noexcept
Return the number of elements (constant time)
T & append(const T &item)
Append a new item by copy.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
constexpr bool is_empty() const noexcept
Return true if list is empty.
DynArray< Graph::Node * > nodes
DynArray< Graph::Arc * > arcs
bool with_power
Configuration options for DOT file generation.
bool with_class
If true, set node shapes based on class field.
Digrafo::Node * search_node(Digrafo &g, const std::string &s)
Find or create a node by ID.
void load_digraph(Digrafo &g, std::istream &nodes_input, std::istream &arcs_input)
Load nodes and arcs from streams into the directed graph.
bool only_num
If true, show only the node number, not the full label.
size_t font_size
Font size for the DOT output.
void generate_dot_file(Digrafo &g, std::ostream &output)
Generate a DOT representation of the digraph.
bool with_nes
If true, include NES percentage in node labels.
Utilities for loading directed graphs from pipe-separated files.
Main namespace for Aleph-w library functions.
bool eq(const C1 &c1, const C2 &c2, Eq e=Eq())
Check equality of two containers using a predicate.
constexpr size_t MIN_NODE_FIELDS
Minimum expected columns for a node record.
std::pair< std::string, DynDlist< std::string > > Info_Nodo
Node payload: (id, fields) where fields come from the input row.
std::vector< std::string > & split(const std::string &s, const char delim, std::vector< std::string > &elems)
Split a std::string by a single delimiter character.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Filtered iterator on all the arcs of a graph.
Functor to compare nodes by their ID.