forked from ot/succinct
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_gamma_bit_vector.cpp
62 lines (48 loc) · 1.47 KB
/
test_gamma_bit_vector.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
#define BOOST_TEST_MODULE gamma_bit_vector
#include "test_common.hpp"
#include <cstdlib>
#include "gamma_bit_vector.hpp"
typedef std::vector<uint64_t> std_vector_type;
std_vector_type random_vector(size_t test_size)
{
std_vector_type v;
for (size_t i = 0; i < test_size; ++i) {
bool b = uint64_t(rand()) & 1;
if (rand() < (RAND_MAX / 3)) {
v.push_back(b);
} else {
v.push_back((uint64_t(rand()) << 1) | b);
}
}
return v;
}
BOOST_AUTO_TEST_CASE(gamma_bit_vector)
{
srand(42);
const size_t test_size = 12345;
std_vector_type v = random_vector(test_size);
succinct::gamma_bit_vector vv(v);
BOOST_REQUIRE_EQUAL(v.size(), vv.size());
for (size_t i = 0; i < v.size(); ++i) {
MY_REQUIRE_EQUAL(v[i], vv[i], "i = " << i);
}
}
BOOST_AUTO_TEST_CASE(gamma_bit_enumerator)
{
srand(42);
const size_t test_size = 12345;
std_vector_type v = random_vector(test_size);
succinct::gamma_bit_vector vv(v);
size_t i = 0;
size_t pos = 0;
succinct::forward_enumerator<succinct::gamma_bit_vector> e(vv, pos);
while (pos < vv.size()) {
succinct::gamma_bit_vector::value_type next = e.next();
MY_REQUIRE_EQUAL(next, v[pos], "pos = " << pos << " i = " << i);
pos += 1;
size_t step = uint64_t(rand()) % (vv.size() - pos + 1);
pos += step;
e = succinct::forward_enumerator<succinct::gamma_bit_vector>(vv, pos);
i += 1;
}
}