10 func generateInput(inputLen int) []string {
12 for i := 0; i < inputLen; i++ {
13 input = append(input, fmt.Sprintf("s%d", i))
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...)
29 if !reflect.DeepEqual(input, inputReconstructedFromResult) {
30 t.Fatal("input != inputReconstructedFromResult")
34 func TestChunkStrings_4_4(t *testing.T) {
35 testChunkStrings(t, 4, 4)
38 func TestChunkStrings_4_1(t *testing.T) {
39 testChunkStrings(t, 4, 1)
42 func TestChunkStrings_1_4(t *testing.T) {
43 testChunkStrings(t, 1, 4)
46 func TestChunkStrings_1000_8(t *testing.T) {
47 testChunkStrings(t, 1000, 8)
50 func TestChunkStrings_1000_9(t *testing.T) {
51 testChunkStrings(t, 1000, 9)
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)
61 func TestShuffleStrings_100(t *testing.T) {
62 testShuffleStrings(t, 100, time.Now().UnixNano())