package uls import ( "os" "testing" ) func TestGrid6(t *testing.T) { cases := []struct { lat, lon float64 want string }{ {38.90, -77.03, "FM18lw"}, // Washington DC {40.71, -74.00, "FN30xr"}, // New York {34.05, -118.24, "DM04vd"},// Los Angeles } for _, c := range cases { if got := grid6(c.lat, c.lon); got[:4] != c.want[:4] { t.Errorf("grid6(%v,%v)=%q want field/square %q", c.lat, c.lon, got, c.want[:4]) } } } // TestParseGeoNames runs against the real GeoNames US.zip if present in the // scratchpad (downloaded during development); skipped otherwise. func TestParseGeoNames(t *testing.T) { path := os.Getenv("GEONAMES_ZIP") if path == "" { t.Skip("set GEONAMES_ZIP to the US.zip path to run") } m, err := parseGeoNames(path) if err != nil { t.Fatal(err) } if len(m) < 30000 { t.Fatalf("expected >30k ZIPs, got %d", len(m)) } // A known ZIP: 20500 = The White House, DC. if r, ok := m["20500"]; !ok || r.state != "DC" { t.Errorf("ZIP 20500 = %+v (ok=%v)", r, ok) } }