package mathext import ( "math" "testing" ) func TestSumFloat64HappyPath(t *testing.T) { values := []float64{1.0, 2.0, 3.0, 4.0} expected := 10.0 if got := SumFloat64(values); got != expected { t.Errorf("SumFloat64(%v) = %v, want %v", values, got, expected) } } func TestSumFloat64Empty(t *testing.T) { values := []float64{} if got := SumFloat64(values); got != 0.0 { t.Errorf("SumFloat64(empty) = %v, want 0.0", got) } } func TestSumFloat64Negatives(t *testing.T) { values := []float64{-1.0, -2.0, 3.0} expected := 0.0 if got := SumFloat64(values); got != expected { t.Errorf("SumFloat64(%v) = %v, want %v", values, got, expected) } } func TestAvgFloat64HappyPath(t *testing.T) { values := []float64{2.0, 4.0, 6.0, 8.0} expected := 5.0 if got := AvgFloat64(values); got != expected { t.Errorf("AvgFloat64(%v) = %v, want %v", values, got, expected) } } func TestAvgFloat64SingleValue(t *testing.T) { values := []float64{42.0} expected := 42.0 if got := AvgFloat64(values); got != expected { t.Errorf("AvgFloat64(%v) = %v, want %v", values, got, expected) } } func TestAvgFloat64EmptyReturnsNaN(t *testing.T) { values := []float64{} got := AvgFloat64(values) if !math.IsNaN(got) { t.Errorf("AvgFloat64(empty) = %v, want NaN", got) } } func TestMaxIntFirstLarger(t *testing.T) { if got := Max(5, 3); got != 5 { t.Errorf("Max(5, 3) = %v, want 5", got) } } func TestMaxIntSecondLarger(t *testing.T) { if got := Max(3, 5); got != 5 { t.Errorf("Max(3, 5) = %v, want 5", got) } } func TestMaxIntEqual(t *testing.T) { if got := Max(5, 5); got != 5 { t.Errorf("Max(5, 5) = %v, want 5", got) } } func TestMaxFloat64(t *testing.T) { if got := Max(2.7, 3.1); got != 3.1 { t.Errorf("Max(2.7, 3.1) = %v, want 3.1", got) } } func TestMaxString(t *testing.T) { if got := Max("apple", "banana"); got != "banana" { t.Errorf(`Max("apple", "banana") = %v, want "banana"`, got) } } func TestMax3FirstLargest(t *testing.T) { if got := Max3(10, 5, 3); got != 10 { t.Errorf("Max3(10, 5, 3) = %v, want 10", got) } } func TestMax3MiddleLargest(t *testing.T) { if got := Max3(5, 10, 3); got != 10 { t.Errorf("Max3(5, 10, 3) = %v, want 10", got) } } func TestMax3LastLargest(t *testing.T) { if got := Max3(5, 3, 10); got != 10 { t.Errorf("Max3(5, 3, 10) = %v, want 10", got) } } func TestMax4(t *testing.T) { if got := Max4(1, 5, 3, 7); got != 7 { t.Errorf("Max4(1, 5, 3, 7) = %v, want 7", got) } } func TestMax4FirstLargest(t *testing.T) { if got := Max4(10, 5, 3, 7); got != 10 { t.Errorf("Max4(10, 5, 3, 7) = %v, want 10", got) } } func TestMax4ThirdLargest(t *testing.T) { if got := Max4(1, 5, 100, 7); got != 100 { t.Errorf("Max4(1, 5, 100, 7) = %v, want 100", got) } } func TestMinIntFirstSmaller(t *testing.T) { if got := Min(3, 5); got != 3 { t.Errorf("Min(3, 5) = %v, want 3", got) } } func TestMinIntSecondSmaller(t *testing.T) { if got := Min(5, 3); got != 3 { t.Errorf("Min(5, 3) = %v, want 3", got) } } func TestMinIntEqual(t *testing.T) { if got := Min(5, 5); got != 5 { t.Errorf("Min(5, 5) = %v, want 5", got) } } func TestMinFloat64(t *testing.T) { if got := Min(2.7, 3.1); got != 2.7 { t.Errorf("Min(2.7, 3.1) = %v, want 2.7", got) } } func TestMin3FirstSmallest(t *testing.T) { if got := Min3(1, 5, 10); got != 1 { t.Errorf("Min3(1, 5, 10) = %v, want 1", got) } } func TestMin3MiddleSmallest(t *testing.T) { if got := Min3(5, 1, 10); got != 1 { t.Errorf("Min3(5, 1, 10) = %v, want 1", got) } } func TestMin3LastSmallest(t *testing.T) { if got := Min3(5, 10, 1); got != 1 { t.Errorf("Min3(5, 10, 1) = %v, want 1", got) } } func TestMin4(t *testing.T) { if got := Min4(7, 3, 5, 1); got != 1 { t.Errorf("Min4(7, 3, 5, 1) = %v, want 1", got) } } func TestMin4FirstSmallest(t *testing.T) { if got := Min4(1, 5, 3, 7); got != 1 { t.Errorf("Min4(1, 5, 3, 7) = %v, want 1", got) } } func TestMin4ThirdSmallest(t *testing.T) { if got := Min4(10, 5, 1, 7); got != 1 { t.Errorf("Min4(10, 5, 1, 7) = %v, want 1", got) } } func TestAbsPositiveInt(t *testing.T) { if got := Abs(5); got != 5 { t.Errorf("Abs(5) = %v, want 5", got) } } func TestAbsNegativeInt(t *testing.T) { if got := Abs(-5); got != 5 { t.Errorf("Abs(-5) = %v, want 5", got) } } func TestAbsZeroInt(t *testing.T) { if got := Abs(0); got != 0 { t.Errorf("Abs(0) = %v, want 0", got) } } func TestAbsPositiveFloat64(t *testing.T) { if got := Abs(3.14); got != 3.14 { t.Errorf("Abs(3.14) = %v, want 3.14", got) } } func TestAbsNegativeFloat64(t *testing.T) { if got := Abs(-3.14); got != 3.14 { t.Errorf("Abs(-3.14) = %v, want 3.14", got) } } func TestAbsNegativeFloat32(t *testing.T) { if got := Abs(float32(-2.5)); got != float32(2.5) { t.Errorf("Abs(-2.5) = %v, want 2.5", got) } }