int_test.go 953 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package mathx
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/tal-tech/go-zero/core/stringx"
  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. t.Run(stringx.Rand(), func(t *testing.T) {
  31. actual := MaxInt(each.a, each.b)
  32. assert.Equal(t, each.expect, actual)
  33. })
  34. }
  35. }
  36. func TestMinInt(t *testing.T) {
  37. cases := []struct {
  38. a int
  39. b int
  40. expect int
  41. }{
  42. {
  43. a: 0,
  44. b: 1,
  45. expect: 0,
  46. },
  47. {
  48. a: 0,
  49. b: -1,
  50. expect: -1,
  51. },
  52. {
  53. a: 1,
  54. b: 1,
  55. expect: 1,
  56. },
  57. }
  58. for _, each := range cases {
  59. t.Run(stringx.Rand(), func(t *testing.T) {
  60. actual := MinInt(each.a, each.b)
  61. assert.Equal(t, each.expect, actual)
  62. })
  63. }
  64. }