-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsave_test.go
More file actions
35 lines (27 loc) · 797 Bytes
/
save_test.go
File metadata and controls
35 lines (27 loc) · 797 Bytes
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
package spellchecker
import (
"os"
"path"
"testing"
"github.com/stretchr/testify/require"
)
func Test_Spellchecker_Save(t *testing.T) {
m1 := newSampleSpellchecker()
filePath := path.Join(t.TempDir(), "spellchecker.bin")
file, err := os.Create(filePath)
require.NoError(t, err)
err = m1.Save(file)
require.NoError(t, err)
err = file.Close()
require.NoError(t, err)
file, err = os.Open(filePath)
require.NoError(t, err)
m2, err := Load(file)
require.NoError(t, err)
require.EqualValues(t, m1.dict.id("green"), m2.dict.id("green"))
require.EqualValues(t, m1.dict.nextID(), m2.dict.nextID())
matches := m2.dict.find("orange", 1, 2, defaultFilterFunc(2))
require.Len(t, matches, 1)
require.Equal(t, matches[0].Value, "orange")
require.Greater(t, matches[0].Score, 0.0)
}