forked from hailocab/go-geoindex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
point_test.go
39 lines (29 loc) · 1.07 KB
/
point_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
package geoindex
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDistance(t *testing.T) {
lonLength := lonDegreeDistance{}
assert.InDelta(t, float64(distance(waterloo, kingsCross)), 3080.074, 0.001)
d := math.Sqrt(float64(approximateSquareDistance(lonLength, waterloo, kingsCross)))
assert.InDelta(t, d, 3074.987, 0.001)
d = math.Sqrt(float64(approximateSquareDistance(lonLength, leicester, coventGarden)))
assert.InDelta(t, d, 305.662, 0.001)
d = math.Sqrt(float64(approximateSquareDistance(lonLength, oxford, embankment)))
assert.InDelta(t, d, 1593.763, 0.001)
}
func TestDirection(t *testing.T) {
assert.Equal(t, North, DirectionTo(waterloo, kingsCross))
assert.Equal(t, NorthEast, DirectionTo(leicester, coventGarden))
assert.Equal(t, SouthEast, DirectionTo(oxford, embankment))
}
func TestBearing(t *testing.T) {
b := BearingTo(waterloo, kingsCross)
assert.InDelta(t, b, -12.659, 0.001)
b = BearingTo(leicester, coventGarden)
assert.InDelta(t, b, 57.706, 0.001)
b = BearingTo(oxford, embankment)
assert.InDelta(t, b, 122.939, 0.001)
}