Skip to content

Commit

Permalink
Merge pull request #333 from simongog/fix_sd_vector_builder
Browse files Browse the repository at this point in the history
sd_vector_builder now works for all sd_vector configurations
  • Loading branch information
simongog authored Jun 29, 2016
2 parents 7a7bec4 + 8967714 commit 0ae738f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
4 changes: 2 additions & 2 deletions include/sdsl/sd_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ class sd_vector
m_wl = builder.m_wl;
m_low.swap(builder.m_low);
util::assign(m_high, builder.m_high);
util::init_support(m_high_1_select, this->m_high);
util::init_support(m_high_0_select, this->m_high);
util::init_support(m_high_1_select, &(this->m_high));
util::init_support(m_high_0_select, &(this->m_high));

builder = sd_vector_builder();
}
Expand Down
21 changes: 0 additions & 21 deletions test/bit_vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,6 @@ TYPED_TEST(bit_vector_test, swap)
}
}

/*
TEST(SD_VECTOR, IteratorConstructor)
{
std::vector<uint64_t> pos;
bit_vector bv(100000);
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;
}
}
sd_vector<> sdv(pos.begin(),pos.end());
for (size_t i=0; i < bv.size(); ++i) {
ASSERT_EQ((bool)sdv[i],(bool)bv[i]);
}
}
*/

}// end namespace

int main(int argc, char* argv[])
Expand Down
27 changes: 20 additions & 7 deletions test/sd_vector_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "sdsl/sd_vector.hpp"
#include "sdsl/bit_vectors.hpp"
#include "gtest/gtest.h"

using namespace sdsl;
Expand All @@ -9,7 +10,19 @@ namespace

const size_t BV_SIZE = 1000000;

TEST(sd_vector_test, iterator_constructor)
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);
Expand All @@ -22,13 +35,13 @@ TEST(sd_vector_test, iterator_constructor)
bv[i] = 1;
}
}
sd_vector<> sdv(pos.begin(),pos.end());
TypeParam sdv(pos.begin(),pos.end());
for (size_t i=0; i < bv.size(); ++i) {
ASSERT_EQ((bool)sdv[i],(bool)bv[i]);
}
}

TEST(sd_vector_test, builder_constructor)
TYPED_TEST(sd_vector_test, builder_constructor)
{
std::vector<uint64_t> pos;
bit_vector bv(BV_SIZE);
Expand All @@ -47,18 +60,18 @@ TEST(sd_vector_test, builder_constructor)
for (auto i : pos) {
builder.set(i);
}
sd_vector<> sdv(builder);
TypeParam sdv(builder);
for (size_t i=0; i < bv.size(); ++i) {
ASSERT_EQ((bool)sdv[i],(bool)bv[i]);
}
}

TEST(sd_vector_test, builder_empty_constructor)
TYPED_TEST(sd_vector_test, builder_empty_constructor)
{
sd_vector_builder builder(BV_SIZE, 0UL);
sd_vector<> sdv(builder);
TypeParam sdv(builder);
for (size_t i=0; i < BV_SIZE; ++i) {
ASSERT_EQ(0, sdv[i]);
ASSERT_FALSE((bool)sdv[i]);
}
}

Expand Down

0 comments on commit 0ae738f

Please sign in to comment.