-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathstrsim_test.go
71 lines (64 loc) · 1.43 KB
/
strsim_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
package strsim
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_Compare_Special(t *testing.T) {
for _, v := range []testCase{
{arg1: "", arg2: "", sim: 1},
{arg1: "1", arg2: "", sim: 0},
{arg1: "", arg2: "1", sim: 0},
} {
for _, o := range []Option{
Default(),
Jaro(),
DiceCoefficient(1),
Hamming(),
Simhash(),
Cosine(),
JaroWinkler(),
} {
sim := Compare(v.arg1, v.arg2, o)
assert.Equal(t, v.sim, sim)
}
}
}
type bestTest struct {
best []string
key string
need string
}
func Test_FindBestMatchOne(t *testing.T) {
for _, d := range []bestTest{
{best: []string{"朝辞白帝彩云间", "千里江陵一日还", "两岸猿声啼不住", "轻舟已过万重山"}, key: "千里还", need: "千里江陵一日还"},
} {
for _, o := range []Option{
DiceCoefficient(1),
Jaro(),
Default(),
Simhash(),
Cosine(),
JaroWinkler(),
} {
m := FindBestMatchOne(d.key, d.best, o)
assert.Equal(t, m.S, d.need)
}
}
}
func Test_FindBestMatch(t *testing.T) {
for _, d := range []bestTest{
{best: []string{"朝辞白帝彩云间", "千里江陵一日还", "两岸猿声啼不住", "轻舟已过万重山"}, key: "千里还", need: "千里江陵一日还"},
} {
for _, o := range []Option{
DiceCoefficient(1),
Jaro(),
Default(),
Simhash(),
Cosine(),
JaroWinkler(),
} {
m := FindBestMatch(d.key, d.best, o)
assert.Equal(t, m.Match.S, d.need)
}
}
}