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
|
package maidenhead
import "testing"
var tests = []struct {
point Point
loc string
loc4 string
}{
{Point{48.14666, 11.60833}, "JN58TD", "JN58TD25"},
{Point{-34.91, -56.21166}, "GF15VC", "GF15VC41"},
{Point{38.92, -77.065}, "FM18LW", "FM18LW20"},
{Point{-41.28333, 174.745}, "RE78IR", "RE78IR92"},
{Point{41.714775, -72.727260}, "FN31PR", "FN31PR21"},
{Point{37.413708, -122.1073236}, "CM87WJ", "CM87WJ79"},
{Point{35.0542, -85.1142}, "EM75KB", "EM75KB63"},
}
func TestGridSquare(t *testing.T) {
for _, test := range tests {
enc, err := test.point.GridSquare()
if err != nil {
t.Fatal(err)
}
if enc != test.loc {
t.Fatalf("%s want %q, got %q\n", test.point, test.loc, enc)
}
t.Logf("%s encoded to %q\n", test.point, enc)
}
}
func TestExtendedSquarePrecision(t *testing.T) {
for _, test := range tests {
got, err := test.point.Locator(ExtendedSquarePrecision)
if err != nil {
t.Fatal(err)
}
if got != test.loc4 {
t.Fatalf("%s want %q, got %q\n", test.point, test.loc4, got)
}
t.Logf("%s encoded to %q\n", test.point, got)
}
}
// invalid Maiden Head locators must return error
func TestParseInvalidLocatorStrict(t *testing.T) {
locs := []string{
"JN58td",
"JN58TDAA",
"JNH",
"QN58jh",
"JN77ya",
" ",
"JN55J",
"JN89HA11aa2",
"JN89HA11aa22",
}
for _, l := range locs {
_, err := ParseLocatorStrict(l)
if err == nil {
t.Errorf("Parsing invalid locator '%s' with ParseLocatorStrict() doesn't return any error", l)
} else {
t.Logf("Parsing invalid locator '%s' returns error: %s", l, err)
}
}
}
|