v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/util/slice/chunk_test.go (about)

     1  package slice
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestChunk(t *testing.T) {
     9  	type args struct {
    10  		array []int
    11  		size  int
    12  	}
    13  	tests := []struct {
    14  		name string
    15  		args args
    16  		want [][]int
    17  	}{
    18  		{
    19  			name: "TestChunk-3-10",
    20  			args: args{
    21  				array: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
    22  				size:  3,
    23  			},
    24  			want: [][]int{
    25  				{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10},
    26  			},
    27  		},
    28  		{
    29  			name: "TestChunk-3-9",
    30  			args: args{
    31  				array: []int{1, 2, 3, 4, 5, 6, 7, 8, 9},
    32  				size:  3,
    33  			},
    34  			want: [][]int{
    35  				{1, 2, 3}, {4, 5, 6}, {7, 8, 9},
    36  			},
    37  		},
    38  		{
    39  			name: "TestChunk-3-8",
    40  			args: args{
    41  				array: []int{1, 2, 3, 4, 5, 6, 7, 8},
    42  				size:  3,
    43  			},
    44  			want: [][]int{
    45  				{1, 2, 3}, {4, 5, 6}, {7, 8},
    46  			},
    47  		},
    48  		{
    49  			name: "TestChunk-3-7",
    50  			args: args{
    51  				array: []int{1, 2, 3, 4, 5, 6, 7},
    52  				size:  3,
    53  			},
    54  			want: [][]int{
    55  				{1, 2, 3}, {4, 5, 6}, {7},
    56  			},
    57  		},
    58  		{
    59  			name: "TestChunk-0-0",
    60  			args: args{
    61  				array: []int{},
    62  				size:  0,
    63  			},
    64  			want: nil,
    65  		},
    66  		{
    67  			name: "TestChunk-1-0",
    68  			args: args{
    69  				array: []int{},
    70  				size:  1,
    71  			},
    72  			want: [][]int{},
    73  		},
    74  	}
    75  	for _, tt := range tests {
    76  		t.Run(tt.name, func(t *testing.T) {
    77  			if got := Chunk(tt.args.array, tt.args.size); !reflect.DeepEqual(got, tt.want) {
    78  				t.Errorf("Chunk() = %v, want %v", got, tt.want)
    79  			}
    80  		})
    81  	}
    82  }