@@ -2,6 +2,7 @@ local array = import '../array.libsonnet';
22local test = import 'github.com/jsonnet-libs/testonnet/main.libsonnet' ;
33
44local arr = std.range (0 , 10 );
5+ local mixedArr = ['a' , 1 , 'b' , 2 , 'c' , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' , 'j' ];
56
67test.new(std.thisFile )
78
@@ -81,3 +82,32 @@ test.new(std.thisFile)
8182 expected=[0 , 2 , 4 ],
8283 )
8384)
85+
86+ + test.case.new(
87+ name='chunkArray' ,
88+ test=test.expect.eq(
89+ actual=array.chunkArray(mixedArr, maxSize=3 ),
90+ expected=[['a' , 1 , 'b' ], [2 , 'c' , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ], ['d' , 'e' , 'f' ], ['g' , 'h' , 'i' ], ['j' ]],
91+ )
92+ )
93+ + test.case.new(
94+ name='chunkArray - maxSize is 2' ,
95+ test=test.expect.eq(
96+ actual=array.chunkArray(mixedArr, maxSize=2 ),
97+ expected=[['a' , 1 ], ['b' , 2 ], ['c' , 3 ], [4 , 5 ], [6 , 7 ], [8 , 9 ], ['d' , 'e' ], ['f' , 'g' ], ['h' , 'i' ], ['j' ]],
98+ )
99+ )
100+ + test.case.new(
101+ name='chunkArray - maxSize is larger than array length' ,
102+ test=test.expect.eq(
103+ actual=array.chunkArray(mixedArr, maxSize=100 ),
104+ expected=[mixedArr],
105+ )
106+ )
107+ + test.case.new(
108+ name='chunkArray - maxSize is 1' ,
109+ test=test.expect.eq(
110+ actual=array.chunkArray(mixedArr, maxSize=1 ),
111+ expected=[['a' ], [1 ], ['b' ], [2 ], ['c' ], [3 ], [4 ], [5 ], [6 ], [7 ], [8 ], [9 ], ['d' ], ['e' ], ['f' ], ['g' ], ['h' ], ['i' ], ['j' ]],
112+ )
113+ )
0 commit comments