tool_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package tool
  2. import (
  3. "fmt"
  4. "net/url"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestToolSign(t *testing.T) {
  9. var (
  10. params url.Values
  11. )
  12. convey.Convey("Sign", t, func(ctx convey.C) {
  13. query, err := Sign(params)
  14. ctx.Convey("Then err should be nil.query should not be nil.", func(ctx convey.C) {
  15. ctx.So(err, convey.ShouldBeNil)
  16. ctx.So(query, convey.ShouldNotBeNil)
  17. })
  18. })
  19. }
  20. func TestToolDeDuplicationSlice(t *testing.T) {
  21. var (
  22. a = []int64{1, 2}
  23. )
  24. convey.Convey("DeDuplicationSlice", t, func(ctx convey.C) {
  25. b := DeDuplicationSlice(a)
  26. ctx.Convey("Then b should not be nil.", func(ctx convey.C) {
  27. ctx.So(b, convey.ShouldNotBeNil)
  28. })
  29. })
  30. }
  31. func TestToolContainAll(t *testing.T) {
  32. var (
  33. a = []int64{1}
  34. b = []int64{2}
  35. )
  36. convey.Convey("ContainAll", t, func(ctx convey.C) {
  37. p1 := ContainAll(a, b)
  38. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  39. ctx.So(p1, convey.ShouldNotBeNil)
  40. })
  41. })
  42. }
  43. func TestToolContainAtLeastOne(t *testing.T) {
  44. var (
  45. a = []int64{}
  46. b = []int64{}
  47. )
  48. convey.Convey("ContainAtLeastOne", t, func(ctx convey.C) {
  49. p1 := ContainAtLeastOne(a, b)
  50. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  51. ctx.So(p1, convey.ShouldNotBeNil)
  52. })
  53. })
  54. }
  55. func TestToolElementInSlice(t *testing.T) {
  56. var (
  57. a = int64(1)
  58. b = []int64{1, 2}
  59. )
  60. convey.Convey("ElementInSlice", t, func(ctx convey.C) {
  61. p1 := ElementInSlice(a, b)
  62. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  63. ctx.So(p1, convey.ShouldNotBeNil)
  64. })
  65. })
  66. }
  67. func TestToolRandomSliceKeys(t *testing.T) {
  68. var (
  69. start = 0
  70. end = 100
  71. count = 100
  72. seed = int64(100)
  73. )
  74. convey.Convey("RandomSliceKeys", t, func(ctx convey.C) {
  75. p1 := RandomSliceKeys(start, end, count, seed)
  76. fmt.Println(p1)
  77. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  78. ctx.So(len(p1), convey.ShouldBeGreaterThan, 0)
  79. })
  80. })
  81. }