-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
65 lines (52 loc) · 1.69 KB
/
utils_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
package neng
import "testing"
/* Tests whether countSyllables returns a proper number of syllables for sample words. */
func TestCountSyllables(t *testing.T) {
cases, err := loadTestMapStringInt("TestCountSyllables.json")
if err != nil {
t.Fatalf("Failed loading test data: %s", err.Error())
}
for input, expected := range cases {
seq := getSequence(input)
output := countSyllables(input, seq)
if output != expected {
t.Errorf("Failed for '%s': expected '%d', got '%d'", input, expected, output)
}
}
}
/* Tests whether findIrregular returns a correct verb line. */
func TestFindIrregular(t *testing.T) {
cases, err := loadTest2DSliceString("TestFindIrregular.json")
if err != nil {
t.Fatalf("Failed loading test data: %s", err.Error())
}
irregular, err := loadIrregularWords("res/verb.irr")
if err != nil {
t.Fatalf("loadIrregularWords failed: %s", err.Error())
}
for _, input := range cases {
output := findIrregular(input[0], irregular)
if output == nil {
t.Errorf("Failed for '%s': nil returned", input)
} else if output[0] != input[0] {
t.Errorf("Failed for '%s': expected '%s', got '%s'", input, input, output)
}
}
regularVerb := "panic"
if output := findIrregular(regularVerb, irregular); output != nil {
t.Errorf("Failed for '%s': nil not returned", regularVerb)
}
}
/* Tests getSequence function. */
func TestGetSequence(t *testing.T) {
cases, err := loadTestMapStringString("TestGetSequence.json")
if err != nil {
t.Fatalf("Failed loading test data: %s", err.Error())
}
for input, expected := range cases {
output := getSequence(input)
if output != expected {
t.Errorf("Failed for '%s': expected '%s', got '%s'", input, expected, output)
}
}
}