-
Notifications
You must be signed in to change notification settings - Fork 0
/
gradation_test.go
101 lines (83 loc) · 2.77 KB
/
gradation_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
package neng
import (
"testing"
"github.com/Zedran/neng/internal/tests"
)
// Tests comparative. Fails if incorrect comparative form is returned.
// If the word does not exist in the database, the test attempts
// to transform it as FT_REGULAR.
func TestComparative(t *testing.T) {
type testCase struct {
Input string `json:"input"`
WC WordClass `json:"word_class"`
Expected string `json:"expected"`
}
var cases []testCase
if err := tests.ReadData("TestComparative.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, c.WC)
if err != nil {
t.Logf("Test case '%s' (WordClass %d) does not exist in the word database. Assume it is regular and proceed.", c.Input, c.WC)
word, err = NewWordFromParams(c.Input, 0, nil)
if err != nil {
t.Errorf("Failed for '%s' - error from NewWordFromParams: %v", c.Input, err)
}
}
output := comparative(word)
if output != c.Expected {
t.Errorf("Failed for '%s': expected '%s', got '%s'", c.Input, c.Expected, output)
}
}
}
// Tests sufGrad. Fails if a malformed graded form is returned.
func TestSufGrad(t *testing.T) {
var cases [][]string
if err := tests.ReadData("TestSufGrad.json", &cases); err != nil {
t.Fatalf("Failed loading test data: %v", err)
}
for _, c := range cases {
cmp := sufGrad(c[0], "er")
sup := sufGrad(c[0], "est")
if cmp != c[1] || sup != c[2] {
t.Errorf("Failed for '%s': expected '%s' - '%s', got '%s' - '%s'", c[0], c[1], c[2], cmp, sup)
}
}
}
// Tests superlative. Fails if a malformed superlative form is returned.
// If the word does not exist in the database, the test attempts
// to transform it as FT_REGULAR.
func TestSuperlative(t *testing.T) {
type testCase struct {
Input string `json:"input"`
WC WordClass `json:"word_class"`
Expected string `json:"expected"`
}
var cases []testCase
if err := tests.ReadData("TestSuperlative.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, c.WC)
if err != nil {
t.Logf("Test case '%s' (WordClass %d) does not exist in the word database. Assume it is regular and proceed.", c.Input, c.WC)
word, err = NewWordFromParams(c.Input, 0, nil)
if err != nil {
t.Errorf("Failed for '%s' - error from NewWordFromParams: %v", c.Input, err)
}
}
output := superlative(word)
if output != c.Expected {
t.Errorf("Failed for '%s': expected '%s', got '%s'", c.Input, c.Expected, output)
}
}
}