-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunk_test.go
61 lines (58 loc) · 1.28 KB
/
chunk_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package slice
import (
"reflect"
"testing"
)
func TestChunkInts(t *testing.T) {
type args struct {
values []int
length int
}
tests := []struct {
name string
args args
want [][]int
}{
{
name: "chunk_ints_should_succeed",
args: args{values: []int{0, 1, 2, 3, 1, 2, 3, 2, 3}, length: 3},
want: [][]int{{0, 1, 2}, {3, 1, 2}, {3, 2, 3}},
},
{
name: "chunk_ints_with_single_element_shoud_succeed",
args: args{values: []int{0}, length: 3},
want: [][]int{{0}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Chunk(tt.args.values, tt.args.length); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Chunk() = %v, want %v", got, tt.want)
}
})
}
}
func TestChunkStrings(t *testing.T) {
type args struct {
values []string
length int
}
tests := []struct {
name string
args args
want [][]string
}{
{
name: "chunk_strings_should_succeed",
args: args{values: []string{"hello", "g", "o", "1.18", "generics"}, length: 2},
want: [][]string{{"hello", "g"}, {"o", "1.18"}, {"generics"}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Chunk(tt.args.values, tt.args.length); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Chunk() = %v, want %v", got, tt.want)
}
})
}
}