You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

lo_test.go 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package lo
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func Test_Remove(t *testing.T) {
  7. Convey("删除数组元素", t, func() {
  8. arr := []string{"a", "b", "c"}
  9. arr = Remove(arr, "b")
  10. So(arr, ShouldResemble, []string{"a", "c"})
  11. })
  12. Convey("删除最后一个元素", t, func() {
  13. arr := []string{"a", "b", "c"}
  14. arr = Remove(arr, "c")
  15. So(arr, ShouldResemble, []string{"a", "b"})
  16. })
  17. Convey("删除第一个元素", t, func() {
  18. arr := []string{"a", "b", "c"}
  19. arr = Remove(arr, "a")
  20. So(arr, ShouldResemble, []string{"b", "c"})
  21. })
  22. Convey("删除不存在的元素", t, func() {
  23. arr := []string{"a", "b", "c"}
  24. arr = Remove(arr, "d")
  25. So(arr, ShouldResemble, []string{"a", "b", "c"})
  26. })
  27. }
  28. func Test_ArrayClone(t *testing.T) {
  29. Convey("复制数组", t, func() {
  30. arr := []string{"a", "b", "c"}
  31. arr2 := ArrayClone(arr)
  32. arr2[1] = "a"
  33. So(arr, ShouldResemble, []string{"a", "b", "c"})
  34. So(arr2, ShouldResemble, []string{"a", "a", "c"})
  35. })
  36. Convey("复制出来的数组进行append", t, func() {
  37. arr := []string{"a", "b", "c"}
  38. arr2 := ArrayClone(arr)
  39. arr = append(arr, "d")
  40. arr2 = append(arr2, "c")
  41. So(arr, ShouldResemble, []string{"a", "b", "c", "d"})
  42. So(arr2, ShouldResemble, []string{"a", "b", "c", "c"})
  43. })
  44. }