File: point_test.go

package info (click to toggle)
golang-github-pd0mz-go-maidenhead 0.0~git20170221.faa09c2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 84 kB
  • sloc: makefile: 2
file content (35 lines) | stat: -rw-r--r-- 956 bytes parent folder | download | duplicates (2)
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
package maidenhead

import (
	"math"
	"testing"
)

var pointTests = []struct {
	point   Point
	bearing float64
	compass string
}{
	{Point{48.14666, 11.60833}, 130, "SE"},
	{Point{-34.91, -56.21166}, 69, "ENE"},
	{Point{38.92, -77.065}, 98, "E"},
	{Point{-41.28333, 174.745}, 122, "ESE"},
	{Point{41.714775, -72.727260}, 101, "ESE"},
	{Point{37.413708, -122.1073236}, 69, "ENE"},
	{Point{35.0542, -85.1142}, 92, "E"},
}

func TestPointBearing(t *testing.T) {
	var center = NewPoint(0, 0)
	for _, test := range pointTests {
		bearing := math.Floor(test.point.Bearing(center))
		if bearing != test.bearing {
			t.Fatalf("%s -> %s, expected %0.f, got %0.f\n", test.point, center, bearing, test.bearing)
		}
		compass := test.point.CompassBearing(center)
		if compass != test.compass {
			t.Logf("%s -> %s, expected %q, got %q\n", test.point, center, compass, test.compass)
		}
		t.Logf("%s -> %s, bearing %.0f %s\n", test.point, center, bearing, compass)
	}
}