v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/fastrand/shuffle_test.go (about)

     1  package fastrand
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestShuffleSlice(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  		ShuffleSlice(in)
    14  		if reflect.DeepEqual(in, in2) {
    15  			t.Errorf("ShuffleSlice(%v) did not shuffle", in)
    16  		}
    17  	})
    18  
    19  	t.Run("strings", func(t *testing.T) {
    20  		in := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}
    21  		in2 := make([]string, len(in))
    22  		copy(in2, in)
    23  		ShuffleSlice(in)
    24  		if reflect.DeepEqual(in, in2) {
    25  			t.Errorf("ShuffleSlice(%v) did not shuffle", in)
    26  		}
    27  	})
    28  }