-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathterms_test.go
49 lines (42 loc) · 935 Bytes
/
terms_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
package indexer
import (
"os"
"testing"
"github.com/stretchr/testify/require"
)
func TestTermDict(t *testing.T) {
var err error
var td *TermDict
var td2 *TermDict
//TESTCASE: query and insert term to an empty dict
if err = os.Remove("/tmp/terms"); err != nil && !os.IsNotExist(err) {
t.Fatalf("%+v", err)
}
td, err = NewTermDict("/tmp", true)
require.NoError(t, err)
terms := []string{
"sunday",
"mon",
"tue",
"wen",
"thurs",
"friday",
"satur",
}
expIds := []uint64{0, 1, 2, 3, 4, 5, 6}
ids, err := td.CreateTermsIfNotExist(terms)
require.NoError(t, err)
require.Equal(t, expIds, ids)
//TESTCASE: query and insert term to an existing dict
td2, err = NewTermDict("/tmp", false)
require.NoError(t, err)
terms = []string{
"friday",
"wikepedia",
"thurs",
}
expIds = []uint64{5, 7, 4}
ids, err = td2.CreateTermsIfNotExist(terms)
require.NoError(t, err)
require.Equal(t, expIds, ids)
}