Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
dyn_treap_test.cc
Go to the documentation of this file.
1#include <gtest/gtest.h>
2#include <tpl_dynTreap.H>
3
4using namespace Aleph;
5
6class DynTreapTest : public ::testing::Test
7{
8protected:
9 void SetUp() override {}
10 void TearDown() override {}
11};
12
18
20{
22
23 treap.insert(5, "five");
24 treap.insert(3, "three");
25 treap.insert(7, "seven");
26
28 EXPECT_EQ(treap.size(), 3u);
29}
30
32{
34
35 treap["one"] = 1;
36 treap["two"] = 2;
37 treap["three"] = 3;
38
39 EXPECT_EQ(treap["one"], 1);
40 EXPECT_EQ(treap["two"], 2);
41 EXPECT_EQ(treap["three"], 3);
42}
43
45{
47
48 treap[10] = 100;
49 EXPECT_EQ(treap[10], 100);
50
51 treap[10] = 200;
52 EXPECT_EQ(treap[10], 200);
53}
54
56{
58
59 treap.insert(5, 50);
60
61 EXPECT_TRUE(treap.has(5));
62 EXPECT_FALSE(treap.has(10));
63}
64
66{
68
69 treap.insert(1, 10);
70 treap.insert(2, 20);
71 treap.insert(3, 30);
72
74 EXPECT_FALSE(treap.has(2));
75 EXPECT_TRUE(treap.has(1));
76 EXPECT_TRUE(treap.has(3));
77}
78
80{
82
83 treap["apple"] = 1;
84 treap["banana"] = 2;
85
86 EXPECT_EQ(treap["apple"], 1);
87 EXPECT_EQ(treap["banana"], 2);
88}
89
91{
93
94 treap[-5] = 50;
95 treap[-1] = 10;
96 treap[0] = 0;
97
98 EXPECT_EQ(treap[-5], 50);
99 EXPECT_EQ(treap[0], 0);
100}
101
103{
105
106 for (int i = 0; i < 100; ++i)
107 treap[i] = i * 2;
108
109 EXPECT_EQ(treap.size(), 100u);
110
111 for (int i = 0; i < 100; i += 10)
112 EXPECT_EQ(treap[i], i * 2);
113}
114
116{
118
119 for (int i = 0; i < 50; ++i)
120 treap.insert(i, i);
121
122 EXPECT_EQ(treap.size(), 50u);
123
124 for (int i = 0; i < 50; i += 2)
125 treap.remove(i);
126
127 // After removing evens, only odds remain
128 EXPECT_EQ(treap.size(), 25u);
129
130 for (int i = 1; i < 50; i += 2)
131 EXPECT_TRUE(treap.has(i));
132}
133
135{
137 treap1[1] = "one";
138 treap1[2] = "two";
139
141
142 EXPECT_EQ(treap2.size(), 2u);
143 EXPECT_EQ(treap2[1], "one");
144 EXPECT_EQ(treap2[2], "two");
145}
T & insert(const T &item)
Insert a new item by copy.
Definition htlist.H:1502
T remove()
Remove the first item of the list.
Definition htlist.H:1611
constexpr bool is_empty() const noexcept
Return true if list is empty.
Definition htlist.H:523
size_t size() const noexcept
Count the number of elements of the list.
Definition htlist.H:1319
void TearDown() override
void SetUp() override
TEST_F(DynTreapTest, DefaultConstructor)
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
DynList< T > maps(const C &c, Op op)
Classic map operation.
Dynamic mapping implemented with treap trees.
Dynamic treap alias.