-
Notifications
You must be signed in to change notification settings - Fork 1
/
haversine_test.go
120 lines (103 loc) · 2.5 KB
/
haversine_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
package disfun
import "testing"
func TestHaversinePointZeroDistance(t *testing.T) {
pa1 := 203.9
pa2 := 203.9
pb1 := 203.9
pb2 := 203.9
radius := 8098.8
distance := HaversinePoint(pa1, pa2, pb1, pb2, radius)
expected := 0.0
if distance != expected {
t.Log("Expected: ", expected, "but got ", distance)
t.Fail()
}
}
func TestHaversinePointDistanceRadiusZero(t *testing.T) {
pa1 := 78543.03
pa2 := 00.143567
pb1 := 233057.87
pb2 := 00.18756783
radius := 0.0
distance := HaversinePoint(pa1, pa2, pb1, pb2, radius)
expected := 0.0
if distance != expected {
t.Log("Expected: ", expected, "but got ", distance)
t.Fail()
}
}
func TestHaversinePointDistanceRadiusNegOne(t *testing.T) {
pa1 := 78543.03
pa2 := 00.143567
pb1 := 233057.87
pb2 := 00.18756783
radius := -1.0
distance := HaversinePoint(pa1, pa2, pb1, pb2, radius)
expected := -1.3062043094350282
if distance != expected {
t.Log("Expected: ", expected, "but got ", distance)
t.Fail()
}
}
func TestHaversinePointDistanceRadiusOne(t *testing.T) {
pa1 := 78543.03
pa2 := 00.143567
pb1 := 233057.87
pb2 := 00.18756783
radius := 2.0
distance := HaversinePoint(pa1, pa2, pb1, pb2, radius)
expected := 2.6124086188700564
if distance != expected {
t.Log("Expected: ", expected, "but got ", distance)
t.Fail()
}
}
func TestHaversinePointDistance(t *testing.T) {
pa1 := 40.3
pa2 := 112.0
pb1 := 82.4
pb2 := 67.19
radius := 1345.09
distance := HaversinePoint(pa1, pa2, pb1, pb2, radius)
expected := 1045.8094451034126
if distance != expected {
t.Log("Expected: ", expected, "but got ", distance)
t.Fail()
}
}
func TestHaversinePointDistEagleToShastaMountain(t *testing.T) {
pa1 := 40.3061
pa2 := 112.0097
pb1 := 41.4092
pb2 := 122.1949
distance := HaversinePoint(pa1, pa2, pb1, pb2, EarthRadius)
expected := 864.8005613102791
if distance != expected {
t.Log("Expected: ", expected, "but got ", distance)
t.Fail()
}
}
func TestHaversineLatLonZeroDistance(t *testing.T) {
lat1 := 40.3061
lon1 := 112.0097
lat2 := 40.3061
lon2 := 112.0097
distance := HaversineLatLon(lat1, lon1, lat2, lon2)
expected := 0.0
if distance != expected {
t.Log("Expected: ", expected, "but got ", distance)
t.Fail()
}
}
func TestHaversineLatLonDistEagleToShastaMountain(t *testing.T) {
lat1 := 40.3061
lon1 := 112.0097
lat2 := 41.4092
lon2 := 122.1949
distance := HaversineLatLon(lat1, lon1, lat2, lon2)
expected := 864.8005613102791
if distance != expected {
t.Log("Expected: ", expected, "but got ", distance)
t.Fail()
}
}