slices: don't share references to the array in tests
Change-Id: I4c5609ae03f08fe71bacb9e861ff2d4ca788b7e0
Reviewed-on: https://go-review.googlesource.com/c/exp/+/461015
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
diff --git a/slices/sort_test.go b/slices/sort_test.go
index 9a52992..27ff980 100644
--- a/slices/sort_test.go
+++ b/slices/sort_test.go
@@ -19,7 +19,7 @@
var strs = [...]string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***"}
func TestSortIntSlice(t *testing.T) {
- data := ints[:]
+ data := Clone(ints[:])
Sort(data)
if !IsSorted(data) {
t.Errorf("sorted %v", ints)
@@ -28,7 +28,7 @@
}
func TestSortFuncIntSlice(t *testing.T) {
- data := ints[:]
+ data := Clone(ints[:])
SortFunc(data, func(a, b int) bool { return a < b })
if !IsSorted(data) {
t.Errorf("sorted %v", ints)
@@ -37,7 +37,7 @@
}
func TestSortFloat64Slice(t *testing.T) {
- data := float64s[:]
+ data := Clone(float64s[:])
Sort(data)
if !IsSorted(data) {
t.Errorf("sorted %v", float64s)
@@ -47,10 +47,8 @@
func TestSortFloat64SliceWithNaNs(t *testing.T) {
data := float64sWithNaNs[:]
- input := make([]float64, len(float64sWithNaNs))
- for i := range input {
- input[i] = float64sWithNaNs[i]
- }
+ input := Clone(data)
+
// Make sure Sort doesn't panic when the slice contains NaNs.
Sort(data)
// Check whether the result is a permutation of the input.
@@ -64,7 +62,7 @@
}
func TestSortStringSlice(t *testing.T) {
- data := strs[:]
+ data := Clone(strs[:])
Sort(data)
if !IsSorted(data) {
t.Errorf("sorted %v", strs)