-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpp_test.go
83 lines (76 loc) · 2.22 KB
/
pp_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package macomp
import (
"fmt"
"testing"
"github.com/fatih/color"
)
func TestDecorateSurfaces(t *testing.T) {
tests := []struct {
text string
surfs []string
gold string
valid bool
}{
{
text: "|ジャパリ?まん|は|美味しい",
surfs: []string{"ジャ", "パリ", "まんは", "美味しい"},
gold: Segment + "ジ ャ" + IllegalSegment + "パ リ" + Segment + "ま ん" + IllegalUnsegment + "は" + Segment + "美 味 し い" + Segment,
valid: false,
},
}
for _, test := range tests {
sysout, isValid := DecorateSurfaces(test.text, test.surfs)
if sysout != test.gold {
t.Errorf("Expected %v but got %v", test.gold, sysout)
}
if isValid != test.valid {
t.Errorf("Expected %v but got %v", test.valid, isValid)
}
}
}
func BenchmarkDecorateSurfaces(b *testing.B) {
for i := 0; i < 10000; i++ {
DecorateSurfaces("|ジャパリ?まん|は|美味しい", []string{"ジャ", "パリ", "まんは", "美味しい"})
DecorateSurfaces("ジ|ャパリ?まん|は|美味しい", []string{"ジャ", "パリ", "まんは", "美味しい"})
DecorateSurfaces("ジャパ|リ?まん|は|美味しい", []string{"ジャ", "パリ", "まんは", "美味しい"})
}
}
func TestPrettySurfaces(t *testing.T) {
tests := []struct {
surfs []string
gold string
}{
{
surfs: []string{"ジャパリ", "まん", "は", "美味しい"},
gold: fmt.Sprintf("%sジ ャ パ リ%sま ん%sは%s美 味 し い%s", Segment, Segment, Segment, Segment, Segment),
},
}
for _, test := range tests {
sysout := PrettySurfaces(test.surfs)
if sysout != test.gold {
t.Errorf("Expected %v but got %v", test.gold, sysout)
}
}
}
func TestPrettyFeatures(t *testing.T) {
tests := []struct {
surfs []string
features []string
gold string
}{
{
surfs: []string{"ジャパリ", "まん", "は", "美味しい"},
features: []string{"名", "名", "助", "形"},
gold: fmt.Sprintf("%s名 %s名 %s助%s形 %s", Segment, Segment, Segment, Segment, Segment),
},
}
for _, test := range tests {
sysout := PrettyFeatures(test.surfs, test.features)
if sysout != test.gold {
t.Errorf("Expected %v but got %v", test.gold, sysout)
}
}
}
func init() {
color.NoColor = true
}