2016-06-13 15:23:23 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-06-13 15:23:23 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-06-13 15:23:23 +00:00
|
|
|
*
|
2018-05-11 02:06:46 +00:00
|
|
|
* @format
|
2017-11-02 13:14:11 +00:00
|
|
|
* @emails oncall+react_native
|
2016-06-13 15:23:23 +00:00
|
|
|
*/
|
2018-05-11 02:06:46 +00:00
|
|
|
|
2016-06-13 15:23:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
describe('groupByEveryN', () => {
|
2018-05-10 22:44:52 +00:00
|
|
|
const groupByEveryN = require('groupByEveryN');
|
2016-06-13 15:23:23 +00:00
|
|
|
|
2016-08-09 13:32:41 +00:00
|
|
|
it('should group by with different n', () => {
|
2018-05-11 02:06:46 +00:00
|
|
|
expect(groupByEveryN([1, 2, 3, 4, 5, 6, 7, 8, 9], 1)).toEqual([
|
|
|
|
[1],
|
|
|
|
[2],
|
|
|
|
[3],
|
|
|
|
[4],
|
|
|
|
[5],
|
|
|
|
[6],
|
|
|
|
[7],
|
|
|
|
[8],
|
|
|
|
[9],
|
|
|
|
]);
|
|
|
|
expect(groupByEveryN([1, 2, 3, 4, 5, 6, 7, 8, 9], 2)).toEqual([
|
|
|
|
[1, 2],
|
|
|
|
[3, 4],
|
|
|
|
[5, 6],
|
|
|
|
[7, 8],
|
|
|
|
[9, null],
|
|
|
|
]);
|
|
|
|
expect(groupByEveryN([1, 2, 3, 4, 5, 6, 7, 8, 9], 3)).toEqual([
|
|
|
|
[1, 2, 3],
|
|
|
|
[4, 5, 6],
|
|
|
|
[7, 8, 9],
|
|
|
|
]);
|
|
|
|
expect(groupByEveryN([1, 2, 3, 4, 5, 6, 7, 8, 9], 4)).toEqual([
|
|
|
|
[1, 2, 3, 4],
|
|
|
|
[5, 6, 7, 8],
|
|
|
|
[9, null, null, null],
|
|
|
|
]);
|
2016-06-13 15:23:23 +00:00
|
|
|
});
|
|
|
|
|
2016-08-09 13:32:41 +00:00
|
|
|
it('should fill with null', () => {
|
2018-05-11 02:06:46 +00:00
|
|
|
expect(groupByEveryN([], 4)).toEqual([]);
|
|
|
|
expect(groupByEveryN([1], 4)).toEqual([[1, null, null, null]]);
|
|
|
|
expect(groupByEveryN([1, 2], 4)).toEqual([[1, 2, null, null]]);
|
|
|
|
expect(groupByEveryN([1, 2, 3], 4)).toEqual([[1, 2, 3, null]]);
|
|
|
|
expect(groupByEveryN([1, 2, 3, 4], 4)).toEqual([[1, 2, 3, 4]]);
|
2016-06-13 15:23:23 +00:00
|
|
|
});
|
|
|
|
});
|