Changeset View
Changeset View
Standalone View
Standalone View
src/test/bloom_tests.cpp
Show First 20 Lines • Show All 1,118 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(rolling_bloom) { | ||||
// when we've inserted one minus an integer multiple of nElement*2. | // when we've inserted one minus an integer multiple of nElement*2. | ||||
unsigned int nHits = 0; | unsigned int nHits = 0; | ||||
for (int i = 0; i < 10000; i++) { | for (int i = 0; i < 10000; i++) { | ||||
if (rb1.contains(RandomData())) { | if (rb1.contains(RandomData())) { | ||||
++nHits; | ++nHits; | ||||
} | } | ||||
} | } | ||||
// Expect about 100 hits | // Expect about 100 hits | ||||
BOOST_CHECK_EQUAL(nHits, 75); | BOOST_CHECK_EQUAL(nHits, 75U); | ||||
BOOST_CHECK(rb1.contains(data[DATASIZE - 1])); | BOOST_CHECK(rb1.contains(data[DATASIZE - 1])); | ||||
rb1.reset(); | rb1.reset(); | ||||
BOOST_CHECK(!rb1.contains(data[DATASIZE - 1])); | BOOST_CHECK(!rb1.contains(data[DATASIZE - 1])); | ||||
// Now roll through data, make sure last 100 entries | // Now roll through data, make sure last 100 entries | ||||
// are always remembered: | // are always remembered: | ||||
for (int i = 0; i < DATASIZE; i++) { | for (int i = 0; i < DATASIZE; i++) { | ||||
Show All 13 Lines | BOOST_AUTO_TEST_CASE(rolling_bloom) { | ||||
// Sanity check to make sure the filter isn't just filling up: | // Sanity check to make sure the filter isn't just filling up: | ||||
nHits = 0; | nHits = 0; | ||||
for (int i = 0; i < DATASIZE; i++) { | for (int i = 0; i < DATASIZE; i++) { | ||||
if (rb1.contains(data[i])) { | if (rb1.contains(data[i])) { | ||||
++nHits; | ++nHits; | ||||
} | } | ||||
} | } | ||||
// Expect about 5 false positives | // Expect about 5 false positives | ||||
BOOST_CHECK_EQUAL(nHits, 6); | BOOST_CHECK_EQUAL(nHits, 6U); | ||||
// last-1000-entry, 0.01% false positive: | // last-1000-entry, 0.01% false positive: | ||||
CRollingBloomFilter rb2(1000, 0.001); | CRollingBloomFilter rb2(1000, 0.001); | ||||
for (int i = 0; i < DATASIZE; i++) { | for (int i = 0; i < DATASIZE; i++) { | ||||
rb2.insert(data[i]); | rb2.insert(data[i]); | ||||
} | } | ||||
// ... room for all of them: | // ... room for all of them: | ||||
for (int i = 0; i < DATASIZE; i++) { | for (int i = 0; i < DATASIZE; i++) { | ||||
BOOST_CHECK(rb2.contains(data[i])); | BOOST_CHECK(rb2.contains(data[i])); | ||||
} | } | ||||
g_mock_deterministic_tests = false; | g_mock_deterministic_tests = false; | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |