[🤖] Add Unit-Tests
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m34s

This commit is contained in:
2026-04-27 10:46:08 +02:00
parent dad0e3240d
commit 02d6894ec6
116 changed files with 18795 additions and 1 deletions
+59
View File
@@ -0,0 +1,59 @@
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)
}
}