|
|
@ -461,6 +461,9 @@ static std::vector<unsigned char> RandomData()
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(rolling_bloom)
|
|
|
|
BOOST_AUTO_TEST_CASE(rolling_bloom)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
SeedInsecureRand(/* deterministic */ true);
|
|
|
|
|
|
|
|
g_mock_deterministic_tests = true;
|
|
|
|
|
|
|
|
|
|
|
|
// last-100-entry, 1% false positive:
|
|
|
|
// last-100-entry, 1% false positive:
|
|
|
|
CRollingBloomFilter rb1(100, 0.01);
|
|
|
|
CRollingBloomFilter rb1(100, 0.01);
|
|
|
|
|
|
|
|
|
|
|
@ -485,12 +488,8 @@ BOOST_AUTO_TEST_CASE(rolling_bloom)
|
|
|
|
if (rb1.contains(RandomData()))
|
|
|
|
if (rb1.contains(RandomData()))
|
|
|
|
++nHits;
|
|
|
|
++nHits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Run test_bitcoin with --log_level=message to see BOOST_TEST_MESSAGEs:
|
|
|
|
// Expect about 100 hits
|
|
|
|
BOOST_TEST_MESSAGE("RollingBloomFilter got " << nHits << " false positives (~100 expected)");
|
|
|
|
BOOST_CHECK_EQUAL(nHits, 75);
|
|
|
|
|
|
|
|
|
|
|
|
// Insanely unlikely to get a fp count outside this range:
|
|
|
|
|
|
|
|
BOOST_CHECK(nHits > 25);
|
|
|
|
|
|
|
|
BOOST_CHECK(nHits < 175);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_CHECK(rb1.contains(data[DATASIZE-1]));
|
|
|
|
BOOST_CHECK(rb1.contains(data[DATASIZE-1]));
|
|
|
|
rb1.reset();
|
|
|
|
rb1.reset();
|
|
|
@ -517,10 +516,8 @@ BOOST_AUTO_TEST_CASE(rolling_bloom)
|
|
|
|
if (rb1.contains(data[i]))
|
|
|
|
if (rb1.contains(data[i]))
|
|
|
|
++nHits;
|
|
|
|
++nHits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Expect about 5 false positives, more than 100 means
|
|
|
|
// Expect about 5 false positives
|
|
|
|
// something is definitely broken.
|
|
|
|
BOOST_CHECK_EQUAL(nHits, 6);
|
|
|
|
BOOST_TEST_MESSAGE("RollingBloomFilter got " << nHits << " false positives (~5 expected)");
|
|
|
|
|
|
|
|
BOOST_CHECK(nHits < 100);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// last-1000-entry, 0.01% false positive:
|
|
|
|
// last-1000-entry, 0.01% false positive:
|
|
|
|
CRollingBloomFilter rb2(1000, 0.001);
|
|
|
|
CRollingBloomFilter rb2(1000, 0.001);
|
|
|
@ -531,6 +528,7 @@ BOOST_AUTO_TEST_CASE(rolling_bloom)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|
|
|
|