-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathforest_test.go
50 lines (45 loc) · 1011 Bytes
/
forest_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
package lsh
import (
"strconv"
"testing"
)
func Test_NewLshForest(t *testing.T) {
lsh := NewLshForest(5, 5, 100, 5.0)
if len(lsh.trees) != 5 {
t.Error("Lsh init fail")
}
}
func Test_LshForestInsert(t *testing.T) {
lsh := NewLshForest(100, 5, 5, 5.0)
points := randomPoints(10, 100, 32.0)
for i, p := range points {
lsh.Insert(p, strconv.Itoa(i))
}
for _, trees := range lsh.trees {
if trees.count == 0 {
t.Error("Insert fail")
}
}
}
func Test_LshForestQuery(t *testing.T) {
lsh := NewLshForest(100, 5, 5, 5.0)
points := randomPoints(10, 100, 32.0)
insertedKeys := make([]string, 10)
for i, p := range points {
lsh.Insert(p, strconv.Itoa(i))
insertedKeys[i] = strconv.Itoa(i)
}
// Use the inserted points as queries, and
// verify that we can get back each query itself
for i, key := range insertedKeys {
found := false
for _, foundKey := range lsh.Query(points[i], 5) {
if foundKey == key {
found = true
}
}
if !found {
t.Error("Query fail")
}
}
}