-
Notifications
You must be signed in to change notification settings - Fork 0
/
rae_test.go
92 lines (72 loc) · 1.86 KB
/
rae_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
package gorae
import (
"fmt"
"strings"
"testing"
)
/*
Word are composed of a 7 char ~random ID: 002rZ9U
and can be as short as 1 character: "a"
*/
func isAValidWord(word RaeWord) bool {
if len(word.ID) < 5 || len(word.Header) < 1 {
return false
}
return true
}
func TestWordOfTheDay(t *testing.T) {
wot := WordOfTheDay()
if isAValidWord(wot) {
fmt.Println("Today's word: " + wot.ID + ", " + wot.Header)
} else {
t.Error("Didn't get a valid key for the Word of the Day: " +
wot.ID + " " + wot.Header)
}
}
func TestSingleResultApproximateWord(t *testing.T) {
words := SearchWords("enfasi")
gotTheWord := false
if len(words.Res) != 1 {
t.Error("Didn't get the single word back from the RAE")
return
}
if words.Res[0].Header == "énfasis." {
gotTheWord = true
}
if !gotTheWord {
t.Error("Didn't the the word 'énfasis.' back from the RAE")
}
}
func TestMultipleResultApproximateWord(t *testing.T) {
words := SearchWords("a") // This returs 4 results
if len(words.Res) < 3 {
t.Errorf("'a' only returned %d words", len(words.Res))
}
}
func TestFailedApproximateWordSearch(t *testing.T) {
words := SearchWords("aoeui")
if len(words.Res) != 0 {
t.Error("Searching 'aoeui' shouldn't return any word o_O")
}
}
func TestExactWordSearchFail(t *testing.T) {
words := searchExactWord("enfasis") // accent
if len(words.Res) != 0 {
t.Errorf("'enfasis' returned %d words", len(words.Res))
}
}
func TestExactWordSearch(t *testing.T) {
words := searchExactWord("énfasis")
if len(words.Res) == 0 {
t.Errorf("'énfasis' returned %d words", len(words.Res))
}
}
func TestFetchDefinition(t *testing.T) {
wotd := WordOfTheDay()
definition := FetchDefinition(wotd.ID)
// HTML with a bunch of "class" attributes is returned
count := strings.Count(definition, "class")
if count < 4 {
t.Error("didn't seem to get a definition for " + wotd.ID)
}
}