forked from simongog/sdsl-lite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsd_vector_test.cpp
85 lines (72 loc) · 1.88 KB
/
sd_vector_test.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
77
78
79
80
81
82
83
84
#include "sdsl/sd_vector.hpp"
#include "sdsl/bit_vectors.hpp"
#include "gtest/gtest.h"
using namespace sdsl;
using namespace std;
namespace
{
const size_t BV_SIZE = 1000000;
template<class T>
class sd_vector_test : public ::testing::Test { };
using testing::Types;
typedef Types<
sd_vector<>,
sd_vector<rrr_vector<63>>
> Implementations;
TYPED_TEST_CASE(sd_vector_test, Implementations);
TYPED_TEST(sd_vector_test, iterator_constructor)
{
std::vector<uint64_t> pos;
bit_vector bv(BV_SIZE);
std::mt19937_64 rng;
std::uniform_int_distribution<uint64_t> distribution(0, 9);
auto dice = bind(distribution, rng);
for (size_t i=0; i < bv.size(); ++i) {
if (0 == dice()) {
pos.emplace_back(i);
bv[i] = 1;
}
}
TypeParam sdv(pos.begin(),pos.end());
for (size_t i=0; i < bv.size(); ++i) {
ASSERT_EQ((bool)sdv[i],(bool)bv[i]);
}
}
TYPED_TEST(sd_vector_test, builder_constructor)
{
std::vector<uint64_t> pos;
bit_vector bv(BV_SIZE);
std::mt19937_64 rng;
std::uniform_int_distribution<uint64_t> distribution(0, 9);
auto dice = bind(distribution, rng);
size_t ones = 0;
for (size_t i=0; i < bv.size(); ++i) {
if (0 == dice()) {
pos.emplace_back(i);
bv[i] = 1;
ones++;
}
}
sd_vector_builder builder(BV_SIZE, ones);
for (auto i : pos) {
builder.set(i);
}
TypeParam sdv(builder);
for (size_t i=0; i < bv.size(); ++i) {
ASSERT_EQ((bool)sdv[i],(bool)bv[i]);
}
}
TYPED_TEST(sd_vector_test, builder_empty_constructor)
{
sd_vector_builder builder(BV_SIZE, 0UL);
TypeParam sdv(builder);
for (size_t i=0; i < BV_SIZE; ++i) {
ASSERT_FALSE((bool)sdv[i]);
}
}
} // end namespace
int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}