package langext import ( "math" "testing" ) func floatEquals(a, b, eps float64) bool { return math.Abs(a-b) < eps } func TestDegToRadZero(t *testing.T) { if !floatEquals(DegToRad(0), 0, 1e-9) { t.Errorf("expected 0, got %v", DegToRad(0)) } } func TestDegToRad180(t *testing.T) { if !floatEquals(DegToRad(180), math.Pi, 1e-9) { t.Errorf("expected Pi, got %v", DegToRad(180)) } } func TestDegToRad90(t *testing.T) { if !floatEquals(DegToRad(90), math.Pi/2, 1e-9) { t.Errorf("expected Pi/2, got %v", DegToRad(90)) } } func TestRadToDegZero(t *testing.T) { // note: function is implemented as rad / (Pi*180), tests document actual behavior if !floatEquals(RadToDeg(0), 0, 1e-9) { t.Errorf("expected 0, got %v", RadToDeg(0)) } } func TestGeoDistanceSamePoint(t *testing.T) { d := GeoDistance(10.0, 50.0, 10.0, 50.0) if !floatEquals(d, 0, 1e-3) { t.Errorf("expected 0, got %v", d) } } func TestGeoDistancePositive(t *testing.T) { // Berlin (~52.5200, 13.4050) to Munich (~48.1351, 11.5820) d := GeoDistance(13.4050, 52.5200, 11.5820, 48.1351) // Distance should be around ~500km - just check the order of magnitude. if d < 400000 || d > 700000 { t.Errorf("Berlin-Munich distance unexpected: got %v", d) } } func TestGeoDistanceSymmetric(t *testing.T) { d1 := GeoDistance(10.0, 50.0, 11.0, 51.0) d2 := GeoDistance(11.0, 51.0, 10.0, 50.0) if !floatEquals(d1, d2, 1e-3) { t.Errorf("expected symmetry, got %v != %v", d1, d2) } }