This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tureng_test.go
88 lines (67 loc) · 1.88 KB
/
tureng_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
package main
import (
"testing"
)
// TODO: mock website
func TestDisplayCount(t *testing.T) {
displayCount := 2
flags := &Flags{
DisplayCount: displayCount,
TypeFilters: []WordType{VERB, NOUN, ADJECTIVE, ADVERB, UNKNOWN},
}
result, _ := Translate("brave", flags)
if len(result.Translations) != displayCount {
t.Errorf("Result count should not be greater than %d. %d", displayCount, len(result.Translations))
}
}
func TestTranslate(t *testing.T) {
displayCount := 10
flags := &Flags{
DisplayCount: displayCount,
TypeFilters: []WordType{VERB, NOUN, ADJECTIVE, ADVERB, UNKNOWN},
}
result, _ := Translate("brave", flags)
if len(result.Translations) == 0 {
t.Errorf("Translation count should not be greater than %d. %d", displayCount, len(result.Translations))
}
if len(result.Translations) == 0 {
t.Error("Translation count should be greater than 0")
}
}
func TestWordTypeFiltering(t *testing.T) {
t.Run("get only verbs", func(t *testing.T) {
conf := &Flags{
DisplayCount: 100,
TypeFilters: []WordType{VERB}, // Get only verbs
}
result, _ := Translate("brave", conf)
for _, item := range result.Translations {
if item.Type != VERB {
t.Fatal("Translation count should equal to 6")
}
}
})
t.Run("get only adverbs", func(t *testing.T) {
flags := &Flags{
DisplayCount: 100,
TypeFilters: []WordType{ADVERB}, // Get only adverbs
}
result, _ := Translate("brave", flags)
if len(result.Translations) != 0 {
t.Errorf("Translation count should equal to 0")
}
})
}
func TestGettingSuggestions(t *testing.T) {
flags := &Flags{
DisplayCount: 100,
TypeFilters: []WordType{NOUN},
}
result, _ := Translate("happyoooo", flags)
if len(result.Translations) > 0 {
t.Errorf("Translation count for 'happyoooo' should be 0.")
}
if len(result.Suggestions) == 0 {
t.Errorf("Should be at least one suggestion for 'happyoooo'")
}
}