X-Git-Url: https://git.sthu.org/?p=libstick.git;a=blobdiff_plain;f=tests%2Fbooleanvector.h;fp=tests%2Fbooleanvector.h;h=ebf6b9f8500108d26f5a44586affc58c4792ad16;hp=0000000000000000000000000000000000000000;hb=67e57c5aa58f667dc96dfee34ec4859af175b7a9;hpb=1e1b88154c99e34f7d84403adfbb3b7fb364a80e diff --git a/tests/booleanvector.h b/tests/booleanvector.h new file mode 100644 index 0000000..ebf6b9f --- /dev/null +++ b/tests/booleanvector.h @@ -0,0 +1,99 @@ +#ifndef booleanvector_h_MeiTephaijaequuy +#define booleanvector_h_MeiTephaijaequuy + +#include +#include + +#include + +using namespace libstick; + + +class boolean_vector_TestSuite: public Test::Suite { + public: + boolean_vector_TestSuite() { + TEST_ADD(boolean_vector_TestSuite::test >); + TEST_ADD(boolean_vector_TestSuite::test >); + + //TEST_ADD(boolean_vector_TestSuite::test_performance >); + //TEST_ADD(boolean_vector_TestSuite::test_performance >); + } + + protected: + virtual void setup() { + } + + virtual void tear_down() { + } + + private: + template + void test() { + const int size = 1000; + + T even; + for (int i=1; 2*i <= size; ++i) + even.set(2*i, true); + + // We added size/2 ones, all of them at even indices. + TEST_ASSERT(even.get_ones().size() == size/2); + for (typename T::indexarray::const_iterator it = even.get_ones().begin(); + it != even.get_ones().end(); ++it) + TEST_ASSERT(*it % 2 == 0); + for (int i=1; i <= size; ++i) + TEST_ASSERT(even.get(i) == (i % 2 == 0)); + + // A complete vector + T all; + for (int i=1; i <= size; ++i) + all.set(i, true); + + // A vector with all odd entries + T odd = even; + odd.add(all); + + // Again size/2 entries in odd. + TEST_ASSERT(odd.get_ones().size() == size/2); + // Check whether we really have odd indices only + for (typename T::indexarray::const_iterator it = odd.get_ones().begin(); + it != odd.get_ones().end(); ++it) + TEST_ASSERT(*it % 2 == 1); + for (int i=1; i <= size; ++i) + TEST_ASSERT(odd.get(i) == (i % 2 == 1)); + + + all.pop_back(); + even.pop_back(); + T all2 = odd; + all2.add(even); + TEST_ASSERT(all2 == all); + } + + template + void test_performance() { + T sum; + + const int size = 1000; + const int cnt = 4; + + T summand; + for (int a=0; a < cnt; ++a) { + summand.clear(); + for (int i=0; i < size; ++i) + summand.set(a*(size/2) + i, true); + sum.add(summand); + } + + //for (int i=0; i < size/2; ++i) { + //TEST_ASSERT(sum.get(i) == true); + //TEST_ASSERT(sum.get(i + size/2) == false); + //TEST_ASSERT(sum.get(i + (cnt-1)*(size/2)) == false); + //TEST_ASSERT(sum.get(i + (cnt)*(size/2)) == true); + //} + + //std::cout << std::endl << sum << std::endl; + } +}; + + +#endif