1 | const assert = require('assert');
|
2 | const {compose, pipe} = require('../fp');
|
3 |
|
4 | const incrementBy = value => data => value + data;
|
5 | const foldBy = value => data => value * data;
|
6 | const rest = value => data => Promise.resolve(data - value);
|
7 |
|
8 | describe('FP', function() {
|
9 | describe('#compose()', function() {
|
10 | it('should return a composed function of right to left', function(){
|
11 | let calc = compose(foldBy(2), incrementBy(1));
|
12 | assert.equal(calc(1),4);
|
13 | });
|
14 | it('should return a composed function that works with promises', async function(){
|
15 | let calc = compose(foldBy(2), rest(1), incrementBy(2));
|
16 | assert.equal(await calc(1),4);
|
17 | });
|
18 | });
|
19 | describe('#pipe()', function() {
|
20 | it('should return a composed function from left to right', function(){
|
21 | let calc = pipe(foldBy(2), incrementBy(1));
|
22 | assert.equal(calc(1),3);
|
23 | });
|
24 | it('should return a composed function that works with promises', async function(){
|
25 | let calc = pipe(foldBy(2), rest(1), incrementBy(2));
|
26 | assert.equal(await calc(1),3);
|
27 | });
|
28 | });
|
29 | });
|