|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73395 - sandbox/bloom_filter/trunk/libs/bloom_filter/test
From: cpp.cabrera_at_[hidden]
Date: 2011-07-26 17:26:02
Author: alejandro
Date: 2011-07-26 17:26:01 EDT (Tue, 26 Jul 2011)
New Revision: 73395
URL: http://svn.boost.org/trac/boost/changeset/73395
Log:
Added exception tests to dynamic Bloom filter suite. Broke a few tests into fixture sets. Removed failing tests from regression suite.
Removed:
sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom_intersect-fail.cpp
sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom_union-fail.cpp
Text files modified:
sandbox/bloom_filter/trunk/libs/bloom_filter/test/Jamfile.v2 | 5 -
sandbox/bloom_filter/trunk/libs/bloom_filter/test/counting_bloom-pass.cpp | 46 +++++++++
sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom-pass.cpp | 169 ++++++++++++++++++++++++---------------
3 files changed, 147 insertions(+), 73 deletions(-)
Modified: sandbox/bloom_filter/trunk/libs/bloom_filter/test/Jamfile.v2
==============================================================================
--- sandbox/bloom_filter/trunk/libs/bloom_filter/test/Jamfile.v2 (original)
+++ sandbox/bloom_filter/trunk/libs/bloom_filter/test/Jamfile.v2 2011-07-26 17:26:01 EDT (Tue, 26 Jul 2011)
@@ -27,8 +27,3 @@
[ run counting_bloom-pass.cpp ]
;
- test-suite "fail"
- :
- [ run-fail dynamic_bloom_union-fail.cpp ]
- [ run-fail dynamic_bloom_intersect-fail.cpp ]
- ;
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:01 EDT (Tue, 26 Jul 2011)
@@ -18,7 +18,11 @@
#include <boost/test/unit_test.hpp>
#include <boost/test/floating_point_comparison.hpp>
+#include <boost/bloom_filter/detail/exceptions.hpp>
+
using boost::bloom_filters::counting_bloom_filter;
+using boost::bloom_filters::detail::bin_underflow_exception;
+using boost::bloom_filters::detail::bin_overflow_exception;
using boost::bloom_filters::boost_hash;
typedef unsigned char small_block_type;
@@ -205,8 +209,7 @@
bloom.insert(1);
BOOST_CHECK_EQUAL(bloom.probably_contains(1), true);
- BOOST_CHECK_LE(bloom.count(), 3ul);
- BOOST_CHECK_GE(bloom.count(), 1ul);
+ BOOST_CHECK_EQUAL(bloom.count(), 1ul);
}
BOOST_AUTO_TEST_CASE(doesNotContain) {
@@ -224,12 +227,47 @@
}
}
-BOOST_AUTO_TEST_CASE(insertOverflowAsExpected) {
- counting_bloom_filter<size_t, 8, BITS_PER_BIN_ONE> bloom;
+BOOST_AUTO_TEST_CASE(insertOverflowExceptionThrown) {
+ counting_bloom_filter<size_t, 8, 2> 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);
+ }
+
+ catch (bin_overflow_exception e) {
+ exception_occurred = true;
+ }
+
+ BOOST_CHECK_EQUAL(exception_occurred, true);
+ BOOST_CHECK_EQUAL(bloom.probably_contains(1), true);
+}
+
+BOOST_AUTO_TEST_CASE(insertUnderflowExceptionThrown) {
+ counting_bloom_filter<size_t, 8, 2> bloom;
+ bool exception_occurred = false;
+
+ try {
+ bloom.remove(1);
+ }
+
+ catch (bin_underflow_exception e) {
+ exception_occurred = true;
+ }
+
+ BOOST_CHECK_EQUAL(exception_occurred, true);
BOOST_CHECK_EQUAL(bloom.probably_contains(1), false);
}
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:01 EDT (Tue, 26 Jul 2011)
@@ -11,7 +11,7 @@
//////////////////////////////////////////////////////////////////////////////
#define BOOST_TEST_DYN_LINK 1
-#define BOOST_TEST_MODULE "Boost Bloom Filter" 1
+#define BOOST_TEST_MODULE "Boost Dynamic Bloom Filter" 1
#include <iostream>
#include <boost/bloom_filter/dynamic_bloom_filter.hpp>
@@ -20,6 +20,7 @@
using boost::bloom_filters::dynamic_bloom_filter;
using boost::bloom_filters::boost_hash;
+using boost::bloom_filters::detail::incompatible_size_exception;
BOOST_AUTO_TEST_CASE(defaultConstructor) {
typedef boost::mpl::vector<
@@ -176,88 +177,98 @@
BOOST_CHECK_EQUAL(bloom.count(), 0ul);
}
-BOOST_AUTO_TEST_CASE(memberSwap) {
- size_t elems[5] = {1,2,3,4,5};
- dynamic_bloom_filter<size_t> bloom1(4, elems, elems+2);
- dynamic_bloom_filter<size_t> bloom2(6, elems+2, elems+5);
+struct SwapFixture {
+ SwapFixture() :
+ bloom1(10, elems, elems+2),
+ bloom2(20, elems+2, elems+5) {}
+
+ dynamic_bloom_filter<size_t> bloom1;
+ dynamic_bloom_filter<size_t> bloom2;
+ size_t elems[5];
+};
+BOOST_FIXTURE_TEST_CASE(memberSwap, SwapFixture) {
bloom1.swap(bloom2);
BOOST_CHECK_EQUAL(bloom1.count(), 3ul);
- BOOST_CHECK_EQUAL(bloom1.bit_capacity(), 6ul);
+ BOOST_CHECK_EQUAL(bloom1.bit_capacity(), 20ul);
BOOST_CHECK_EQUAL(bloom2.count(), 2ul);
- BOOST_CHECK_EQUAL(bloom2.bit_capacity(), 4ul);
+ BOOST_CHECK_EQUAL(bloom2.bit_capacity(), 10ul);
}
-BOOST_AUTO_TEST_CASE(testUnion) {
- dynamic_bloom_filter<size_t> bloom_1(300);
- dynamic_bloom_filter<size_t> bloom_2(300);
- dynamic_bloom_filter<size_t> bloom_union(300);
+BOOST_FIXTURE_TEST_CASE(globalSwap, SwapFixture) {
+ swap(bloom1, bloom2);
- for (size_t i = 0; i < 100; ++i)
- bloom_1.insert(i);
+ BOOST_CHECK_EQUAL(bloom1.count(), 3ul);
+ BOOST_CHECK_EQUAL(bloom2.count(), 2ul);
+}
- for (size_t i = 100; i < 200; ++i)
- bloom_2.insert(i);
+struct PairwiseOpsFixture {
+ PairwiseOpsFixture() :
+ bloom1(100), bloom2(100), bloom_result(100)
+ {
+ }
- bloom_union = bloom_1 | bloom_2;
+ dynamic_bloom_filter<size_t> bloom1;
+ dynamic_bloom_filter<size_t> bloom2;
+ dynamic_bloom_filter<size_t> bloom_result;
+};
- for (size_t i = 0; i < 200; ++i)
- BOOST_CHECK_EQUAL(bloom_union.probably_contains(i), true);
- BOOST_CHECK_GE(bloom_union.count(), bloom_1.count());
- BOOST_CHECK_GE(bloom_union.count(), bloom_2.count());
-}
+BOOST_FIXTURE_TEST_CASE(testUnion, PairwiseOpsFixture) {
+ for (size_t i = 0; i < 50; ++i)
+ bloom1.insert(i);
+
+ for (size_t i = 50; i < 100; ++i)
+ bloom2.insert(i);
-BOOST_AUTO_TEST_CASE(testUnionAssign) {
- dynamic_bloom_filter<size_t> bloom_1(300);
- dynamic_bloom_filter<size_t> bloom_union(300);
+ bloom_result = bloom1 | bloom2;
+ for (size_t i = 0; i < 100; ++i)
+ BOOST_CHECK_EQUAL(bloom_result.probably_contains(i), true);
+
+ BOOST_CHECK_GE(bloom_result.count(), bloom1.count());
+ BOOST_CHECK_GE(bloom_result.count(), bloom2.count());
+}
+
+BOOST_FIXTURE_TEST_CASE(testUnionAssign, PairwiseOpsFixture) {
for (size_t i = 0; i < 100; ++i)
- bloom_1.insert(i);
+ bloom1.insert(i);
- bloom_union |= bloom_1;
+ bloom_result |= bloom1;
for (size_t i = 0; i < 100; ++i)
- BOOST_CHECK_EQUAL(bloom_union.probably_contains(i), true);
- BOOST_CHECK_EQUAL(bloom_union.count(), bloom_1.count());
+ BOOST_CHECK_EQUAL(bloom_result.probably_contains(i), true);
+
+ BOOST_CHECK_EQUAL(bloom_result.count(), bloom1.count());
}
-BOOST_AUTO_TEST_CASE(testIntersect) {
- dynamic_bloom_filter<size_t> bloom_1(300);
- dynamic_bloom_filter<size_t> bloom_2(300);
- dynamic_bloom_filter<size_t> bloom_intersect(300);
-
- // overlap at 100
- for (size_t i = 0; i < 101; ++i)
- bloom_1.insert(i);
+BOOST_FIXTURE_TEST_CASE(testIntersect, PairwiseOpsFixture) {
+ // overlap at 50
+ for (size_t i = 0; i < 51; ++i)
+ bloom1.insert(i);
- for (size_t i = 100; i < 200; ++i)
- bloom_2.insert(i);
+ for (size_t i = 50; i < 100; ++i)
+ bloom2.insert(i);
- bloom_intersect = bloom_1 & bloom_2;
+ bloom_result = bloom1 & bloom2;
- BOOST_CHECK_LE(bloom_intersect.count(), bloom_1.count());
- BOOST_CHECK_LE(bloom_intersect.count(), bloom_2.count());
- BOOST_CHECK_EQUAL(bloom_intersect.probably_contains(100), true);
+ BOOST_CHECK_LE(bloom_result.count(), bloom1.count());
+ BOOST_CHECK_LE(bloom_result.count(), bloom2.count());
+ BOOST_CHECK_LE(bloom_result.count(), 1ul);
+ BOOST_CHECK_EQUAL(bloom_result.probably_contains(50), true);
}
-BOOST_AUTO_TEST_CASE(testIntersectAssign) {
- dynamic_bloom_filter<size_t> bloom_1(300);
- dynamic_bloom_filter<size_t> bloom_intersect(300);
-
+BOOST_FIXTURE_TEST_CASE(testIntersectAssign, PairwiseOpsFixture) {
for (size_t i = 0; i < 100; ++i)
- bloom_1.insert(i);
+ bloom1.insert(i);
- bloom_intersect &= bloom_1;
+ bloom_result &= bloom1;
for (size_t i = 0; i < 100; ++i)
- BOOST_CHECK_EQUAL(bloom_intersect.probably_contains(i), false);
+ BOOST_CHECK_EQUAL(bloom_result.probably_contains(i), false);
}
-BOOST_AUTO_TEST_CASE(equalityOperator) {
- dynamic_bloom_filter<int> bloom1(8);
- dynamic_bloom_filter<int> bloom2(8);
-
+BOOST_FIXTURE_TEST_CASE(equalityOperator, PairwiseOpsFixture) {
BOOST_CHECK_EQUAL(bloom1 == bloom2, true);
bloom1.insert(1);
BOOST_CHECK_EQUAL(bloom1 == bloom2, false);
@@ -265,10 +276,7 @@
BOOST_CHECK_EQUAL(bloom1 == bloom2, true);
}
-BOOST_AUTO_TEST_CASE(inequalityOperator) {
- dynamic_bloom_filter<int> bloom1(8);
- dynamic_bloom_filter<int> bloom2(8);
-
+BOOST_FIXTURE_TEST_CASE(inequalityOperator, PairwiseOpsFixture) {
BOOST_CHECK_EQUAL(bloom1 != bloom2, false);
bloom1.insert(1);
BOOST_CHECK_EQUAL(bloom1 != bloom2, true);
@@ -276,14 +284,47 @@
BOOST_CHECK_EQUAL(bloom1 != bloom2, false);
}
-BOOST_AUTO_TEST_CASE(globalSwap) {
- size_t elems[5] = {1,2,3,4,5};
- dynamic_bloom_filter<size_t> bloom1(8, elems, elems+2);
- dynamic_bloom_filter<size_t> bloom2(8, elems+2, elems+5);
+struct IncompatibleSizeFixture {
+ IncompatibleSizeFixture() :
+ bloom1(100), bloom2(101), exception_thrown(false)
+ {}
+
+ dynamic_bloom_filter<size_t> bloom1;
+ dynamic_bloom_filter<size_t> bloom2;
+ dynamic_bloom_filter<size_t> bloom3;
+ bool exception_thrown;
+};
+
+BOOST_FIXTURE_TEST_CASE(_intersectException, IncompatibleSizeFixture) {
+ try {
+ bloom3 = bloom1 & bloom2;
+ }
+ catch (incompatible_size_exception e) {
+ exception_thrown = true;
+ }
- swap(bloom1, bloom2);
+ BOOST_CHECK_EQUAL(exception_thrown, true);
+}
- BOOST_CHECK_EQUAL(bloom1.count(), 3ul);
- BOOST_CHECK_EQUAL(bloom2.count(), 2ul);
+BOOST_FIXTURE_TEST_CASE(_unionException, IncompatibleSizeFixture) {
+ try {
+ bloom3 = bloom1 | bloom2;
+ }
+ catch (incompatible_size_exception e) {
+ exception_thrown = true;
+ }
+
+ BOOST_CHECK_EQUAL(exception_thrown, true);
}
+BOOST_FIXTURE_TEST_CASE(_equalityException, IncompatibleSizeFixture) {
+ try {
+ if (bloom1 == bloom2)
+ exception_thrown = false;
+ }
+ catch (incompatible_size_exception e) {
+ exception_thrown = true;
+ }
+
+ BOOST_CHECK_EQUAL(exception_thrown, true);
+}
Deleted: sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom_intersect-fail.cpp
==============================================================================
--- sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom_intersect-fail.cpp 2011-07-26 17:26:01 EDT (Tue, 26 Jul 2011)
+++ (empty file)
@@ -1,29 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-//
-// (C) Copyright Alejandro Cabrera 2011.
-// Distributed under the Boost
-// Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or
-// copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-// See http://www.boost.org/libs/bloom_filter for documentation.
-//
-//////////////////////////////////////////////////////////////////////////////
-
-#define BOOST_TEST_DYN_LINK 1
-#define BOOST_TEST_MODULE "Boost Bloom Filter" 1
-
-#include <boost/bloom_filter/dynamic_bloom_filter.hpp>
-#include <boost/test/unit_test.hpp>
-
-using boost::bloom_filters::dynamic_bloom_filter;
-using boost::bloom_filters::boost_hash;
-
-BOOST_AUTO_TEST_CASE(testIntersectFailDifferentSize) {
- dynamic_bloom_filter<size_t> bloom_1(300);
- dynamic_bloom_filter<size_t> bloom_2(299);
- dynamic_bloom_filter<size_t> bloom_union(300);
-
- bloom_union = bloom_1 & bloom_2;
-}
-
Deleted: sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom_union-fail.cpp
==============================================================================
--- sandbox/bloom_filter/trunk/libs/bloom_filter/test/dynamic_bloom_union-fail.cpp 2011-07-26 17:26:01 EDT (Tue, 26 Jul 2011)
+++ (empty file)
@@ -1,29 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-//
-// (C) Copyright Alejandro Cabrera 2011.
-// Distributed under the Boost
-// Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or
-// copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-// See http://www.boost.org/libs/bloom_filter for documentation.
-//
-//////////////////////////////////////////////////////////////////////////////
-
-#define BOOST_TEST_DYN_LINK 1
-#define BOOST_TEST_MODULE "Boost Bloom Filter" 1
-
-#include <boost/bloom_filter/dynamic_bloom_filter.hpp>
-#include <boost/test/unit_test.hpp>
-
-using boost::bloom_filters::dynamic_bloom_filter;
-using boost::bloom_filters::boost_hash;
-
-BOOST_AUTO_TEST_CASE(testUnionFailDifferentSize) {
- dynamic_bloom_filter<size_t> bloom_1(300);
- dynamic_bloom_filter<size_t> bloom_2(299);
- dynamic_bloom_filter<size_t> bloom_union(300);
-
- bloom_union = bloom_1 | bloom_2;
-}
-
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