github.com/lingyao2333/mo-zero@v1.4.1/core/mathx/int_test.go (about) 1 package mathx 2 3 import ( 4 "testing" 5 6 "github.com/lingyao2333/mo-zero/core/stringx" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestMaxInt(t *testing.T) { 11 cases := []struct { 12 a int 13 b int 14 expect int 15 }{ 16 { 17 a: 0, 18 b: 1, 19 expect: 1, 20 }, 21 { 22 a: 0, 23 b: -1, 24 expect: 0, 25 }, 26 { 27 a: 1, 28 b: 1, 29 expect: 1, 30 }, 31 } 32 33 for _, each := range cases { 34 each := each 35 t.Run(stringx.Rand(), func(t *testing.T) { 36 actual := MaxInt(each.a, each.b) 37 assert.Equal(t, each.expect, actual) 38 }) 39 } 40 } 41 42 func TestMinInt(t *testing.T) { 43 cases := []struct { 44 a int 45 b int 46 expect int 47 }{ 48 { 49 a: 0, 50 b: 1, 51 expect: 0, 52 }, 53 { 54 a: 0, 55 b: -1, 56 expect: -1, 57 }, 58 { 59 a: 1, 60 b: 1, 61 expect: 1, 62 }, 63 } 64 65 for _, each := range cases { 66 t.Run(stringx.Rand(), func(t *testing.T) { 67 actual := MinInt(each.a, each.b) 68 assert.Equal(t, each.expect, actual) 69 }) 70 } 71 }