package utils import ( "math" "testing" ) func assertVectorsEqual(t *testing.T, got, want []float64) { t.Helper() if len(got) != len(want) { t.Fatalf("length %d, want %d", len(got), len(want)) } for i := range want { if math.Abs(got[i]-want[i]) > 1e-9 { t.Fatalf("index %d = %v, want %v", i, got, want) } } } func TestAverageVector(t *testing.T) { tests := []struct { name string in [][]float64 want []float64 }{ {name: "empty input", in: nil, want: nil}, {name: "empty slice", in: [][]float64{}, want: nil}, {name: "all empty vectors", in: [][]float64{{}, {}, {}}, want: nil}, {name: "single vector", in: [][]float64{{0.4, -0.2}}, want: []float64{0.4, -0.2}}, {name: "multiple vectors", in: [][]float64{{0.1, 0.2}, {0.3, 0.4}}, want: []float64{0.2, 0.3}}, {name: "first vector empty", in: [][]float64{{}, {0.1, 0.2}, {0.3, 0.4}}, want: []float64{0.2, 0.3}}, {name: "trailing empty vectors", in: [][]float64{{0.1, 0.2}, {}, {0.3, 0.4}}, want: []float64{0.2, 0.3}}, {name: "only first valid", in: [][]float64{{}, {}, {0.1, 0.2}}, want: []float64{0.1, 0.2}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := AverageVector(tt.in) if tt.want == nil { if got != nil { t.Fatalf("AverageVector(%v) = %v, want nil", tt.in, got) } return } assertVectorsEqual(t, got, tt.want) }) } }