forked from tylertreat/BoomFilters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminhash_test.go
48 lines (39 loc) · 801 Bytes
/
minhash_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
package boom
import (
"strconv"
"testing"
)
// Ensures that MinHash returns the correct similarity ratio.
func TestMinHash(t *testing.T) {
bag := []string{
"bob",
"alice",
"frank",
"tyler",
"sara",
}
if s := MinHash(bag, bag); s != 1 {
t.Errorf("expected 1, got %f", s)
}
dict := dictionary(1000)
bag2 := []string{}
for i := 0; i < 1000; i++ {
bag = append(bag2, strconv.Itoa(i))
}
if s := MinHash(dict, bag2); s != 0 {
t.Errorf("Expected 0, got %f", s)
}
bag2 = dictionary(500)
if s := MinHash(dict, bag2); s > 0.7 || s < 0.5 {
t.Errorf("Expected between 0.5 and 0.7, got %f", s)
}
}
func BenchmarkMinHash(b *testing.B) {
b.StopTimer()
bag1 := dictionary(500)
bag2 := dictionary(300)
b.StartTimer()
for n := 0; n < b.N; n++ {
MinHash(bag1, bag2)
}
}