package numerics import ( "math" "testing" ) func TestAddGeo(t *testing.T) { // Rates sum component-wise with no longitude wrapping. got := AddGeo(GeoVec{Lat: 1, Lng: 350, Altitude: 2}, GeoVec{Lat: 3, Lng: 20, Altitude: 4}) want := GeoVec{Lat: 4, Lng: 370, Altitude: 6} if got != want { t.Errorf("AddGeo = %+v, want %+v (no wrap on rates)", got, want) } } func TestWindToGeoRate(t *testing.T) { // Pure eastward 10 m/s at the equator, sea level. dLat, dLng := WindToGeoRate(10, 0, 0, 0) wantLng := (180.0 / math.Pi) * 10.0 / EarthRadius if math.Abs(dLat) > 1e-15 { t.Errorf("dLat = %v, want 0", dLat) } if math.Abs(dLng-wantLng) > 1e-15 { t.Errorf("dLng = %v, want %v", dLng, wantLng) } // Northward 5 m/s at 60°N: dLat independent of longitude scaling. dLat, _ = WindToGeoRate(0, 5, 60, 0) wantLat := (180.0 / math.Pi) * 5.0 / EarthRadius if math.Abs(dLat-wantLat) > 1e-15 { t.Errorf("dLat at 60N = %v, want %v", dLat, wantLat) } // cos(lat) factor makes eastward motion span more degrees nearer the poles. _, dLngEq := WindToGeoRate(10, 0, 0, 0) _, dLng60 := WindToGeoRate(10, 0, 60, 0) if dLng60 <= dLngEq { t.Errorf("eastward deg/s should grow with latitude: eq=%v 60N=%v", dLngEq, dLng60) } } func TestDragTerminalVelocity(t *testing.T) { // Descent is downward (negative) and faster (more negative) at altitude // where the air is thinner. sea := DragTerminalVelocity(5, 0) high := DragTerminalVelocity(5, 20000) if sea >= 0 { t.Errorf("sea-level rate = %v, want negative (downward)", sea) } if high >= sea { t.Errorf("expected faster descent at altitude: sea=%v high=%v", sea, high) } // Sanity: at sea level rho≈1.225, so v ≈ -5*1.1045/sqrt(1.225) ≈ -4.99 m/s. if math.Abs(sea-(-5*1.1045/math.Sqrt(NasaDensity(0)))) > 1e-12 { t.Errorf("sea-level formula mismatch: %v", sea) } }