package geo import "testing" func TestMeters(t *testing.T) { // NYC → Boston ≈ 305 km d := Meters(Point{Lat: 40.7128, Lon: -74.006}, Point{Lat: 42.3601, Lon: -71.0589}) if d < 300_000 || d > 320_000 { t.Errorf("NYC-Boston = %.0f m, want ~305km", d) } } func TestDistToPolyline(t *testing.T) { poly := []Point{{Lat: 0, Lon: 0}, {Lat: 10, Lon: 0}} // north-south at lon 0 // 1 deg lon at equator ≈ 111.3 km d := DistToPolylineMeters(Point{Lat: 5, Lon: 1}, poly) if d < 110_000 || d > 115_000 { t.Errorf("distance = %.0f m, want ~111km", d) } // on the line if d := DistToPolylineMeters(Point{Lat: 5, Lon: 0}, poly); d > 100 { t.Errorf("on-line distance = %.0f m, want ~0", d) } // past the end: distance to endpoint if d := DistToPolylineMeters(Point{Lat: 12, Lon: 0}, poly); d < 200_000 || d > 240_000 { t.Errorf("past-end distance = %.0f m, want ~222km", d) } } func TestMinAt(t *testing.T) { if m := MinAt(4600, 4.6); m != 60 { t.Errorf("MinAt(4600m, 4.6kmh) = %d, want 60", m) } }