-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathgroupBy.test.js
More file actions
54 lines (44 loc) · 1.2 KB
/
groupBy.test.js
File metadata and controls
54 lines (44 loc) · 1.2 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// FIXME: npm test /src/utils/groupBy.test.js
const { _groupBy } = require('./util');
describe('groupBy 테스트', () => {
describe('non-lazy', () => {
it('case: 1, Normal', () => {
const array = [6.1, 4.2, 6.3];
const grouped = _groupBy(array, Math.floor);
expect(grouped).toEqual({ 4: [4.2], 6: [6.1, 6.3] });
});
it('case: 2, Advanced', () => {
const array = [
[1, 'a'],
[2, 'a'],
[2, 'b'],
];
// 두 번째 인자가 index
const [groupedFirstIndex, groupedSecondIndex] = [
_groupBy(array, item => item[0]),
_groupBy(array, item => item[1]),
];
expect(groupedFirstIndex).toEqual({
1: [[1, 'a']],
2: [
[2, 'a'],
[2, 'b'],
],
});
expect(groupedSecondIndex).toEqual({
a: [
[1, 'a'],
[2, 'a'],
],
b: [[2, 'b']],
});
});
it('case: 3, Advanced', () => {
const grouped = _groupBy({ a: 6.1, b: 4.2, c: 6.3 }, Math.floor);
expect(grouped).toEqual({ 4: [4.2], 6: [6.1, 6.3] });
});
});
describe('lazy', () => {
// 여기에 Lazy 테스트 코드를 작성해보자!!!
});
});