forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflip.js
36 lines (30 loc) · 1.1 KB
/
flip.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
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
var fc = require('fast-check');
describe('flip', function() {
it('returns a function which inverts the first two arguments to the supplied function', function() {
var f = function(a, b, c) {return a + ' ' + b + ' ' + c;};
var g = R.flip(f);
eq(f('a', 'b', 'c'), 'a b c');
eq(g('a', 'b', 'c'), 'b a c');
});
it('returns a curried function', function() {
var f = function(a, b, c) {return a + ' ' + b + ' ' + c;};
var g = R.flip(f)('a');
eq(g('b', 'c'), 'b a c');
});
it('returns a function with the correct arity', function() {
var f2 = function(a, b) {return a + ' ' + b;};
var f3 = function(a, b, c) {return a + ' ' + b + ' ' + c;};
eq(R.flip(f2).length, 2);
eq(R.flip(f3).length, 3);
});
});
describe('flip properties', function() {
it('inverts first two arguments', function() {
fc.assert(fc.property(fc.func(fc.anything()), fc.anything(), fc.anything(), fc.anything(), function(f, a, b, c) {
var g = R.flip(f);
return R.equals(f(a, b, c), g(b, a, c));
}));
});
});