-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathdarts_test.go
53 lines (47 loc) · 1.27 KB
/
darts_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
package darts
import(
"testing"
"bufio"
"strings"
"strconv"
"time"
"os"
)
func TestExactMatchSearch(t *testing.T) {
_, err := Import("darts.txt", "darts.lib", false)
if err != nil {
t.Errorf("Test fail")
}
}
func TestPerf(t *testing.T) {
inFile := "d.txt"
unifile, erri := os.Open(inFile)
if erri != nil{
t.Error(erri)
}
defer unifile.Close()
d, _ := Load("darts.lib")
dartsKeys := make(dartsKeySlice, 0, 130000)
uniLineReader := bufio.NewReaderSize(unifile, 400)
line, _, bufErr := uniLineReader.ReadLine()
for nil == bufErr {
rst := strings.Split(string(line), "\t")
key := []rune /*Key_type*/(rst[0])
value, _ := strconv.Atoi(rst[1])
dartsKeys = append(dartsKeys, dartsKey{key, value})
line, _, bufErr = uniLineReader.ReadLine()
}
keys := make([][]rune /*Key_type*/, len(dartsKeys))
for i := 0; i < len(dartsKeys); i++ {
keys[i] = dartsKeys[i].key
}
t.Logf("input dict length: %v\n", len(keys))
tm := time.Now()
for i := 0; i < len(keys); i++ {
if true != d.ExactMatchSearch(keys[i], 0) {
t.Errorf("missing key %s, %v, %d", string(keys[i]), keys[i], i)
return
}
}
t.Log(time.Since(tm))
}