-
Notifications
You must be signed in to change notification settings - Fork 0
/
deduper_test.go
61 lines (46 loc) · 1.03 KB
/
deduper_test.go
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
package revregex
import (
"fmt"
"math/rand"
"testing"
"time"
)
func TestDedupMap(t *testing.T) {
d := NewDedupMap()
for i := 0; i < 10_000; i++ {
if !d.Unique(fmt.Sprint(i)) {
t.Fatal(i, "expecetd to be unique")
}
}
for i := 0; i < 10_000; i++ {
if d.Unique(fmt.Sprint(i)) {
t.Fatal(i, "expected NOT to be unique")
}
}
}
func TestDedupBloom(t *testing.T) {
d := NewDedupBloom(DefaultBloomSize)
salt := "kjhs sklhqskdhmlqsjfl!k"
for i := 0; i < 5_000_000; i++ {
if !d.Unique(fmt.Sprint(i, salt)) {
t.Fatal(i, "expected to be unique - false positive !")
}
}
for i := 0; i < 5_000_000; i++ {
if d.Unique(fmt.Sprint(i, salt)) {
t.Fatal(i, "expected NOT to be unique")
}
}
}
func TestDedupConstistentency(t *testing.T) {
d1 := NewDedupBloom(DefaultBloomSize)
d2 := NewDedupMap()
rd := rand.New(rand.NewSource(time.Now().Unix()))
for i := 1; i < 1_000_000; i++ {
k := rd.Int()
ks := fmt.Sprint(k)
if d1.Unique(ks) != d2.Unique(ks) {
t.Fatalf("inconsistent after %d rounds ", i)
}
}
}