-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
address_test.go
51 lines (42 loc) · 1.05 KB
/
address_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
package faker
import (
"regexp"
"testing"
)
func TestGetLongitude(t *testing.T) {
long := Longitude()
if long > 180 || long < -180 {
t.Error("function Longitude need return a valid longitude")
}
}
func TestGetLatitude(t *testing.T) {
lat := Latitude()
if lat > 90 || lat < -90 {
t.Error("function Latitude need return a valid longitude")
}
}
func TestGetRealAddress(t *testing.T) {
addr := GetRealAddress()
if addr.Address == "" || addr.City == "" {
t.Error("empty address")
}
t.Log(addr)
}
func TestGetCountryInfo(t *testing.T) {
rand.Seed(31)
countryInfo := GetCountryInfo()
expectedCountryName := "Morocco"
if countryInfo.Name != expectedCountryName {
t.Errorf("Test failed, expected: %s, got: %s", expectedCountryName, countryInfo.Name)
}
if len(countryInfo.Abbr) != 2 {
t.Error("Invalid ISO-3166 abbreviation")
}
if len(countryInfo.Continent) != 2 {
t.Error("Invalid continent abbreviation")
}
re := regexp.MustCompile(`^\d{1,3}(,\d{3})*$`)
if !re.MatchString(countryInfo.Population) {
t.Error("Invalid population number")
}
}