-
Notifications
You must be signed in to change notification settings - Fork 0
/
geo_test.go
177 lines (164 loc) · 3.04 KB
/
geo_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package is
import (
"testing"
)
// TestLatitude tests Latitude function.
func TestLatitude(t *testing.T) {
tests := []struct {
name string
inStr string
inFloat float64
want bool
}{
{
name: "Valid Latitude float",
inFloat: 45.0,
want: true,
},
{
name: "Invalid Latitude float",
inFloat: 91.0,
want: false,
},
{
name: "Valid Latitude string",
inStr: "45.0",
want: true,
},
{
name: "Invalid Latitude string",
inStr: "91.0",
want: false,
},
{
name: "Invalid Latitude string format",
inStr: "invalid",
want: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var got bool
if test.inStr != "" {
got = Latitude(test.inStr)
} else {
got = Latitude(test.inFloat)
}
if got != test.want {
t.Errorf("Latitude(%v) = %v; want %v",
test.inStr, got, test.want)
}
})
}
}
// TestLongitude tests Longitude function.
func TestLongitude(t *testing.T) {
tests := []struct {
name string
inStr string
inFloat float64
want bool
}{
{
name: "Valid Longitude float",
inFloat: 45.0,
want: true,
},
{
name: "Invalid Longitude float",
inFloat: 181.0,
want: false,
},
{
name: "Valid Longitude string",
inStr: "45.0",
want: true,
},
{
name: "Invalid Longitude string",
inStr: "181.0",
want: false,
},
{
name: "Invalid Longitude string format",
inStr: "invalid",
want: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var got bool
if test.inStr != "" {
got = Longitude(test.inStr)
} else {
got = Longitude(test.inFloat)
}
if got != test.want {
t.Errorf("Longitude(%v) = %v; want %v",
test.inStr, got, test.want)
}
})
}
}
// TestCoordinates tests Coordinates function.
func TestCoordinates(t *testing.T) {
tests := []struct {
name string
latStr string
lonStr string
latFloat float64
lonFloat float64
want bool
}{
{
name: "Valid Coordinates float",
latFloat: 45.0,
lonFloat: -123.1,
want: true,
},
{
name: "Invalid Coordinates float",
latFloat: 90.1,
lonFloat: 180.1,
want: false,
},
{
name: "Valid Coordinates string",
latStr: "45.0",
lonStr: "-123.1",
want: true,
},
{
name: "Invalid Coordinates string",
latStr: "90.1",
lonStr: "180.1",
want: false,
},
{
name: "Invalid Coordinates string format",
latStr: "invalid",
lonStr: "180.1",
want: false,
},
{
name: "Invalid Coordinates string format",
latStr: "90.1",
lonStr: "invalid",
want: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var got bool
if test.latStr != "" && test.lonStr != "" {
got = Coordinates(test.latStr, test.lonStr)
} else {
got = Coordinates(test.latFloat, test.lonFloat)
}
if got != test.want {
t.Errorf("Coordinates(%v, %v) = %v; want %v",
test.latStr, test.lonStr, got, test.want)
}
})
}
}