-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountries_test.go
77 lines (69 loc) · 1.69 KB
/
countries_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
package countries
import (
"fmt"
"testing"
)
var countryData *CountryData
func init() {
countryData = InstanceCountry()
}
func TestData_GetCountryCodeByEnglishName(t *testing.T) {
expected := "US"
given, err := countryData.GetCountryCodeByEnglishName("United States")
if given != expected && err != nil {
fmt.Println(err)
t.Fatalf(`TestData_GetCountryCodeByEnglishName("United States") = %s, want "%s", error`, given, expected)
}
}
func TestGetContinentByCountryValid(t *testing.T) {
expected := "Asia"
given, err := countryData.GetContinentByCountry("CN")
if expected != given && err != nil {
t.Fatalf(`GetContinentByCountry("CN") = %s, want "%s", error`, given, expected)
}
}
func TestGetContinentByCountryError(t *testing.T) {
expected := ""
given, err := countryData.GetContinentByCountry("")
if expected != given && err != nil {
t.Fatalf(`GetContinentByCountry("") = %s, want "%s", error`, given, expected)
}
}
func TestGetCountriesByContinent(t *testing.T) {
expected := []string{"AS",
"AU",
"CK",
"FJ",
"PF",
"GU",
"KI",
"MH",
"FM",
"NR",
"NC",
"NZ",
"NU",
"NF",
"MP",
"PW",
"PG",
"PN",
"SB",
"TK",
"TO",
"TV",
"VU",
"WF",
"WS"}
given, err := countryData.GetCountryCodesByContinent("Oceania")
if len(expected) != len(given) && err != nil {
t.Fatalf(`GetCountriesByContinent("Oceania") = %d, want "%d", error`, len(given), len(expected))
}
}
func TestGetCountriesByContinentEmpty(t *testing.T) {
expected := make([]string, 0)
given, err := countryData.GetCountryCodesByContinent("")
if len(expected) != len(given) && err != nil {
t.Fatalf(`GetCountriesByContinent("Oceania") = %d, want "%d", error`, len(given), len(expected))
}
}