Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
generate_df_tree_test.cc
Go to the documentation of this file.
1#include <gtest/gtest.h>
2#include <tpl_tree_node.H>
3
4// Test basic structures from generate_df_tree.H without Grafo dependency
5struct Clave
6{
7 int key;
8 long count;
9 long low;
10};
11
12struct Clave_Igual
13{
14 bool operator () (const Clave & c1, const Clave & c2) const
15 {
16 return c1.key == c2.key;
17 }
18};
19
20class GenerateDfTreeTest : public ::testing::Test
21{
22protected:
23 void SetUp() override {}
24 void TearDown() override {}
25};
26
28{
29 Clave c;
30 c.key = 65;
31 c.count = 1;
32 c.low = 0;
33
34 EXPECT_EQ(c.key, 65);
35 EXPECT_EQ(c.count, 1);
36 EXPECT_EQ(c.low, 0);
37}
38
40{
41 Clave c1 = {65, 1, 0};
42 Clave c2 = {65, 2, 1};
43 Clave c3 = {66, 1, 0};
44
46
49}
50
52{
53 Clave c = {42, 10, 5};
54
56 EXPECT_TRUE(cmp(c, c));
57}
58
60{
61 Clave c1 = {100, 1, 0};
62 Clave c2 = {100, 2, 1};
63
67}
68
70{
72 Clave& k = node.get_key();
73 k.key = 'A';
74 k.count = 0;
75 k.low = 0;
76
77 EXPECT_EQ(k.key, 'A');
78 EXPECT_EQ(k.count, 0);
79}
80
82{
84
85 for (int i = 0; i < 10; ++i)
86 {
87 for (int j = 0; j < 10; ++j)
88 {
89 Clave c1 = {i, 0, 0};
90 Clave c2 = {j, 0, 0};
91
92 if (i == j)
94 else
96 }
97 }
98}
99
101{
102 Clave c = {0, 0, 0};
103
104 EXPECT_EQ(c.key, 0);
105 EXPECT_EQ(c.count, 0);
106 EXPECT_EQ(c.low, 0);
107}
108
110{
111 Clave c = {10, 5, -1};
112
113 EXPECT_EQ(c.low, -1);
114}
115
117{
118 Clave c = {1000, 1000000, 500000};
119
120 EXPECT_EQ(c.key, 1000);
121 EXPECT_EQ(c.count, 1000000);
122 EXPECT_EQ(c.low, 500000);
123}
124
126{
128 std::vector<Clave> claves;
129
130 for (int i = 0; i < 50; ++i)
131 claves.push_back({i, i * 10, i * 5});
132
133 for (size_t i = 0; i < claves.size(); ++i)
134 {
135 EXPECT_TRUE(cmp(claves[i], claves[i]));
136
137 if (i + 1 < claves.size())
138 EXPECT_FALSE(cmp(claves[i], claves[i + 1]));
139 }
140}
size_t size() const noexcept
Count the number of elements of the list.
Definition htlist.H:1319
Generic m-ary trees.
T & get_key() noexcept
Returns a modifiable reference to the node contents.
TEST_F(GenerateDfTreeTest, ClaveStructure)
int cmp(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Definition gmpfrxx.h:4118
DynList< T > maps(const C &c, Op op)
Classic map operation.
Equality comparator for Clave structures.
bool operator()(const Clave &c1, const Clave &c2) const
Key structure for DFS tree nodes.
int key
Original node identifier.
long count
DFS discovery number (pre-order)
long low
Low-link value (minimum reachable via back edges)
General tree (n-ary tree) node.