1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package mathx
- import (
- "testing"
- "git.i2edu.net/i2/go-zero/core/stringx"
- "github.com/stretchr/testify/assert"
- )
- 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 {
- each := each
- 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)
- })
- }
- }
|