forked from Uniswap/interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchunkArray.test.ts
More file actions
32 lines (29 loc) · 887 Bytes
/
Copy pathchunkArray.test.ts
File metadata and controls
32 lines (29 loc) · 887 Bytes
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
import chunkArray from './chunkArray'
describe('#chunkArray', () => {
it('size 1', () => {
expect(chunkArray([1, 2, 3], 1)).toEqual([[1], [2], [3]])
})
it('size 0 throws', () => {
expect(() => chunkArray([1, 2, 3], 0)).toThrow('maxChunkSize must be gte 1')
})
it('size gte items', () => {
expect(chunkArray([1, 2, 3], 3)).toEqual([[1, 2, 3]])
expect(chunkArray([1, 2, 3], 4)).toEqual([[1, 2, 3]])
})
it('size exact half', () => {
expect(chunkArray([1, 2, 3, 4], 2)).toEqual([
[1, 2],
[3, 4]
])
})
it('evenly distributes', () => {
const chunked = chunkArray([...Array(100).keys()], 40)
expect(chunked).toEqual([
[...Array(34).keys()],
[...Array(34).keys()].map(i => i + 34),
[...Array(32).keys()].map(i => i + 68)
])
expect(chunked[0][0]).toEqual(0)
expect(chunked[2][31]).toEqual(99)
})
})