-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhyphenate_test.go
158 lines (143 loc) · 2.39 KB
/
hyphenate_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
package hyphenation
import (
"strings"
"testing"
)
const patternsEN string = `1co
4m1p
pu2t
5pute
put3er
pos1s
1pos
2ess
2ss
s1e4s
s1si
1sio
5sion
2io
o2n
`
const patternsDE string = `
.sc4h4
1de
1fa
1fe
1ne
1sc
1se
1ße
1ta
2ä3s2e
2hn
2hr
2if
4ahr
4f1f
4l1l
4n1g
4n1n
4r1t
4rn
5fahrt
6r1s
c2h
g2r4
gl2
h2ü
h3ner
hn2e
hühne4
ng2läs
ö1ß
rn3g2
s1t
s2ta
s4er.
üh3ne
`
func TestHyphenate(t *testing.T) {
r := strings.NewReader(patternsEN)
l, err := New(r)
if err != nil {
t.Error(err)
}
data := []struct {
word string
breakpoints []int
}{
{"possession", []int{3, 6}},
{"Computer", []int{3, 6}},
{"a", []int{}},
}
for _, entry := range data {
h := l.Hyphenate(entry.word)
if len(h) != len(entry.breakpoints) {
t.Errorf("Hyphenate(%s), len = %d, want %d", entry.word, len(h), len(entry.breakpoints))
}
for i, v := range h {
if bp := entry.breakpoints[i]; bp != v {
t.Errorf("Hyphenate(%s), breakpoint[%d] = %d, want %d", entry.word, i, bp, v)
}
}
}
}
func TestHyphenateDE(t *testing.T) {
r := strings.NewReader(patternsDE)
l, err := New(r)
if err != nil {
t.Error(err)
}
data := []struct {
word string
breakpoints []int
}{
{"größer", []int{3}},
{"Schiffahrt", []int{5, 9}},
{"Hühnerstall", []int{3, 6, 10}},
{"ferngläser", []int{4, 7}},
{"denn", []int{3}},
}
for _, entry := range data {
h := l.Hyphenate(entry.word)
if len(h) != len(entry.breakpoints) {
t.Errorf("Hyphenate(%s), len = %d, want %d", entry.word, len(h), len(entry.breakpoints))
}
for i, v := range h {
if bp := entry.breakpoints[i]; bp != v {
t.Errorf("Hyphenate(%s), breakpoint[%d] = %d, want %d", entry.word, i, bp, v)
}
}
}
}
func TestHyphenateDEmin(t *testing.T) {
r := strings.NewReader(patternsDE)
l, err := New(r)
if err != nil {
t.Error(err)
}
l.Leftmin = 2
l.Rightmin = 3
data := []struct {
word string
breakpoints []int
}{
{"größer", []int{3}},
{"Schiffahrt", []int{5}},
{"Hühnerstall", []int{3, 6}},
{"ferngläser", []int{4, 7}},
{"denn", []int{}},
}
for _, entry := range data {
h := l.Hyphenate(entry.word)
if len(h) != len(entry.breakpoints) {
t.Errorf("Hyphenate(%s), len = %d, want %d", entry.word, len(h), len(entry.breakpoints))
}
for i, v := range h {
if bp := entry.breakpoints[i]; bp != v {
t.Errorf("Hyphenate(%s), breakpoint[%d] = %d, want %d", entry.word, i, bp, v)
}
}
}
}