-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttifier_test.go
More file actions
141 lines (126 loc) · 3.18 KB
/
buttifier_test.go
File metadata and controls
141 lines (126 loc) · 3.18 KB
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
package buttifier
import (
"strings"
"testing"
)
type UnitTestRandSource struct{}
func (UnitTestRandSource) Uint64() uint64 {
return 0
}
func TestButtifyWord(t *testing.T) {
b, err := New(English)
b.RandSource = UnitTestRandSource{}
if err != nil {
t.Fatal(err)
}
resultMap := map[string]string{
"successful": "buttbuttbutt",
"someone": "buttbutt",
"": "",
"partner": "buttbutt",
"partne": "butt",
"developers": "buttbuttbuttbuttbutt",
"computer": "buttbuttbutt",
"asd": "butt",
"butt": "butt",
}
for word, expected := range resultMap {
actual, _ := b.ButtifyWord(word)
if expected != actual {
t.Errorf("expected %s => %s, got %s => %s", word, expected, word, actual)
}
}
}
func TestButtifySentence(t *testing.T) {
b, err := New(English)
b.RandSource = UnitTestRandSource{}
if err != nil {
t.Fatal(err)
}
resultMap := map[string]string{
"grinding for partner": "buttbutt for partner",
"frizze5Wade laffer curve ": "butt laffer curve ",
}
for sentence, expected := range resultMap {
actual := b.ButtifySentence(sentence)
if expected != actual {
t.Errorf("expected %s, got %s", expected, actual)
}
}
}
func TestButtifyWordKeepsCase(t *testing.T) {
b, err := New(English)
b.RandSource = UnitTestRandSource{}
if err != nil {
t.Fatal(err)
}
resultMap := map[string]string{
"SUCcessFUL": "BUTTbuttBUTT",
"Someone": "buttbutt",
"SOmeone": "buttbutt",
"SOMeone": "buttbutt",
"SOMEone": "BUTTbutt",
}
for word, expected := range resultMap {
actual, _ := b.ButtifyWord(word)
if expected != actual {
t.Errorf("expected %s, got %s", expected, actual)
}
}
}
func TestHyphenateWord(t *testing.T) {
b, err := New(English)
b.RandSource = UnitTestRandSource{}
if err != nil {
t.Fatal(err)
}
expectedResults := []string{
"successful",
"someone",
"",
"partner",
"partne",
"developers",
"computer",
"asd",
"butt",
}
for _, expected := range expectedResults {
hyphenatedWord := b.HyphenateWord(expected)
syllables := []string{}
for _, syllable := range hyphenatedWord.Syllables {
syllables = append(syllables, syllable.Letters)
}
actual := strings.Join(syllables, "")
if expected != actual {
t.Errorf("expected '%s' got '%s'", expected, actual)
}
}
}
func TestHyphenateWordPt(t *testing.T) {
b, err := New(Portuguese)
b.RandSource = UnitTestRandSource{}
if err != nil {
t.Fatal(err)
}
expectedResults := map[string][]string{
"perspicaz": {"pers", "pi", "caz"},
"milionário": {"mi", "li", "o", "na", "ri", "o"},
"não": {"nao"},
}
for word, expectedSyllables := range expectedResults {
hyphenatedWord := b.HyphenateWord(word)
syllables := []string{}
for _, syllable := range hyphenatedWord.Syllables {
syllables = append(syllables, syllable.Letters)
}
if len(expectedSyllables) != len(hyphenatedWord.Syllables) {
t.Errorf("expected '%d' syllables got '%d' for word %q", len(expectedSyllables), len(hyphenatedWord.Syllables), word)
}
for i, syllable := range syllables {
if syllable != expectedSyllables[i] {
t.Errorf("expected '%s' got '%s'", strings.Join(expectedSyllables, "-"), strings.Join(syllables, "-"))
}
}
}
}