-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcedar_test.go
43 lines (40 loc) · 896 Bytes
/
cedar_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
package cedar
import (
"fmt"
"testing"
)
func TestInsertInt(t *testing.T) {
fmt.Printf("\ntesting int type value...\n")
cd := NewCedar()
words := []string{
"she", "hers", "her", "he",
}
for i, word := range words {
cd.Insert([]byte(word), i)
}
ids := cd.PrefixMatch([]byte("hers"), 0)
for _, id := range ids {
k, _ := cd.Key(id)
v, _ := cd.Get(k)
fmt.Printf("key:%s val:%d\n", string(k), v.(int))
}
cd.DumpGraph("datrie.gv")
}
func TestInsertFloat(t *testing.T) {
fmt.Printf("\ntesting int float32 value...\n")
cd := NewCedar()
words := []string{
"she", "hers", "her", "he",
}
for i, word := range words {
v := float32(i) + 1.880001
cd.Insert([]byte(word), v)
}
ids := cd.PrefixMatch([]byte("hers"), 0)
for _, id := range ids {
k, _ := cd.Key(id)
v, _ := cd.Get(k)
fmt.Printf("key:%s val:%f\n", string(k), v.(float32))
}
cd.DumpGraph("datrie.gv")
}