package geo import "testing" // The squares the PSK Reporter feed is filtered on. A wrong ring means either // receiving the world again or hearing nothing. func TestNeighbourGrids(t *testing.T) { // JN36 is around 46.5N 5.5E. lat, lon, ok := GridToLatLon("JN36") if !ok { t.Fatal("JN36 did not resolve") } if got := LatLonToGrid(lat, lon); got != "JN36" { t.Fatalf("round trip gave %q, want JN36", got) } ring := NeighbourGrids(lat, lon, 1) if len(ring) != 9 { t.Errorf("ring 1 has %d squares, want 9: %v", len(ring), ring) } found := false for _, g := range ring { if g == "JN36" { found = true } if len(g) != 4 { t.Errorf("not a 4-character square: %q", g) } } if !found { t.Errorf("the operator's own square is missing from %v", ring) } if n := len(NeighbourGrids(lat, lon, 0)); n != 1 { t.Errorf("ring 0 has %d squares, want just the operator's", n) } if n := len(NeighbourGrids(lat, lon, 2)); n != 25 { t.Errorf("ring 2 has %d squares, want 25", n) } } // Near a pole a step north has nowhere to go; it must be dropped, not wrapped // onto a square on the far side of the world. func TestNeighbourGridsNearThePole(t *testing.T) { for _, g := range NeighbourGrids(89.5, 25, 1) { if len(g) != 4 { t.Errorf("bad square near the pole: %q", g) } } }