forked from huichen/sego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.go
64 lines (56 loc) · 1.21 KB
/
test_utils.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
package sego
import (
"fmt"
"testing"
)
func expect(t *testing.T, expect string, actual interface{}) {
actualString := fmt.Sprint(actual)
if expect != actualString {
t.Errorf("期待值=\"%s\", 实际=\"%s\"", expect, actualString)
}
}
func printNodes(nodes []*node) (output string) {
for _, node := range nodes {
output += fmt.Sprintf("%s ", node.word)
}
return
}
func getNodeString(node *node) string {
output := string(node.word)
if node.token != nil {
output += "."
}
if node.children != nil {
output += "("
for _, c := range node.children {
output += getNodeString(c) + " "
}
output += ")"
}
return output
}
func printDictionary(dict *Dictionary) string {
return fmt.Sprint(getNodeString(&dict.root))
}
func printTokens(tokens []*Token, numTokens int) (output string) {
for iToken := 0; iToken < numTokens; iToken++ {
for _, word := range tokens[iToken].text {
output += fmt.Sprint(string(word))
}
output += " "
}
return
}
func toWords(strings ...string) []Text {
words := []Text{}
for _, s := range strings {
words = append(words, []byte(s))
}
return words
}
func bytesToString(bytes []Text) (output string) {
for _, b := range bytes {
output += (string(b) + "/")
}
return
}