-
Notifications
You must be signed in to change notification settings - Fork 0
/
wubi_test.go
160 lines (146 loc) · 3.09 KB
/
wubi_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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package wubi
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestGetCode_WuBi86(t *testing.T) {
testTable := []struct {
testName string
char rune
codes []string
}{
{
testName: "在",
char: '在',
codes: []string{"d", "dhf", "dhfd"},
},
{
testName: "的",
char: '的',
codes: []string{"r", "rqy", "rqyy"},
},
{
testName: "餰",
char: '餰',
codes: []string{"wpth", "wyvh"},
},
}
c := New86()
for _, v := range testTable {
codes := c.GetCode(v.char)
require.Equal(t, v.codes, codes)
}
}
func TestGetCode_WuBi86_Code2Chars(t *testing.T) {
testTable := []struct {
testName string
code string
chars []string
}{
{
testName: "d",
chars: []string{"在", "石"},
code: "d",
},
{
testName: "r",
chars: []string{"白", "的"},
code: "r",
},
{
testName: "wpth",
chars: []string{"飾", "餰"},
code: "wpth",
},
}
c := New86()
for _, v := range testTable {
chars := c.GetChar(v.code)
require.Equal(t, v.chars, chars)
}
}
func TestGetCode_WuBi86_Codes2Chars(t *testing.T) {
testTable := []struct {
testName string
code []string
chars [][]string
}{
{
testName: "d r",
chars: [][]string{{"在", "石"}, {"白", "的"}},
code: []string{"d", "r"},
},
{
testName: "wpth p",
chars: [][]string{{"飾", "餰"}, {"之", "这"}},
code: []string{"wpth", "p"},
},
}
c := New86()
for _, v := range testTable {
chars := c.GetChars(v.code)
require.Equal(t, v.chars, chars)
}
}
func TestGetCodes_WuBi86(t *testing.T) {
testTable := []struct {
testName string
chars string
codes [][]string
}{
{
testName: "干一行",
chars: "干一行,爱一行,一行行,行行行,一行不行,行行不行",
codes: [][]string{{"fggh"}, {"g", "ggl", "ggll"}, {"tf", "tfhh"}, {","}, {"ep", "epd", "epdc"},
{"g", "ggl", "ggll"}, {"tf", "tfhh"}, {","}, {"g", "ggl", "ggll"}, {"tf", "tfhh"}, {"tf", "tfhh"},
{","}, {"tf", "tfhh"}, {"tf", "tfhh"}, {"tf", "tfhh"}, {","}, {"g", "ggl", "ggll"}, {"tf", "tfhh"},
{"i", "gi", "gii"}, {"tf", "tfhh"}, {","}, {"tf", "tfhh"}, {"tf", "tfhh"}, {"i", "gi", "gii"},
{"tf", "tfhh"}},
},
}
c := New86()
for _, v := range testTable {
codes := c.GetCodes(v.chars)
require.Equal(t, v.codes, codes)
}
}
func TestGetCode_WuBi98(t *testing.T) {
testTable := []struct {
testName string
char rune
codes []string
}{
{
testName: "在",
char: '在',
codes: []string{"d", "dhf", "dhfd"},
},
{
testName: "的",
char: '的',
codes: []string{"r", "rqy", "rqyy"},
},
{
testName: "餰",
char: '餰',
codes: []string{"wvts"},
},
}
c := New98()
for _, v := range testTable {
codes := c.GetCode(v.char)
require.Equal(t, v.codes, codes)
}
}
func BenchmarkWubi86Char2Codes(b *testing.B) {
c := New86()
for i := 0; i < b.N; i++ {
_ = c.GetCode('一')
}
}
func BenchmarkWubi86Chars2Codes(b *testing.B) {
c := New86()
for i := 0; i < b.N; i++ {
_ = c.GetCodes("干一行")
}
}