forked from angus-c/just
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (54 loc) · 1.29 KB
/
Copy pathindex.js
File metadata and controls
57 lines (54 loc) · 1.29 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
55
56
57
var test = require('../util/test')(__filename);
var groupBy = require('../../packages/array-group-by');
test('throws if first argument is not an array', function(t) {
t.plan(6);
t.throws(function() {
groupBy({}, function() {});
});
t.throws(function() {
groupBy('hello', function() {});
});
t.throws(function() {
groupBy(/hullo/, function() {});
});
t.throws(function() {
groupBy(null, function() {});
});
t.throws(function() {
groupBy(undefined, function() {});
});
t.throws(function() {
groupBy();
});
t.end();
});
test('throws if second argument is not a function', function(t) {
t.plan(6);
t.throws(function() {
groupBy([], {});
});
t.throws(function() {
groupBy([], []);
});
t.throws(function() {
groupBy([], /hullo/);
});
t.throws(function() {
groupBy([], null);
});
t.throws(function() {
groupBy([], undefined);
});
t.throws(function() {
groupBy([]);
});
t.end();
});
test('should return grouped objects', function(t) {
t.plan(2);
var result1 = groupBy([6.1, 4.2, 6.3], Math.floor);
t.deepEqual(result1, {'4': [4.2], '6': [6.1, 6.3]});
var result2 = groupBy([1, 2, 3, 4, 5, 6, 7, 8], function(i) { return i % 2; });
t.deepEqual(result2, {'0': [2, 4, 6, 8], '1': [1, 3, 5, 7]});
t.end();
});