diff options
-rw-r--r-- | js/b/tests.js | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/js/b/tests.js b/js/b/tests.js index 5b8ee87..dac9efa 100644 --- a/js/b/tests.js +++ b/js/b/tests.js @@ -4,7 +4,14 @@ import b from './b'; // curry const add = (x, y) => x + y; const curriedAdd = b.curry(add); +const addThree = (x, y, z) => x + y + z; +const curriedAddThree = b.curry(addThree); +const addTen = b.curry(add)(10); console.assert(curriedAdd(3)(4) === 7, 'Unexpected result from curried function'); +console.assert(addThree(1, 2, 3) === 6, 'Unexpected result from addThree(1, 2, 3)'); +console.assert(curriedAddThree(1)(2)(3) === 6, 'Unexpected result from curried function, curriedAddThree(1)(2)(3)'); +console.assert(curriedAddThree(1, 2, 3) === 6, 'Unexpected result from curried function, curriedAddThree(1, 2, 3)'); +console.assert(addTen(5) === 15, 'Unexpected result from curried function, addTen(5)'); // pipe const addOne = (x) => x + 1; @@ -14,6 +21,15 @@ console.assert(b.pipe(addOne, double)(3) === 8, 'Unexpected result from pipe'); // compose console.assert(b.compose(double, addOne)(3) === 8, 'Unexpected result from compose'); +const addTwo = (x) => x + 2; +const half = (x) => x / 2; +const composed = b.compose(addTwo, half); +const piped = b.pipe(addTwo, half); + +console.assert(composed(1) === 2.5, 'Unexpected result from compose, composed'); +console.assert(piped(1) === 1.5, 'Unexpected result from pipe, piped'); + + // identity console.assert(b.identity(5) === 5, 'Unexpected result from identity'); @@ -36,4 +52,11 @@ console.assert(JSON.stringify(mapDoubles([1, 2, 3])) === JSON.stringify([2, 4, 6 // deepMap const nestedArray = [1, [2, [3, 4]], [5, 6]]; -console.assert(JSON.stringify(b.deepMap()(double, nestedArray)) === JSON.stringify([2, [4, [6, 8]], [10, 12]]), 'Unexpected result from deepMap'); \ No newline at end of file +const nestedArray2 = [1, [2, [3, 4]], [5, 6, [7, 8, [9, 10]]]]; +console.assert(JSON.stringify(b.deepMap()(double, nestedArray)) === JSON.stringify([2, [4, [6, 8]], [10, 12]]), 'Unexpected result from deepMap, nestedArray'); +console.assert(JSON.stringify(b.deepMap()(double, nestedArray2)) === JSON.stringify([2, [4, [6, 8]], [10, 12, [14, 16, [18, 20]]]]), 'Unexpected result from deepMap, nestedArray2'); + +const nestedArray3 = [1, [2, [3, 4]], [5, 6, [7, 8, [9, 10]]]]; +const filterLessThanFive = (x) => x < 5; +const deepMapFilterLessThanFive = b.deepMap()(filterLessThanFive, nestedArray3); +console.assert(JSON.stringify(deepMapFilterLessThanFive) === JSON.stringify([true, [true, [true, true]], [false, false, [false, false, [false, false]]]]), 'Unexpected result from deepMap, nestedArray3'); \ No newline at end of file |