-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathn-gram_test.go
68 lines (60 loc) · 1.29 KB
/
n-gram_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
package muzzy_test
import (
"io/ioutil"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/suite"
"github.com/vporoshok/muzzy"
)
type SplitIndexSuite struct {
suite.Suite
index *muzzy.SplitIndex
}
func (s *SplitIndexSuite) SetupSuite() {
corpus, err := ioutil.ReadFile(filepath.Join("testdata", "dead_souls.txt"))
s.Require().NoError(err)
lines := strings.Split(string(corpus), "\n")
splitter := muzzy.NGramSplitter(3, true)
s.index = muzzy.NewSplitIndex(splitter)
s.index.Add(lines...)
}
func (s *SplitIndexSuite) Test() {
cases := [...]struct {
name string
search string
nearest string
}{
{
"exactly",
`"Что ж барин? у себя, что ли?"`,
`"Что ж барин? у себя, что ли?"`,
},
{
"misstype",
`"Что ж баирн? у себя, что ли?"`,
`"Что ж барин? у себя, что ли?"`,
},
{
"substring",
`Что ж барин? у себя?`,
`"Что ж барин? у себя, что ли?"`,
},
{
"not found",
"not found",
"",
},
}
// nolint:gocritic
for _, c := range cases {
c := c
s.Run(c.name, func() {
i := s.index.Search(c.search)
s.Equal(c.nearest, s.index.Get(i))
})
}
}
func TestSplitIndex(t *testing.T) {
suite.Run(t, new(SplitIndexSuite))
}