github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/base/bmath/max_test.go (about) 1 package bmath 2 3 import ( 4 "math" 5 "math/rand" 6 "strconv" 7 "testing" 8 "time" 9 ) 10 11 func TestMax(t *testing.T) { 12 type args struct { 13 a float64 14 b float64 15 } 16 type ts struct { 17 name string 18 args args 19 want float64 20 } 21 var tests []ts 22 23 rand.Seed(time.Now().Unix()) 24 for i := 0; i < 100; i++ { 25 a := rand.Float64() 26 b := rand.Float64() 27 tests = append(tests, ts{ 28 name: strconv.Itoa(i), 29 args: args{ 30 a: a, 31 b: b, 32 }, 33 want: math.Max(a, b), 34 }) 35 } 36 for _, tt := range tests { 37 t.Run(tt.name, func(t *testing.T) { 38 if got := Max[float64](tt.args.a, tt.args.b); got != tt.want { 39 t.Errorf("Abs() = %v, want %v", got, tt.want) 40 } 41 }) 42 } 43 }