slice_test.go 760 B

1234567891011121314151617181920212223242526
  1. package slice
  2. import "testing"
  3. func TestRemoveRepeatElement(t *testing.T) {
  4. strSlice := []string{"1", "2", "1", "3", "2", "4", "3"}
  5. intSlice := []int{1, 2, 1, 3, 2, 4, 3}
  6. strSliceRemovedRepeatElement := RemoveRepeatElement(strSlice)
  7. if strSliceRemovedRepeatElement[0] != "1" ||
  8. strSliceRemovedRepeatElement[1] != "2" ||
  9. strSliceRemovedRepeatElement[2] != "3" ||
  10. strSliceRemovedRepeatElement[3] != "4" {
  11. t.Fatal("字符串slice移除元素后不正确")
  12. }
  13. intSliceRemovedRepeatElement := RemoveRepeatElement(intSlice)
  14. if intSliceRemovedRepeatElement[0] != 1 ||
  15. intSliceRemovedRepeatElement[1] != 2 ||
  16. intSliceRemovedRepeatElement[2] != 3 ||
  17. intSliceRemovedRepeatElement[3] != 4 {
  18. t.Fatal("整型slice移除元素后不正确")
  19. }
  20. }