go-zero/core/mathx/int_test.go

72 lines
968 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package mathx
import (
"testing"
"github.com/stretchr/testify/assert"
2020-08-08 16:40:10 +08:00
"github.com/tal-tech/go-zero/core/stringx"
2020-07-26 17:09:05 +08:00
)
func TestMaxInt(t *testing.T) {
cases := []struct {
a int
b int
expect int
}{
{
a: 0,
b: 1,
expect: 1,
},
{
a: 0,
b: -1,
expect: 0,
},
{
a: 1,
b: 1,
expect: 1,
},
}
for _, each := range cases {
2020-10-16 10:50:43 +08:00
each := each
2020-07-26 17:09:05 +08:00
t.Run(stringx.Rand(), func(t *testing.T) {
actual := MaxInt(each.a, each.b)
assert.Equal(t, each.expect, actual)
})
}
}
func TestMinInt(t *testing.T) {
cases := []struct {
a int
b int
expect int
}{
{
a: 0,
b: 1,
expect: 0,
},
{
a: 0,
b: -1,
expect: -1,
},
{
a: 1,
b: 1,
expect: 1,
},
}
for _, each := range cases {
t.Run(stringx.Rand(), func(t *testing.T) {
actual := MinInt(each.a, each.b)
assert.Equal(t, each.expect, actual)
})
}
}