mirror of https://github.com/mum4k/termdash.git
Simplify MinMax result float checks on test
Signed-off-by: Xabier Larrakoetxea <slok69@gmail.com>
This commit is contained in:
parent
b54694ed12
commit
2ae5ca1dcb
|
@ -109,7 +109,7 @@ func Round(x float64) float64 {
|
||||||
|
|
||||||
// MinMax returns the smallest and the largest value among the provided values.
|
// MinMax returns the smallest and the largest value among the provided values.
|
||||||
// Returns (0, 0) if there are no 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.
|
// values can be NaN, in this case the function will return NaN as min and max.
|
||||||
func MinMax(values []float64) (min, max float64) {
|
func MinMax(values []float64) (min, max float64) {
|
||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
|
|
|
@ -232,13 +232,11 @@ func TestMinMax(t *testing.T) {
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
t.Run(tc.desc, func(t *testing.T) {
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
gotMin, gotMax := MinMax(tc.values)
|
gotMin, gotMax := MinMax(tc.values)
|
||||||
// Different assertion for NaN cases.
|
if diff := pretty.Compare(tc.wantMin, gotMin); diff != "" {
|
||||||
if (math.IsNaN(tc.wantMin) && !math.IsNaN(gotMin)) ||
|
t.Errorf("MinMax => unexpected min, diff (-want, +got):\n %s", diff)
|
||||||
(math.IsNaN(tc.wantMax) && !math.IsNaN(gotMax)) {
|
}
|
||||||
t.Errorf("MinMax => (%v, %v), want (%v, %v)", gotMin, gotMax, tc.wantMin, tc.wantMax)
|
if diff := pretty.Compare(tc.wantMax, gotMax); diff != "" {
|
||||||
} else if !math.IsNaN(tc.wantMin) && gotMin != tc.wantMin ||
|
t.Errorf("MinMax => unexpected max, diff (-want, +got):\n %s", diff)
|
||||||
!math.IsNaN(tc.wantMax) && gotMax != tc.wantMax {
|
|
||||||
t.Errorf("MinMax => (%v, %v), want (%v, %v)", gotMin, gotMax, tc.wantMin, tc.wantMax)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue