-
Notifications
You must be signed in to change notification settings - Fork 1
/
dict_test.go
61 lines (52 loc) · 1.02 KB
/
dict_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
package fate
import (
"reflect"
"testing"
)
func TestDict(t *testing.T) {
var tests = []struct {
strs []string
q string
expected token
}{
{[]string{}, "foo", 0},
{[]string{"foo"}, "foo", 0},
{[]string{"foo"}, "bar", 1},
}
for ti, tt := range tests {
d := newDict()
for _, str := range tt.strs {
d.ID(str)
}
res := d.ID(tt.q)
if res != tt.expected {
t.Errorf("[%d] Id(%q) => %d, want %d", ti, tt.q, res, tt.expected)
}
}
}
func toks(toks ...token) *tokset {
ts := &tokset{}
for _, tok := range toks {
ts.Add(tok)
}
return ts
}
func TestSyndict(t *testing.T) {
var tests = []struct {
strs []string
query string
expected *tokset
}{
{[]string{"foo", "Foo", "bar", "baz"}, "FOO", toks(0, 1)},
}
for ti, tt := range tests {
d := newSyndict(DefaultStemmer)
for _, str := range tt.strs {
d.ID(str)
}
res := d.Syns(tt.query)
if !reflect.DeepEqual(res, tt.expected.Tokens()) {
t.Errorf("[%d] Get(%q) => %d, want %d", ti, tt.query, res, tt.expected)
}
}
}