Test migration to jest by hand
Apparently using regular expressions is way easier.
This commit is contained in:
6
test/uncurry/uncurry.js
Normal file
6
test/uncurry/uncurry.js
Normal file
@ -0,0 +1,6 @@
|
||||
const uncurry = (fn, n = 1) => (...args) => {
|
||||
const next = acc => args => args.reduce((x, y) => x(y), acc);
|
||||
if (n > args.length) throw new RangeError('Arguments too few!');
|
||||
return next(fn)(args.slice(0, n));
|
||||
};
|
||||
module.exports = uncurry;
|
||||
16
test/uncurry/uncurry.test.js
Normal file
16
test/uncurry/uncurry.test.js
Normal file
@ -0,0 +1,16 @@
|
||||
const expect = require('expect');
|
||||
const uncurry = require('./uncurry.js');
|
||||
|
||||
|
||||
test('uncurry is a Function', () => {
|
||||
expect(uncurry).toBeInstanceOf(Function);
|
||||
});
|
||||
const add = x => y => z => x + y + z;
|
||||
const add1 = uncurry(add);
|
||||
const add2 = uncurry(add, 2);
|
||||
const add3 = uncurry(add, 3);
|
||||
t.equal(add1(1)(2)(3), 6, 'Works without a provided value for n');
|
||||
t.equal(add2(1,2)(3), 6, 'Works without n = 2');
|
||||
t.equal(add3(1,2,3), 6, 'Works withoutn = 3');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user