diff --git a/internal/numbers/numbers.go b/internal/numbers/numbers.go index 76be1aa..e62f346 100644 --- a/internal/numbers/numbers.go +++ b/internal/numbers/numbers.go @@ -109,7 +109,7 @@ func Round(x float64) float64 { // MinMax returns the smallest and the largest value among the provided values. // Returns (0, 0) if there are no values. -// Ignores NaN values. Allowing NaN values could led in a corner case where all +// Ignores NaN values. Allowing NaN values could lead to a corner case where all // values can be NaN, in this case the function will return NaN as min and max. func MinMax(values []float64) (min, max float64) { if len(values) == 0 { diff --git a/internal/numbers/numbers_test.go b/internal/numbers/numbers_test.go index d1bfed0..f5955b5 100644 --- a/internal/numbers/numbers_test.go +++ b/internal/numbers/numbers_test.go @@ -232,13 +232,11 @@ func TestMinMax(t *testing.T) { for _, tc := range tests { t.Run(tc.desc, func(t *testing.T) { gotMin, gotMax := MinMax(tc.values) - // Different assertion for NaN cases. - if (math.IsNaN(tc.wantMin) && !math.IsNaN(gotMin)) || - (math.IsNaN(tc.wantMax) && !math.IsNaN(gotMax)) { - t.Errorf("MinMax => (%v, %v), want (%v, %v)", gotMin, gotMax, tc.wantMin, tc.wantMax) - } else if !math.IsNaN(tc.wantMin) && gotMin != tc.wantMin || - !math.IsNaN(tc.wantMax) && gotMax != tc.wantMax { - t.Errorf("MinMax => (%v, %v), want (%v, %v)", gotMin, gotMax, tc.wantMin, tc.wantMax) + if diff := pretty.Compare(tc.wantMin, gotMin); diff != "" { + t.Errorf("MinMax => unexpected min, diff (-want, +got):\n %s", diff) + } + if diff := pretty.Compare(tc.wantMax, gotMax); diff != "" { + t.Errorf("MinMax => unexpected max, diff (-want, +got):\n %s", diff) } }) }