Skip to content

Commit 8b86cf1

Browse files
authored
Merge pull request #445 from apache/bf_test_fix
fix seed for bloom filter test where we use probabilistic bounds
2 parents fa1ba4f + c020e8f commit 8b86cf1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

filters/test/bloom_filter_test.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ TEST_CASE("bloom_filter: standard constructors", "[bloom_filter]") {
7979
TEST_CASE("bloom_filter: basic operations", "[bloom_filter]") {
8080
uint64_t num_items = 5000;
8181
double fpp = 0.01;
82+
uint64_t seed = 4897301548054ULL;
8283

83-
auto bf = bloom_filter::builder::create_by_accuracy(num_items, fpp);
84+
auto bf = bloom_filter::builder::create_by_accuracy(num_items, fpp, seed);
8485
REQUIRE(bf.is_empty());
8586
REQUIRE(bf.get_bits_used() == 0);
8687

@@ -90,16 +91,20 @@ TEST_CASE("bloom_filter: basic operations", "[bloom_filter]") {
9091

9192
REQUIRE(!bf.is_empty());
9293
// filter is about 50% full at target capacity
93-
REQUIRE(bf.get_bits_used() == Approx(0.5 * bf.get_capacity()).epsilon(0.05));
94+
// since seed is fixed we expect an exact value every time
95+
// but leaving the approximate test in since that's more the "expectation"
96+
REQUIRE(bf.get_bits_used() == 24793); // exact value is not important but should be consistent
97+
REQUIRE(bf.get_bits_used() == Approx(0.5 * bf.get_capacity()).epsilon(0.05)); // just over 3.3% in practice
9498

9599
uint32_t num_found = 0;
96100
for (uint64_t i = num_items; i < bf.get_capacity(); ++i) {
97101
if (bf.query(i)) {
98102
++num_found;
99103
}
100104
}
101-
// fpp is average with significant variance
102-
REQUIRE(num_found == Approx((bf.get_capacity() - num_items) * fpp).epsilon(0.12));
105+
// fpp is average with significant variance -- even at 12% it would fail occasionally
106+
REQUIRE(num_found == 423);
107+
//REQUIRE(num_found == Approx((bf.get_capacity() - num_items) * fpp).epsilon(0.12));
103108
auto bytes = bf.serialize();
104109

105110
// initialize in memory and run the same tests

0 commit comments

Comments
 (0)