forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunapply.js
52 lines (44 loc) · 1.33 KB
/
unapply.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('unapply', function() {
it('returns a function which is always passed one argument', function() {
var fn = R.unapply(function() { return arguments.length; });
eq(fn(), 1);
eq(fn('x'), 1);
eq(fn('x', 'y'), 1);
eq(fn('x', 'y', 'z'), 1);
});
it('forwards arguments to decorated function as an array', function() {
var fn = R.unapply(function(xs) { return '[' + xs + ']'; });
eq(fn(), '[]');
eq(fn(2), '[2]');
eq(fn(2, 4), '[2,4]');
eq(fn(2, 4, 6), '[2,4,6]');
});
it('returns a function with length 0', function() {
var fn = R.unapply(R.identity);
eq(fn.length, 0);
});
it('is the inverse of R.apply', function() {
var a, b, c, d, e, f, g, n;
var rand = function() {
return Math.floor(200 * Math.random()) - 100;
};
f = Math.max;
g = R.unapply(R.apply(f));
n = 1;
while (n <= 100) {
a = rand(); b = rand(); c = rand(); d = rand(); e = rand();
eq(f(a, b, c, d, e), g(a, b, c, d, e));
n += 1;
}
f = function(xs) { return '[' + xs + ']'; };
g = R.apply(R.unapply(f));
n = 1;
while (n <= 100) {
a = rand(); b = rand(); c = rand(); d = rand(); e = rand();
eq(f([a, b, c, d, e]), g([a, b, c, d, e]));
n += 1;
}
});
});