github.com/prebid/prebid-server/v2@v2.18.0/usersync/shuffler_test.go (about)

     1  package usersync
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestShuffler(t *testing.T) {
    10  	testCases := []struct {
    11  		description string
    12  		given       []string
    13  	}{
    14  		{
    15  			description: "Nil",
    16  			given:       nil,
    17  		},
    18  		{
    19  			description: "Empty",
    20  			given:       []string{},
    21  		},
    22  		{
    23  			description: "One",
    24  			given:       []string{"a"},
    25  		},
    26  		{
    27  			// at least 3 elements are required to test the swap logic.
    28  			description: "Many",
    29  			given:       []string{"a", "b", "c"},
    30  		},
    31  	}
    32  
    33  	for _, test := range testCases {
    34  		givenCopy := make([]string, len(test.given))
    35  		copy(givenCopy, test.given)
    36  
    37  		randomShuffler{}.shuffle(test.given)
    38  
    39  		// ignores order of elements. we're testing the swap logic, not the rand shuffle algorithm.
    40  		assert.ElementsMatch(t, givenCopy, test.given, test.description)
    41  	}
    42  }