int_test.go 965 B

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