Simplify MinMax result float checks on test

Signed-off-by: Xabier Larrakoetxea <slok69@gmail.com>
This commit is contained in:
Xabier Larrakoetxea 2019-04-18 20:31:27 +02:00
parent b54694ed12
commit 2ae5ca1dcb
No known key found for this signature in database
GPG Key ID: FDAD7FD8275E1B32
2 changed files with 6 additions and 8 deletions

View File

@ -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 {

View File

@ -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)
}
})
}