v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/util/slice/shuffle_test.go (about) 1 package slice 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestShuffle(t *testing.T) { 9 t.Run("ints", func(t *testing.T) { 10 in := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} 11 in2 := make([]int, len(in)) 12 copy(in2, in) 13 Shuffle(in) 14 if reflect.DeepEqual(in, in2) { 15 Shuffle(in) 16 } 17 if reflect.DeepEqual(in, in2) { 18 t.Errorf("ShuffleSlice(%v) did not shuffle", in) 19 } 20 }) 21 22 t.Run("strings", func(t *testing.T) { 23 in := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"} 24 in2 := make([]string, len(in)) 25 copy(in2, in) 26 Shuffle(in) 27 if reflect.DeepEqual(in, in2) { 28 Shuffle(in) 29 } 30 if reflect.DeepEqual(in, in2) { 31 t.Errorf("ShuffleSlice(%v) did not shuffle", in) 32 } 33 }) 34 }