Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73397 - sandbox/bloom_filter/trunk/libs/bloom_filter/test
From: cpp.cabrera_at_[hidden]
Date: 2011-07-26 17:26:20


Author: alejandro
Date: 2011-07-26 17:26:19 EDT (Tue, 26 Jul 2011)
New Revision: 73397
URL: http://svn.boost.org/trac/boost/changeset/73397

Log:
Restructured counting_bloom-pass a bit. Corrected a source of randomness in dynamic_bloom-pass that might make swap tests fail randomly.
Text files modified:
   sandbox/bloom_filter/trunk/libs/bloom_filter/test/counting_bloom-pass.cpp | 136 +++++++++++++++++----------------------
   sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom-pass.cpp | 16 +++-
   2 files changed, 70 insertions(+), 82 deletions(-)

Modified: sandbox/bloom_filter/trunk/libs/bloom_filter/test/counting_bloom-pass.cpp
==============================================================================
--- sandbox/bloom_filter/trunk/libs/bloom_filter/test/counting_bloom-pass.cpp (original)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/test/counting_bloom-pass.cpp 2011-07-26 17:26:19 EDT (Tue, 26 Jul 2011)
@@ -25,38 +25,22 @@
 using boost::bloom_filters::detail::bin_overflow_exception;
 using boost::bloom_filters::boost_hash;
 
-typedef unsigned char small_block_type;
-typedef unsigned short med_block_type;
-typedef unsigned long large_block_type;
-
-static const size_t NUM_BINS = 8;
-
-enum {
- BITS_PER_BIN_ONE = 1,
- BITS_PER_BIN_TINY = 2,
- BITS_PER_BIN_DEFAULT = 4,
- BITS_PER_BIN_ODD = 5,
- BITS_PER_BIN_MED = 8,
- BITS_PER_BIN_LARGE = 16,
- BITS_PER_BIN_MAX = 32
-};
-
 BOOST_AUTO_TEST_CASE(defaultConstructor) {
   typedef boost::mpl::vector<
     boost_hash<int, 13>,
     boost_hash<int, 17>,
     boost_hash<int, 19> > BoostHashFunctions;
   
- counting_bloom_filter<int, NUM_BINS> bloom1;
- counting_bloom_filter<int, NUM_BINS, BITS_PER_BIN_ONE> bloom2;
- counting_bloom_filter<int, NUM_BINS, BITS_PER_BIN_TINY, BoostHashFunctions> bloom3;
- counting_bloom_filter<int, NUM_BINS, BITS_PER_BIN_MED,
- BoostHashFunctions, small_block_type> bloom4;
+ counting_bloom_filter<int, 2> bloom1;
+ counting_bloom_filter<int, 2, 1> bloom2;
+ counting_bloom_filter<int, 2, 2, BoostHashFunctions> bloom3;
+ counting_bloom_filter<int, 2, 4,
+ BoostHashFunctions, unsigned char> bloom4;
 }
 
 BOOST_AUTO_TEST_CASE(countSingle)
 {
- counting_bloom_filter<int, NUM_BINS> bloom;
+ counting_bloom_filter<int, 2> bloom;
   
   bloom.insert(1);
   BOOST_CHECK_EQUAL(bloom.count(), 1ul);
@@ -95,14 +79,14 @@
 
 BOOST_AUTO_TEST_CASE(rangeConstructor) {
   int elems[5] = {1,2,3,4,5};
- counting_bloom_filter<int, NUM_BINS> bloom(elems, elems+5);
+ counting_bloom_filter<int, 5> bloom(elems, elems+5);
 
   BOOST_CHECK_EQUAL(bloom.count(), 5ul);
 }
 
 #ifndef BOOST_NO_0X_HDR_INITIALIZER_LIST
 BOOST_AUTO_TEST_CASE(initListConstructor) {
- counting_bloom_filter<int, NUM_BINS> bloom = {1,2,3,4,5};
+ counting_bloom_filter<int, 5> bloom = {1,2,3,4,5};
 
   BOOST_CHECK_EQUAL(bloom.count(), 5ul);
 }
@@ -110,8 +94,8 @@
 
 BOOST_AUTO_TEST_CASE(copyConstructor) {
   int elems[5] = {1,2,3,4,5};
- counting_bloom_filter<int, NUM_BINS> bloom1(elems, elems+5);
- counting_bloom_filter<int, NUM_BINS> bloom2(bloom1);
+ counting_bloom_filter<int, 5> bloom1(elems, elems+5);
+ counting_bloom_filter<int, 5> bloom2(bloom1);
 
   BOOST_CHECK_EQUAL(bloom1.count(), bloom2.count());
 }
@@ -138,13 +122,13 @@
   counting_bloom_filter<size_t, 256> bloom_256;
   counting_bloom_filter<size_t, 2048> bloom_2048;
   
- BOOST_CHECK_EQUAL(bloom_8.bit_capacity(), 8ul * BITS_PER_BIN_DEFAULT);
- BOOST_CHECK_EQUAL(bloom_256.bit_capacity(), 256ul * BITS_PER_BIN_DEFAULT);
- BOOST_CHECK_EQUAL(bloom_2048.bit_capacity(), 2048ul * BITS_PER_BIN_DEFAULT);
+ BOOST_CHECK_EQUAL(bloom_8.bit_capacity(), 8ul * 4ul);
+ BOOST_CHECK_EQUAL(bloom_256.bit_capacity(), 256ul * 4ul);
+ BOOST_CHECK_EQUAL(bloom_2048.bit_capacity(), 2048ul * 4ul);
 }
 
 BOOST_AUTO_TEST_CASE(empty) {
- counting_bloom_filter<size_t, NUM_BINS> bloom;
+ counting_bloom_filter<size_t, 2> bloom;
   
   BOOST_CHECK_EQUAL(bloom.empty(), true);
   bloom.insert(1);
@@ -154,11 +138,11 @@
 }
 
 BOOST_AUTO_TEST_CASE(numHashFunctions) {
- counting_bloom_filter<size_t, NUM_BINS> bloom_1;
- counting_bloom_filter<size_t, NUM_BINS, BITS_PER_BIN_TINY, boost::mpl::vector<
+ counting_bloom_filter<size_t, 1> bloom_1;
+ counting_bloom_filter<size_t, 1, 1, boost::mpl::vector<
     boost_hash<size_t, 1>,
     boost_hash<size_t, 2> > > bloom_2;
- counting_bloom_filter<size_t, NUM_BINS, BITS_PER_BIN_TINY, boost::mpl::vector<
+ counting_bloom_filter<size_t, 1, 1, boost::mpl::vector<
     boost_hash<size_t, 1>,
     boost_hash<size_t, 2>,
     boost_hash<size_t, 3>,
@@ -205,7 +189,7 @@
 */
 
 BOOST_AUTO_TEST_CASE(probably_contains) {
- counting_bloom_filter<size_t, NUM_BINS> bloom;
+ counting_bloom_filter<size_t, 2> bloom;
 
   bloom.insert(1);
   BOOST_CHECK_EQUAL(bloom.probably_contains(1), true);
@@ -213,13 +197,13 @@
 }
 
 BOOST_AUTO_TEST_CASE(doesNotContain) {
- counting_bloom_filter<size_t, NUM_BINS> bloom;
+ counting_bloom_filter<size_t, 2> bloom;
 
   BOOST_CHECK_EQUAL(bloom.probably_contains(1), false);
 }
 
 BOOST_AUTO_TEST_CASE(insertNoFalseNegatives) {
- counting_bloom_filter<size_t, 2048> bloom;
+ counting_bloom_filter<size_t, 100> bloom;
 
   for (size_t i = 0; i < 100; ++i) {
     bloom.insert(i);
@@ -228,21 +212,12 @@
 }
 
 BOOST_AUTO_TEST_CASE(insertOverflowExceptionThrown) {
- counting_bloom_filter<size_t, 8, 2> bloom;
+ counting_bloom_filter<size_t, 2, 1> bloom;
   bool exception_occurred = false;
 
   bloom.insert(1);
   BOOST_CHECK_EQUAL(bloom.probably_contains(1), true);
 
- bloom.insert(1);
- BOOST_CHECK_EQUAL(bloom.probably_contains(1), true);
-
- bloom.insert(1);
- BOOST_CHECK_EQUAL(bloom.probably_contains(1), true);
-
- bloom.insert(1);
- BOOST_CHECK_EQUAL(bloom.probably_contains(1), true);
-
   try {
     bloom.insert(1);
   }
@@ -256,7 +231,7 @@
 }
 
 BOOST_AUTO_TEST_CASE(insertUnderflowExceptionThrown) {
- counting_bloom_filter<size_t, 8, 2> bloom;
+ counting_bloom_filter<size_t, 2, 1> bloom;
   bool exception_occurred = false;
 
   try {
@@ -273,14 +248,14 @@
 
 BOOST_AUTO_TEST_CASE(rangeInsert) {
   int elems[5] = {1,2,3,4,5};
- counting_bloom_filter<size_t, NUM_BINS> bloom;
+ counting_bloom_filter<size_t, 5> bloom;
 
   bloom.insert(elems, elems+5);
   BOOST_CHECK_EQUAL(bloom.count(), 5ul);
 }
 
 BOOST_AUTO_TEST_CASE(_remove) {
- counting_bloom_filter<size_t, NUM_BINS> bloom;
+ counting_bloom_filter<size_t, 1> bloom;
   
   bloom.insert(1);
   bloom.remove(1);
@@ -299,7 +274,7 @@
 
 BOOST_AUTO_TEST_CASE(rangeRemove) {
   size_t arr[] = {1,2,3,4,5};
- counting_bloom_filter<size_t, 100> bloom;
+ counting_bloom_filter<size_t, 5> bloom;
 
   bloom.insert(arr, arr+5);
   bloom.remove(arr, arr+5);
@@ -307,7 +282,7 @@
 }
 
 BOOST_AUTO_TEST_CASE(clear) {
- counting_bloom_filter<size_t, NUM_BINS> bloom;
+ counting_bloom_filter<size_t, 1000> bloom;
 
   for (size_t i = 0; i < 1000; ++i)
     bloom.insert(i);
@@ -317,22 +292,46 @@
   BOOST_CHECK_EQUAL(bloom.count(), 0ul);
 }
 
-BOOST_AUTO_TEST_CASE(memberSwap) {
- size_t elems[5] = {1,2,3,4,5};
- counting_bloom_filter<size_t, NUM_BINS> bloom1(elems, elems+2);
- counting_bloom_filter<size_t, NUM_BINS> bloom2(elems+2, elems+5);
+struct SwapFixture {
+ SwapFixture()
+ {
+ for (size_t i = 0; i < 5; ++i)
+ elems[i] = i+1;
+
+ bloom1.insert(elems, elems+2);
+ bloom2.insert(elems+2, elems+5);
+ }
 
+ size_t elems[5];
+ counting_bloom_filter<size_t, 5> bloom1;
+ counting_bloom_filter<size_t, 5> bloom2;
+};
+
+BOOST_FIXTURE_TEST_CASE(memberSwap, SwapFixture) {
   bloom1.swap(bloom2);
 
   BOOST_CHECK_EQUAL(bloom1.count(), 3ul);
   BOOST_CHECK_EQUAL(bloom2.count(), 2ul);
 }
 
+BOOST_FIXTURE_TEST_CASE(globalSwap, SwapFixture) {
+ swap(bloom1, bloom2);
+
+ BOOST_CHECK_EQUAL(bloom1.count(), 3ul);
+ BOOST_CHECK_EQUAL(bloom2.count(), 2ul);
+}
+
+struct PairwiseOpsFixture {
+
+ PairwiseOpsFixture() {}
+
+ counting_bloom_filter<size_t, 300> bloom1;
+ counting_bloom_filter<size_t, 300> bloom2;
+ counting_bloom_filter<size_t, 300> bloom_result;
+};
+
 /*
 BOOST_AUTO_TEST_CASE(testUnion) {
- counting_bloom_filter<size_t, 300> bloom_1;
- counting_bloom_filter<size_t, 300> bloom_2;
- counting_bloom_filter<size_t, 300> bloom_union;
 
   for (size_t i = 0; i < 100; ++i)
     bloom_1.insert(i);
@@ -395,21 +394,7 @@
 }
 */
 
-BOOST_AUTO_TEST_CASE(globalSwap) {
- size_t elems[5] = {1,2,3,4,5};
- counting_bloom_filter<size_t, NUM_BINS> bloom1(elems, elems+2);
- counting_bloom_filter<size_t, NUM_BINS> bloom2(elems+2, elems+5);
-
- swap(bloom1, bloom2);
-
- BOOST_CHECK_EQUAL(bloom1.count(), 3ul);
- BOOST_CHECK_EQUAL(bloom2.count(), 2ul);
-}
-
-BOOST_AUTO_TEST_CASE(equalityOperator) {
- counting_bloom_filter<int, NUM_BINS> bloom1;
- counting_bloom_filter<int, NUM_BINS> bloom2;
-
+BOOST_FIXTURE_TEST_CASE(equalityOperator, PairwiseOpsFixture) {
   BOOST_CHECK_EQUAL(bloom1 == bloom2, true);
   bloom1.insert(1);
   BOOST_CHECK_EQUAL(bloom1 == bloom2, false);
@@ -417,10 +402,7 @@
   BOOST_CHECK_EQUAL(bloom1 == bloom2, true);
 }
 
-BOOST_AUTO_TEST_CASE(inequalityOperator) {
- counting_bloom_filter<int, NUM_BINS> bloom1;
- counting_bloom_filter<int, NUM_BINS> bloom2;
-
+BOOST_FIXTURE_TEST_CASE(inequalityOperator, PairwiseOpsFixture) {
   BOOST_CHECK_EQUAL(bloom1 != bloom2, false);
   bloom1.insert(1);
   BOOST_CHECK_EQUAL(bloom1 != bloom2, true);

Modified: sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom-pass.cpp
==============================================================================
--- sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom-pass.cpp (original)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom-pass.cpp 2011-07-26 17:26:19 EDT (Tue, 26 Jul 2011)
@@ -34,14 +34,14 @@
 
 BOOST_AUTO_TEST_CASE(rangeConstructor) {
   int elems[5] = {1,2,3,4,5};
- dynamic_bloom_filter<int> bloom(8, elems, elems+5);
+ dynamic_bloom_filter<int> bloom(elems, elems+5);
 
   BOOST_CHECK_EQUAL(bloom.count(), 5ul);
 }
 
 BOOST_AUTO_TEST_CASE(copyConstructor) {
   int elems[5] = {1,2,3,4,5};
- dynamic_bloom_filter<int> bloom1(8, elems, elems+5);
+ dynamic_bloom_filter<int> bloom1(elems, elems+5);
   dynamic_bloom_filter<int> bloom2(bloom1);
 
   BOOST_CHECK_EQUAL(bloom1.count(), bloom2.count());
@@ -178,9 +178,15 @@
 }
 
 struct SwapFixture {
- SwapFixture() :
- bloom1(10, elems, elems+2),
- bloom2(20, elems+2, elems+5) {}
+ SwapFixture()
+ : bloom1(10), bloom2(20)
+ {
+ for (size_t i = 0; i < 5; ++i)
+ elems[i] = i+1;
+
+ bloom1.insert(elems, elems+2);
+ bloom2.insert(elems+2, elems+5);
+ }
 
   dynamic_bloom_filter<size_t> bloom1;
   dynamic_bloom_filter<size_t> bloom2;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk