-
Notifications
You must be signed in to change notification settings - Fork 1
/
runetrie_test.go
74 lines (67 loc) · 1.52 KB
/
runetrie_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
package hairetsu
import (
"testing"
"github.com/ajiyoshi-vg/hairetsu/codec/composer"
"github.com/ajiyoshi-vg/hairetsu/codec/runes"
"github.com/ajiyoshi-vg/hairetsu/node"
"github.com/stretchr/testify/assert"
)
func TestRuneTrieSearch(t *testing.T) {
cases := []struct {
title string
data []string
ng []string
prefix string
num int
}{
{
title: "インドネシア",
ng: []string{
("hoge"),
("印"),
},
prefix: ("印度尼西亚啊"),
num: 2,
data: []string{
("印度"),
("印度尼西亚"),
("印加帝国"),
("瑞士"),
("瑞典"),
("巴基斯坦"),
("巴勒斯坦"),
("以色列"),
("巴比伦"),
("土耳其"),
},
},
}
for _, c := range cases {
t.Run(c.title, func(t *testing.T) {
encs := map[string]composer.Composable[string]{
"rune-id": composer.NewRunes(runes.NewIdentityDict()),
"rune-map": composer.NewRunes(runes.NewMapDict()),
}
for name, enc := range encs {
t.Run(name, func(t *testing.T) {
x, err := enc.ComposeFromSlice(c.data)
assert.NoError(t, err)
da := x.Searcher()
for i, x := range c.data {
actual, err := da.ExactMatchSearch(x)
assert.NoError(t, err, x)
assert.Equal(t, node.Index(i), actual)
}
for _, x := range c.ng {
_, err := da.ExactMatchSearch(x)
assert.Error(t, err, x)
}
is, err := da.CommonPrefixSearch(c.prefix)
assert.NoError(t, err)
assert.Equal(t, c.num, len(is))
t.Log(x.Stat())
})
}
})
}
}