github.com/go-playground/pkg/v5@v5.29.1/math/min_test.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 package mathext 5 6 import ( 7 "math" 8 "testing" 9 10 . "github.com/go-playground/assert/v2" 11 ) 12 13 func TestMin(t *testing.T) { 14 Equal(t, true, math.IsNaN(Min(math.NaN(), 1))) 15 Equal(t, true, math.IsNaN(Min(1, math.NaN()))) 16 Equal(t, math.Inf(-1), Min(math.Inf(0), math.Inf(-1))) 17 Equal(t, math.Inf(-1), Min(math.Inf(-1), math.Inf(0))) 18 Equal(t, 1.0, Min(1.333, 1.0)) 19 Equal(t, 1.0, Min(1.0, 1.333)) 20 Equal(t, 1, Min(3, 1)) 21 Equal(t, 1, Min(1, 3)) 22 Equal(t, -0, Min(0, -0)) 23 Equal(t, -0, Min(-0, 0)) 24 } 25 26 func BenchmarkMinInf(b *testing.B) { 27 n1 := math.Inf(0) 28 n2 := math.Inf(-1) 29 30 for i := 0; i < b.N; i++ { 31 _ = Min(n1, n2) 32 } 33 } 34 35 func BenchmarkMinNaN(b *testing.B) { 36 n1 := math.Inf(0) 37 n2 := math.NaN() 38 39 for i := 0; i < b.N; i++ { 40 _ = Min(n1, n2) 41 } 42 } 43 44 func BenchmarkMinNumber(b *testing.B) { 45 n1 := 1 46 n2 := 3 47 48 for i := 0; i < b.N; i++ { 49 _ = Min(n1, n2) 50 } 51 }