-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeo_test.go
37 lines (29 loc) · 953 Bytes
/
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
package femtioelva_test
import (
"math"
"testing"
"github.com/vikblom/femtioelva"
)
func TestWhereIsGothenburg(t *testing.T) {
// Sanity check against https://www.latlong.net/lat-long-utm.html
east, north := femtioelva.LatLong2UTM(femtioelva.GBG_LAT, femtioelva.GBG_LON)
if int(east) != 677214 {
t.Error("UTM easting of Gothenburg in unexpected place.")
}
if int(north) != 6400188 {
t.Error("UTM northing of Gothenburg in unexpected place.")
}
}
func TestBoxIsSquare(t *testing.T) {
side := 1000.0
b := femtioelva.GeoBox(femtioelva.GBG_LAT, femtioelva.GBG_LON, side)
e1, n1 := femtioelva.LatLong2UTM(b.LowLat, b.LowLong)
e2, n2 := femtioelva.LatLong2UTM(b.HighLat, b.HighLong)
width := e2 - e1
height := n2 - n1
diagonal := math.Sqrt(width*width + height*height)
diff := diagonal - side*math.Sqrt(2)
if diff < -1 || 1 < diff {
t.Errorf("Expected diagonal length close to %f but got %f", side*math.Sqrt(2), diagonal)
}
}