github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/hack/integration-cli-on-swarm/agent/master/set_test.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "reflect" 6 "testing" 7 "time" 8 ) 9 10 func generateInput(inputLen int) []string { 11 input := []string{} 12 for i := 0; i < inputLen; i++ { 13 input = append(input, fmt.Sprintf("s%d", i)) 14 } 15 16 return input 17 } 18 19 func testChunkStrings(t *testing.T, inputLen, numChunks int) { 20 t.Logf("inputLen=%d, numChunks=%d", inputLen, numChunks) 21 input := generateInput(inputLen) 22 result := chunkStrings(input, numChunks) 23 t.Logf("result has %d chunks", len(result)) 24 inputReconstructedFromResult := []string{} 25 for i, chunk := range result { 26 t.Logf("chunk %d has %d elements", i, len(chunk)) 27 inputReconstructedFromResult = append(inputReconstructedFromResult, chunk...) 28 } 29 if !reflect.DeepEqual(input, inputReconstructedFromResult) { 30 t.Fatal("input != inputReconstructedFromResult") 31 } 32 } 33 34 func TestChunkStrings_4_4(t *testing.T) { 35 testChunkStrings(t, 4, 4) 36 } 37 38 func TestChunkStrings_4_1(t *testing.T) { 39 testChunkStrings(t, 4, 1) 40 } 41 42 func TestChunkStrings_1_4(t *testing.T) { 43 testChunkStrings(t, 1, 4) 44 } 45 46 func TestChunkStrings_1000_8(t *testing.T) { 47 testChunkStrings(t, 1000, 8) 48 } 49 50 func TestChunkStrings_1000_9(t *testing.T) { 51 testChunkStrings(t, 1000, 9) 52 } 53 54 func testShuffleStrings(t *testing.T, inputLen int, seed int64) { 55 t.Logf("inputLen=%d, seed=%d", inputLen, seed) 56 x := generateInput(inputLen) 57 shuffleStrings(x, seed) 58 t.Logf("shuffled: %v", x) 59 } 60 61 func TestShuffleStrings_100(t *testing.T) { 62 testShuffleStrings(t, 100, time.Now().UnixNano()) 63 }