Initial import

This commit is contained in:
2026-02-14 15:59:31 +01:00
parent 05dcea3c2b
commit f1ecbfaf8d
19 changed files with 2675 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package maidenhead
import (
"math"
"testing"
)
var pointTests = []struct {
point Point
bearing float64
compass string
}{
{Point{48.14666, 11.60833}, 195, "SSW"},
{Point{-34.91, -56.21166}, 69, "ENE"},
{Point{38.92, -77.065}, 98, "E"},
{Point{-41.28333, 174.745}, 187, "S"},
{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 {
t.Run("", func(t *testing.T) {
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, test.bearing, bearing)
}
compass := test.point.CompassBearing(center)
if compass != test.compass {
t.Logf("%s -> %s, expected %q, got %q\n", test.point, center, test.compass, compass)
}
//t.Logf("%s -> %s, bearing %.0f %s\n", test.point, center, bearing, compass)
})
}
}