-
Notifications
You must be signed in to change notification settings - Fork 17
/
test_darray.cpp
76 lines (65 loc) · 1.82 KB
/
test_darray.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#define BOOST_TEST_MODULE darray
#include "test_common.hpp"
#include "test_rank_select_common.hpp"
#include <cstdlib>
#include <boost/foreach.hpp>
#include "mapper.hpp"
#include "darray.hpp"
void test_darray(std::vector<bool> const& v, const char* test_name)
{
succinct::bit_vector bv(v);
succinct::darray1 d1(bv);
succinct::darray0 d0(bv);
size_t cur_rank = 0;
size_t cur_rank0 = 0;
for (size_t i = 0; i < v.size(); ++i) {
if (v[i]) {
MY_REQUIRE_EQUAL(i, d1.select(bv, cur_rank),
"select (" << test_name << "): cur_rank = " << cur_rank << ", i = " << i << ", v[i] = " << v[i]);
cur_rank += 1;
} else {
MY_REQUIRE_EQUAL(i, d0.select(bv, cur_rank0),
"select0 (" << test_name << "): cur_rank0 = " << cur_rank0 << ", i = " << i << ", v[i] = " << v[i]);
cur_rank0 += 1;
}
}
BOOST_REQUIRE_EQUAL(cur_rank, d1.num_positions());
BOOST_REQUIRE_EQUAL(cur_rank0, d0.num_positions());
}
BOOST_AUTO_TEST_CASE(darray)
{
srand(42);
size_t N = 10000;
{
// Random bitmap
std::vector<bool> v = random_bit_vector(N);
test_darray(v, "random");
}
{
// Empty bitmap
std::vector<bool> v;
test_darray(v, "empty");
}
{
// Only one value
std::vector<bool> v(N);
v[37] = 1;
test_darray(v, "singleton");
}
{
// Full bitmap
std::vector<bool> v(N, 1);
test_darray(v, "full");
}
{
// Very sparse random bitmap
size_t bigN = (1 << 16) * 4;
std::vector<bool> v(bigN);
size_t cur_pos = 0;
while(cur_pos < bigN) {
v[cur_pos] = 1;
cur_pos += rand() % 1024;
}
test_darray(v, "sparse");
}
}