-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
39 lines (34 loc) · 1.26 KB
/
index.test.js
File metadata and controls
39 lines (34 loc) · 1.26 KB
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
const groupArrayElements = require("./index");
describe("groupArrayElements", ()=> {
it("Should split elements into 4 equally sized arrays", ()=> {
const myArray = [1,2,3,4,5,6,7,8];
const groupedInto = 4;
const result = groupArrayElements(myArray, groupedInto);
expect(result.length).toBe(groupedInto);
expect(result[0]).toEqual([1,2]);
expect(result[1]).toEqual([3,4]);
expect(result[2]).toEqual([5,6]);
});
it("Should handle remainder when groups are not equally divisable", ()=> {
const myArray = [1,2,3,4,5];
const groupedInto = 3;
const result = groupArrayElements(myArray, groupedInto);
expect(result.length).toBe(groupedInto);
expect(result[0].length).toEqual(result[1].length);
expect(result[1].length).not.toEqual(result[2].length);
});
it("Should split empty array", ()=> {
const myArray = [];
const groupedInto = 2;
const result = groupArrayElements(myArray, groupedInto);
expect(result.length).toBe(groupedInto);
expect(result[0]).toEqual([]);
expect(result[1]).toEqual([]);
});
it("Should handle negative integers", ()=> {
const myArray = [1,2,3];
const groupedInto = -2;
const result = groupArrayElements(myArray, groupedInto);
expect(result).toEqual([]);
});
})