-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradation_test.go
118 lines (99 loc) · 3.46 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// neng -- Non-Extravagant Name Generator
// Copyright (C) 2024 Wojciech Głąb (github.com/Zedran)
//
// This file is part of neng.
//
// neng is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3 only.
//
// neng is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with neng. If not, see <https://www.gnu.org/licenses/>.
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(nil)
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(nil)
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)
}
}
}