utils_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/stretchr/testify/assert"
  5. "testing"
  6. )
  7. func TestIsContain(t *testing.T) {
  8. ass := assert.New(t)
  9. // test Int
  10. intSlice := []int{1, 2, 3}
  11. ass.Equal(true, IsContain(intSlice, 1))
  12. ass.Equal(false, IsContain(intSlice, 5))
  13. // test String
  14. stringSlice := []string{"1", "2", "3"}
  15. ass.Equal(true, IsContain(stringSlice, "1"))
  16. ass.Equal(false, IsContain(stringSlice, "5"))
  17. // test Map
  18. mapSlice := []map[string]interface{}{{"id": 1}, {"id": 2}}
  19. ass.Equal(true, IsContain(mapSlice, map[string]interface{}{"id": 1}))
  20. ass.Equal(false, IsContain(mapSlice, map[string]interface{}{"id": 3}))
  21. // test Slice
  22. sliceSlice := [][]int{{1, 1, 1}, {2, 2, 2}}
  23. ass.Equal(true, IsContain(sliceSlice, []int{1, 1, 1}))
  24. ass.Equal(false, IsContain(sliceSlice, []int{1, 1, 2}))
  25. //test Struct
  26. type TestStruct struct {
  27. ID int
  28. }
  29. structSlice := []TestStruct{{ID: 1}}
  30. ass.Equal(true, IsContain(structSlice, TestStruct{ID: 1}))
  31. ass.Equal(false, IsContain(structSlice, TestStruct{ID: 2}))
  32. }
  33. func TestCheckMobile(t *testing.T) {
  34. ass := assert.New(t)
  35. ass.Equal(true, CheckMobile("18007097771"))
  36. ass.Equal(true, CheckMobile("19507097771"))
  37. }
  38. func TestRandomOrder(t *testing.T) {
  39. fmt.Println(RandomOrder("10", 2))
  40. }