-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbf_add_test.v
119 lines (94 loc) · 1.99 KB
/
bf_add_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module bloomfilter
fn test_add_elements() {
mut filter := new()
filter.add('Apple')
filter.add('True')
filter.add('False')
assert filter.check('Apple') == true
assert filter.check('True') == true
assert filter.check('False') == true
assert filter.check('Toast') == false
}
fn test_add_nothing() {
mut filter := new()
assert filter.check('Apple') == false
assert filter.check('True') == false
assert filter.check('False') == false
assert filter.check('Toast') == false
}
fn test_multiple_types() {
mut filter := new()
filter.add('Apple')
filter.add(12)
filter.add(`a`)
assert filter.check('Apple') == true
assert filter.check(12) == true
assert filter.check(`a`) == true
assert filter.check('43') == false
assert filter.check('Appleeeeeeee') == false
}
fn test_add_same() {
mut filter := new()
filter.add('Apple')
filter.add('Apple')
assert filter.check('Apple') == true
}
fn test_add_empty_string() {
mut filter := new()
assert filter.check('') == false
filter.add('')
assert filter.check('')
}
fn test_add_non_ascii() {
mut filter := new()
filter.add('éàéàéà')
assert filter.check('éàéàé') == false
assert filter.check('éàéàéà') == true
}
fn test_add_emoji() {
mut filter := new()
filter.add('😊')
assert filter.check('😊!') == false
assert filter.check('😊') == true
}
fn test_loop() {
mut filter := new()
for i in 0 .. 10 {
filter.add('${i}')
}
for i in 0 .. 10 {
assert filter.check('${i}')
}
}
fn test_loop_multiple_types() {
mut filter := new()
for i in 0 .. 10 {
if i & 1 == 0 {
filter.add('${i}')
} else {
filter.add(i)
}
}
for i in 0 .. 10 {
if i & 1 == 0 {
assert filter.check('${i}')
} else {
assert filter.check(i)
}
}
}
fn test_add_longstring() {
mut str := ''
mut filter := new()
for _ in 0 .. 1024 {
str += 'No'
}
filter.add(str)
assert filter.check(str)
}
fn test_add_hex() {
mut filter := new()
filter.add(0xff12)
assert filter.check(0xff10) == false
assert filter.check(0xff12) == true
}