forked from simple-statistics/simple-statistics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchunk.test.js
33 lines (30 loc) · 954 Bytes
/
chunk.test.js
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
/* eslint no-shadow: 0 */
const test = require("tap").test;
const ss = require("../dist/simple-statistics.js");
test("chunk", function (t) {
t.test("can get chunks of an array", function (t) {
t.same(ss.chunk([1, 2], 1), [[1], [2]]);
t.same(ss.chunk([1, 2], 2), [[1, 2]]);
t.same(ss.chunk([1, 2, 3, 4], 4), [[1, 2, 3, 4]]);
t.same(ss.chunk([1, 2, 3, 4], 2), [
[1, 2],
[3, 4]
]);
t.same(ss.chunk([1, 2, 3, 4], 3), [[1, 2, 3], [4]]);
t.same(ss.chunk([1, 2, 3, 4, 5, 6, 7], 2), [
[1, 2],
[3, 4],
[5, 6],
[7]
]);
t.same(ss.chunk([], 2), []);
t.throws(function () {
ss.chunk([1, 2], 0);
}, "Throws with zero chunk size");
t.throws(function () {
ss.chunk([1, 2], 1.5);
}, "Throws with non-integer chunk size");
t.end();
});
t.end();
});