-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbloomfilter_test.v
52 lines (39 loc) · 1.03 KB
/
bloomfilter_test.v
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
51
52
module bloomfilter
import crypto.sha256
import crypto.sha512
fn test_clange_algorithms() {
mut filter := new()
// Remove old hash functions and clear the filter
filter.reset_hash_functions()
filter.add_hash_functions(sha256.hexhash, sha512.hexhash)
assert filter.check('Apple') == false
filter.add('Apple')
assert filter.check('Apple') == true
}
fn test_is_empty() {
mut filter := new()
assert filter.is_empty() == true
filter.add('Ok')
assert filter.is_empty() == false
}
fn test_clear() {
mut filter := new()
assert filter.check('Ok') == false
filter.add('Ok')
assert filter.check('Ok') == true
filter.clear()
assert filter.check('Ok') == false
}
fn reset_hash_function() {
mut filter := new()
assert filter.check('Ok') == false
filter.add('Ok')
filter.reset_hash_functions()
assert filter.check('Ok') == false
filter.add('12')
// Not recommended - High probability of colisions if multiple types are
// used
assert filter.check('12') == true
assert filter.check('123') == false
assert filter.check(12) == false
}