-
Notifications
You must be signed in to change notification settings - Fork 0
/
verb_test.go
140 lines (114 loc) · 3.75 KB
/
verb_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
package neng
import (
"testing"
"github.com/Zedran/neng/internal/tests"
)
// Tests gerund. Fails if improper gerund form of a verb is returned.
func TestGerund(t *testing.T) {
var cases map[string]string
if err := tests.ReadData("TestGerund.json", &cases); err != nil {
t.Fatalf("Failed loading test data: %v", err)
}
for input, expected := range cases {
output := gerund(input)
if output != expected {
t.Errorf("Failed for '%s': expected '%s', got '%s'", input, expected, output)
}
}
}
// Tests pastParticiple. Fails if improper Past Participle form of a verb
// is returned. Handling of regular verbs is only symbolically checked,
// as it is the main goal of TestPastSimpleRegular.
func TestPastParticiple(t *testing.T) {
var cases map[string]string
if err := tests.ReadData("TestPastParticiple.json", &cases); err != nil {
t.Fatalf("Failed loading test data: %v", err)
}
gen, err := DefaultGenerator()
if err != nil {
t.Fatalf("Failed: DefaultGenerator returned an error: %v", err)
}
for input, expected := range cases {
word, err := gen.Find(input, WC_VERB)
if err != nil {
t.Logf("Test case '%s' does not exist in the word database. Assume it is regular and proceed.", input)
word, err = NewWordFromParams(input, 0, nil)
if err != nil {
t.Errorf("Failed for '%s' - error from NewWordFromParams: %v", input, err)
}
}
output := pastParticiple(word)
if output != expected {
t.Errorf("Failed for '%s': expected '%s', got '%s'", input, expected, output)
}
}
}
// Tests pastRegular. Fails if incorrect past tense form of a regular verb
// is returned.
func TestPastRegular(t *testing.T) {
var cases map[string]string
if err := tests.ReadData("TestPastRegular.json", &cases); err != nil {
t.Fatalf("Failed loading test data: %v", err)
}
for input, expected := range cases {
output := pastRegular(input)
if output != expected {
t.Errorf("Failed for '%s': expected '%s', got '%s'", input, expected, output)
}
}
}
// Tests pastSimple. Fails if improper Past Simple form of a verb is returned.
// Handling of regular verbs is only symbolically checked, as it is the main
// goal of TestPastSimpleRegular
func TestPastSimple(t *testing.T) {
type testCase struct {
Input string `json:"input"`
Expected string `json:"expected"`
Plural bool `json:"plural"`
}
var cases []testCase
if err := tests.ReadData("TestPastSimple.json", &cases); err != nil {
t.Fatalf("Failed loading test data: %v", err)
}
gen, err := DefaultGenerator()
if err != nil {
t.Fatalf("Failed: DefaultGenerator returned an error: %v", err)
}
for _, c := range cases {
word, err := gen.Find(c.Input, WC_VERB)
if err != nil {
t.Logf("Test case '%s' does not exist in the word database. Assume it is regular and proceed.", c.Input)
word, err = NewWordFromParams(c.Input, 0, nil)
if err != nil {
t.Errorf("Failed for '%s' - error from NewWordFromParams: %v", c.Input, err)
}
}
output := pastSimple(word, c.Plural)
if output != c.Expected {
t.Errorf("Failed for '%s' (plural = %v): expected '%s', got '%s'", c.Input, c.Plural, c.Expected, output)
}
}
}
// Tests presentSimple. Fails if improper Present Simple form of a verb
// is returned.
func TestPresentSimple(t *testing.T) {
type testCase struct {
Input string `json:"input"`
Expected string `json:"expected"`
Plural bool `json:"plural"`
}
var cases []testCase
if err := tests.ReadData("TestPresentSimple.json", &cases); err != nil {
t.Fatalf("Failed loading test data: %v", err)
}
for _, c := range cases {
output := presentSimple(c.Input, c.Plural)
if output != c.Expected {
number := "sing."
if c.Plural {
number = "pl."
}
t.Errorf("Failed for '%s': expected '%s' (%s), got '%s'", c.Input, c.Expected, number, output)
}
}
}