-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuvant_test.go
More file actions
88 lines (76 loc) · 1.9 KB
/
cuvant_test.go
File metadata and controls
88 lines (76 loc) · 1.9 KB
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 definitii
import (
"testing"
)
// Functie de test pentru functia getUrl.
func TestGetUrl(t *testing.T) {
var cuvant string
cuvant = "test"
rezultat := getUrl(cuvant)
if rezultat != "https://dexonline.ro/definitie/test/json" {
t.Error("Url format incorect")
}
}
func TestIsValid(t *testing.T) {
defs := make([]Definitie, 1, 1) // Exemplu corect
defs = append(defs, Definitie{Text: "test"})
var cuvant = Cuvant{
Type: "test",
Word: "test",
Definitions: defs,
}
valid := cuvant.isValid()
if valid == false {
t.Error("Expected true, input is valid")
}
defsInvalid := make([]Definitie, 0, 1) // Lipsesc definitiile.
cuvantInvalid := Cuvant{
Definitions: defsInvalid,
Type: "test",
Word: "test",
}
valid2 := cuvantInvalid.isValid()
if valid2 == true {
t.Error("Expected false, input is invalid")
}
defsValid := make([]Definitie, 0, 10)
defsValid = append(defsValid, Definitie{Text: "test"})
cuvantFaraType := Cuvant{ // Formam un cuvant fara Type.
Definitions: defsValid,
Word: "test",
}
if cuvantFaraType.isValid() == true {
t.Error("Expected false, input is invalid")
}
cuvantFaraWord := Cuvant{ // Formam un cuvant fara Word
Definitions: defsValid,
Type: "test",
}
if cuvantFaraWord.isValid() == true {
t.Error("Expected false, input is invalid")
}
}
func TestFetchCuvant(t *testing.T) {
var cuvant string
cuvant = "cuvant"
rez, err := FetchCuvant(cuvant)
if err != nil {
t.Error("Unexpected Error")
} else {
if rez.isValid() != true {
t.Error("Expected true, input is valid")
}
if rez.Word != "cuvant" {
t.Error("wrong Word field")
}
if rez.Type != "searchResults" {
t.Error("Wrong Type field")
}
}
rez, err = FetchCuvant("ababababa") // Cuvant inexistent
if err == nil {
t.Error("Expected error")
} else if err.Error() != "Cuvantul nu a fost gasit" {
t.Error("Expected error message not found.")
}
}