14#include <gtest/gtest.h>
47 for (
int i = 0; i < 100; ++i)
49 auto * p = this->set.insert(i);
50 ASSERT_NE(p,
nullptr) <<
"Failed to insert " << i;
57 for (
int i = 0; i < 100; ++i)
59 EXPECT_NE(this->set.search(i),
nullptr) <<
"Element " << i <<
" not found";
65 EXPECT_EQ(this->set.search(100),
nullptr);
66 EXPECT_EQ(this->set.search(1000),
nullptr);
75 for (
int i = 0; i < 100; ++i)
81 for (
int i = 0; i < 100; i += 2)
87 for (
int i = 0; i < 100; ++i)
91 EXPECT_EQ(this->set.search(i),
nullptr) <<
"Element " << i <<
" should be removed";
96 EXPECT_NE(this->set.search(i),
nullptr) <<
"Element " << i <<
" should exist";
105 for (
int i = 0; i < 50; ++i)
114 for (
int i = 0; i < 50; ++i)
126 for (
int i = 0; i < 50; ++i)
134 for (
int i = 0; i < 50; ++i)
141 for (
int i = 0; i < 50; ++i)
149 for (
int i = 0; i < 50; ++i)
156 for (
int i = 0; i < 50; ++i)
165 for (
int i = 0; i < 50; ++i)
173 vector<int> values = {50, 25, 75, 10, 30, 60, 90, 5, 15, 27, 35};
179 for (
auto it = this->set.get_it(); it.has_curr(); it.next_ne())
190 for (
int i = 0; i < 50; ++i)
202 for (
int i = 0; i < 50; ++i)
209 for (
int i : {50, 25, 75, 10, 90})
215 this->set.remove(10);
218 this->set.remove(90);
225 auto * p1 = this->set.insert(42);
230 auto * p2 = this->set.insert(42);
238 auto * p1 = this->set.search_or_insert(42);
243 auto * p2 = this->set.search_or_insert(42);
254 for (
int i = 0; i <
N; ++i)
257 EXPECT_EQ(this->set.size(),
static_cast<size_t>(
N));
262 for (
int i = 0; i <
N; i += 100)
266 for (
int i = 0; i <
N; i += 2)
269 EXPECT_EQ(this->set.size(),
static_cast<size_t>(
N / 2));
272 for (
int i = 0; i <
N; ++i)
286 for (
int i : {1, 2, 3})
288 for (
int i : {10, 20})
291 this->set.swap(
set2);
309 vector<string> words = {
"apple",
"banana",
"cherry",
"date",
"elderberry"};
311 for (
const auto&
word : words)
317 for (
const auto&
word : words)
325 for (
auto it = set.get_it(); it.has_curr(); it.next_ne())
336 for (
int i : {5, 2, 8, 1, 9})
341 for (
auto it = set.get_it(); it.has_curr(); it.next_ne())
344 vector<int>
expected = {9, 8, 5, 2, 1};
T & insert(const T &item)
Insert a new item by copy.
T remove()
Remove the first item of the list.
Dynamic set implemented using AVL binary search trees of type Avl_Tree<Key>.
Dynamic set implemented using binary search trees of type BinTree<Key>.
Dynamic set implemented using randomized binary search trees of type Rand_Tree<Key>.
Dynamic set implemented using Red-Black binary search trees of type Rb_Tree<Key> (bottom-up implement...
Dynamic set implemented using splay binary search trees of type Splay_Tree<Key>.
Dynamic set implemented using extended treap binary search trees with rank support of type Treap_Rk<K...
Dynamic set implemented using randomized treap binary search trees of type Treap<Key>.
Dynamic set backed by balanced binary search trees with automatic memory management.
Key * insert(const Key &key)
Inserts a key into the dynamic set.
size_t size() const noexcept
Count the number of elements of the list.
iterator end() noexcept
Return an STL-compatible end iterator.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
::testing::Types< DynSetBinTree< int >, DynSetAvlTree< int >, DynSetRbTree< int >, DynSetSplayTree< int >, DynSetTreap< int >, DynSetRandTree< int >, DynSetTreapRk< int > > AllTreeTypes
TYPED_TEST(DynSetTreeTest, InsertAndSearch)
TYPED_TEST_SUITE(DynSetTreeTest, AllTreeTypes)
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
DynList< T > maps(const C &c, Op op)
Classic map operation.
Dynamic set implementations based on balanced binary search trees.