Skip to content

Commit 4100b90

Browse files
committed
Added tests for class address_table
1 parent f9b7146 commit 4100b90

File tree

2 files changed

+182
-0
lines changed

2 files changed

+182
-0
lines changed

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ set(IReSearch_tests_sources
4040
./formats/formats_tests.cpp
4141
./formats/formats_test_case_base.cpp
4242
./formats/skip_list_test.cpp
43+
./formats/address_table_tests.cpp
4344
./store/directory_test_case.cpp
4445
./store/caching_directory_test.cpp
4546
./store/directory_cleaner_tests.cpp
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
2+
#include <iostream>
3+
#include "formats/columnstore2.hpp"
4+
#include "resource_manager.hpp"
5+
#include <gtest/gtest.h>
6+
7+
using irs::columnstore2::column;
8+
9+
namespace {
10+
11+
class address_table_tests : public ::testing::Test {
12+
public:
13+
address_table_tests() { }
14+
15+
void SetUp() override {
16+
}
17+
18+
void TearDown() override {}
19+
20+
public:
21+
irs::ManagedTypedAllocator<uint64_t> alloc;
22+
};
23+
}
24+
25+
TEST_F(address_table_tests, smoke_test) {
26+
27+
column::address_table addr_table(alloc);
28+
29+
ASSERT_EQ(0, addr_table.size());
30+
31+
// push
32+
ASSERT_TRUE(addr_table.push_back(1));
33+
ASSERT_EQ(1, addr_table.size());
34+
35+
// pop
36+
ASSERT_TRUE(addr_table.pop_back());
37+
ASSERT_EQ(0, addr_table.size());
38+
39+
// full
40+
for (uint64_t i = 0; i < column::kBlockSize; i++) {
41+
ASSERT_TRUE(addr_table.push_back(i));
42+
}
43+
ASSERT_EQ(addr_table.size(), column::kBlockSize);
44+
ASSERT_TRUE(addr_table.full());
45+
46+
// reset
47+
addr_table.reset();
48+
ASSERT_TRUE(addr_table.empty());
49+
}
50+
51+
// pop when empty
52+
TEST_F(address_table_tests, pop_when_empty) {
53+
54+
column::address_table addr_table(alloc);
55+
ASSERT_TRUE(addr_table.empty());
56+
ASSERT_FALSE(addr_table.pop_back());
57+
}
58+
59+
// push when full
60+
TEST_F(address_table_tests, push_when_full) {
61+
62+
column::address_table addr_table(alloc);
63+
64+
ASSERT_TRUE(addr_table.empty());
65+
66+
for (uint64_t i = 0; i < column::kBlockSize; i++) {
67+
ASSERT_TRUE(addr_table.push_back(i));
68+
}
69+
70+
ASSERT_EQ(addr_table.size(), column::kBlockSize);
71+
ASSERT_FALSE(addr_table.push_back(2));
72+
73+
ASSERT_TRUE(addr_table.pop_back());
74+
ASSERT_TRUE(addr_table.push_back(2));
75+
}
76+
77+
// push and verify data
78+
TEST_F(address_table_tests, verify_data) {
79+
80+
column::address_table addr_table(alloc);
81+
82+
for (uint64_t i = 0; i < 200; i++) {
83+
ASSERT_TRUE(addr_table.push_back(i));
84+
}
85+
86+
ASSERT_EQ(addr_table.size(), 200);
87+
88+
auto curr = addr_table.current();
89+
auto begin = addr_table.begin();
90+
91+
uint64_t data { 199 };
92+
while (curr != begin) {
93+
--curr;
94+
ASSERT_EQ(*curr, data--);
95+
}
96+
}
97+
98+
// write using current ptr
99+
TEST_F(address_table_tests, write_using_current_ptr) {
100+
101+
column::address_table addr_table(alloc);
102+
103+
// add data via push_back.
104+
auto data = 0;
105+
for (uint64_t i = 0; i < 60; i++) {
106+
ASSERT_TRUE(addr_table.push_back(data++));
107+
}
108+
109+
// add data via current() ptr.
110+
// column::flush_block() uses address_table
111+
// in this way.
112+
auto curr = addr_table.current();
113+
uint64_t addr_table_size = 40900;
114+
auto end = curr + addr_table_size;
115+
116+
while (curr != end) {
117+
*curr++ = data++;
118+
}
119+
120+
// size is updated only when adding data
121+
// via push_back().
122+
ASSERT_EQ(addr_table.size(), 60);
123+
124+
auto begin = addr_table.begin();
125+
for (uint64_t i = 0; i < 40960; i++) {
126+
ASSERT_EQ(*begin++, i);
127+
}
128+
}
129+
130+
// size arithmetic
131+
TEST_F(address_table_tests, begin_current_end) {
132+
133+
column::address_table addr_table(alloc);
134+
135+
ASSERT_EQ(addr_table.size(), 0);
136+
ASSERT_TRUE(addr_table.push_back(45));
137+
ASSERT_EQ(addr_table.size(), 1);
138+
139+
ASSERT_EQ(addr_table.current(), addr_table.begin() + addr_table.size());
140+
}
141+
142+
// max size allowed
143+
TEST_F(address_table_tests, max_size_allowed) {
144+
145+
column::address_table addr_table(alloc);
146+
147+
// end() always points to begin() + kBlockSize
148+
// coz address_table pre-allocates memory to
149+
// accommodate kBlockSize elements.
150+
ASSERT_EQ(addr_table.size(), 0);
151+
ASSERT_EQ(addr_table.end(), addr_table.begin() + column::kBlockSize);
152+
ASSERT_EQ(addr_table.current(), addr_table.begin() + 0);
153+
154+
for (uint64_t i = 0; i < 1234; i++) {
155+
ASSERT_TRUE(addr_table.push_back(i));
156+
}
157+
158+
ASSERT_EQ(addr_table.end(), addr_table.begin() + column::kBlockSize);
159+
ASSERT_EQ(addr_table.current(), addr_table.begin() + 1234);
160+
}
161+
162+
// full
163+
TEST_F(address_table_tests, empty_full_and_reset) {
164+
165+
column::address_table addr_table(alloc);
166+
167+
ASSERT_FALSE(addr_table.full());
168+
for (uint64_t i = 0; i < column::kBlockSize; i++) {
169+
ASSERT_TRUE(addr_table.push_back(i));
170+
}
171+
ASSERT_TRUE(addr_table.full());
172+
173+
addr_table.pop_back();
174+
ASSERT_FALSE(addr_table.full());
175+
ASSERT_EQ(addr_table.current() + 1, addr_table.end());
176+
177+
addr_table.reset();
178+
ASSERT_FALSE(addr_table.full());
179+
ASSERT_EQ(addr_table.current(), addr_table.begin());
180+
ASSERT_EQ(addr_table.size(), 0);
181+
}

0 commit comments

Comments
 (0)