-
Notifications
You must be signed in to change notification settings - Fork 7
/
lib_test.go
87 lines (71 loc) · 1.69 KB
/
lib_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
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
package dejavu
import (
"crypto/rand"
"testing"
)
func TestDeterministic(t *testing.T) {
d := New(false, 3, 0.0)
// add entries
if d.Witness([]byte("foo")) {
t.Errorf("Incorrect déjà vu: 'foo'!")
}
if d.Witness([]byte("bar")) {
t.Errorf("Incorrect déjà vu: 'bar'!")
}
// remembers entry
if !d.Witness([]byte("bar")) {
t.Errorf("Expected déjà vu: 'bar'!")
}
// remembers oldest entry before overwriting
if !d.Witness([]byte("foo")) {
t.Errorf("Expected déjà vu: 'foo'!")
}
// add entries
if d.Witness([]byte("bam")) {
t.Errorf("Incorrect déjà vu: 'bam'!")
}
if d.Witness([]byte("baz")) {
t.Errorf("Incorrect déjà vu: 'baz'!")
}
// forgot oldest
if d.Witness([]byte("bar")) {
t.Errorf("Incorrect déjà vu: 'bar'!")
}
}
func TestProbabilistic(t *testing.T) {
d := New(true, 1024, 0.000001)
// add entries
if d.Witness([]byte("foo")) {
t.Errorf("Incorrect déjà vu: 'foo'!")
}
if d.Witness([]byte("bar")) {
t.Errorf("Incorrect déjà vu: 'bar'!")
}
// remembers entry
if !d.Witness([]byte("foo")) {
t.Errorf("Expected déjà vu: 'foo'!")
}
// fill memory
for i := 0; i < 2048; i++ {
d.Witness([]byte("data"))
}
// forgot oldest
if d.Witness([]byte("bar")) {
t.Errorf("Incorrect déjà vu: 'bar'!")
}
}
func TestProbabilisticLoad(t *testing.T) {
d := NewProbabilistic(65536, 0.00000001)
for i := 0; i < 65536; i++ {
data := make([]byte, 20, 20)
rand.Read(data)
if d.Witness(data) {
t.Errorf("Unexpected dejavu: %#X", data)
}
}
}
func TestProcess(t *testing.T) {
// TODO compare know test input files to expected output file
d := NewProbabilistic(65536, 0.00000001)
ProcessPaths(d, true, "/dev/null", "LICENSE", "README.md")
}