6#include <gtest/gtest.h>
33 child = child->get_right_sibling())
46 size_t max_child_height = 0;
49 child = child->get_right_sibling())
52 if (
h > max_child_height)
56 return 1 + max_child_height;
68 while (child !=
nullptr)
93 ASSERT_NE(tree,
nullptr);
99 if (p->get_key() != 0)
101 for (
auto * c = p->get_left_child(); c !=
nullptr; c = c->get_right_sibling())
105 EXPECT_EQ(nonzero, 0u);
115 ASSERT_NE(tree,
nullptr);
116 EXPECT_EQ(count_nodes(tree), 1u);
117 EXPECT_EQ(tree_height(tree), 1u);
128 ASSERT_NE(tree,
nullptr);
129 EXPECT_EQ(count_nodes(tree), 5u);
130 EXPECT_GT(tree_height(tree), 0u);
140 ASSERT_NE(tree,
nullptr);
141 EXPECT_EQ(count_nodes(tree), 50u);
151 ASSERT_NE(tree,
nullptr);
152 EXPECT_EQ(count_nodes(tree), 500u);
163 const unsigned seed = 12345;
172 ASSERT_NE(tree1,
nullptr);
173 ASSERT_NE(tree2,
nullptr);
176 EXPECT_EQ(count_nodes(tree1), count_nodes(tree2));
179 EXPECT_EQ(tree_height(tree1), tree_height(tree2));
195 ASSERT_NE(tree1,
nullptr);
196 ASSERT_NE(tree2,
nullptr);
199 EXPECT_EQ(count_nodes(tree1), n);
200 EXPECT_EQ(count_nodes(tree2), n);
204 EXPECT_GT(tree_height(tree1), 0u);
205 EXPECT_GT(tree_height(tree2), 0u);
219 for (
int i = 0; i < 10; ++i)
222 ASSERT_NE(tree,
nullptr);
223 EXPECT_EQ(count_nodes(tree),
static_cast<size_t>(10 + i * 5));
233 ASSERT_NE(tree,
nullptr);
234 EXPECT_EQ(count_nodes(tree), 2000u);
248 ASSERT_NE(tree,
nullptr);
249 EXPECT_EQ(count_nodes(tree), 2u);
253 ASSERT_NE(child,
nullptr);
265 ASSERT_NE(tree,
nullptr);
266 EXPECT_EQ(count_nodes(tree), 3u);
280 ASSERT_NE(tree,
nullptr);
281 EXPECT_EQ(count_nodes(tree), 20u);
291 ASSERT_NE(tree,
nullptr);
292 EXPECT_EQ(count_nodes(tree), 15u);
309 ASSERT_NE(tree1,
nullptr);
310 ASSERT_NE(tree2,
nullptr);
313 EXPECT_EQ(count_nodes(tree1), 10u);
314 EXPECT_EQ(count_nodes(tree2), 10u);
329 ASSERT_NE(tree,
nullptr);
341 if (not validate(child))
348 EXPECT_TRUE(validate(tree));
349 EXPECT_EQ(count_nodes(tree), 100u);
362 std::vector<size_t> sizes = {10, 50, 100, 500, 1000};
364 for (
size_t n : sizes)
367 ASSERT_NE(tree,
nullptr);
368 EXPECT_EQ(count_nodes(tree), n);
Forward declaration used by CRTP helpers before the full node definition.
Tree_Node * get_left_child() const noexcept
Returns the leftmost child of this.
Tree_Node * get_right_sibling() const noexcept
Returns the right sibling of this.
T & get_key() noexcept
Returns a modifiable reference to the node contents.
Generator for uniformly random trees.
void destroy_tree(Tree_Node< T > *root)
size_t count_nodes(Tree_Node< T > *root)
size_t tree_height(Tree_Node< T > *root)
__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)
void destroy_tree(Node *root)
Destroys (frees memory) the tree whose root is root.
Main namespace for Aleph-w library functions.
void next()
Advance all underlying iterators (bounds-checked).
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
TEST_F(RandomTreeTest, EveryKeyIsValueInitialized)
Utility functions for binary tree operations.
General tree (n-ary tree) node.