-
Notifications
You must be signed in to change notification settings - Fork 2
/
bloom_filter_test.h
50 lines (35 loc) · 1.22 KB
/
bloom_filter_test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef BLOOM_FILTER_TEST_H_
#define BLOOM_FILTER_TEST_H_
#include "bloom_filter.h"
#include <gtest/gtest.h>
namespace pil {
TEST(BloomFilterTests, InsertFind) {
BlockSplitBloomFilter b;
uint32_t optimal = b.OptimalNumOfBits(1000, 0.05);
b.Init(optimal);
std::vector<uint32_t> vals = {12, 21, 191, 1024};
for(int i = 0; i < vals.size(); ++i) {
uint64_t hash = b.Hash(vals[i]);
b.InsertHash(hash);
}
for(int i = 0; i < vals.size(); ++i) {
ASSERT_EQ(true, b.FindHash(b.Hash(vals[i])));
}
}
TEST(BloomFilterTests, InsertFindString) {
BlockSplitBloomFilter b;
uint32_t optimal = b.OptimalNumOfBits(1000, 0.05);
b.Init(optimal);
std::vector<std::string> vals = {"john doe", "bananman", "superman", "johnsson", "dawn", "sun"};
for(int i = 0; i < vals.size(); ++i) {
uint64_t hash = b.Hash(&vals[i][0], vals[i].size());
b.InsertHash(hash);
}
for(int i = 0; i < vals.size(); ++i) {
ASSERT_EQ(true, b.FindHash(b.Hash(&vals[i][0], vals[i].size())));
}
std::string fake = "i should not be found on average even by pure chance";
ASSERT_EQ(false, b.FindHash(b.Hash(&fake[0], fake.size())));
}
}
#endif /* BLOOM_FILTER_TEST_H_ */