about summary refs log tree commit diff stats
path: root/js/b/tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/b/tests.js')
-rw-r--r--js/b/tests.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/js/b/tests.js b/js/b/tests.js
new file mode 100644
index 0000000..62ebf4a
--- /dev/null
+++ b/js/b/tests.js
@@ -0,0 +1,39 @@
+import b from './b';
+
+// Tests! 
+// pipe
+const addOne = (x) => x + 1;
+const double = (x) => x * 2;
+console.assert(b.pipe(addOne, double)(3) === 8, 'Test for pipe failed');
+
+// compose
+console.assert(b.compose(double, addOne)(3) === 8, 'Test for compose failed');
+
+// identity
+console.assert(b.identity(5) === 5, 'Test for identity failed');
+
+// curry
+const add = (x, y) => x + y;
+const curriedAdd = b.curry(add);
+console.assert(curriedAdd(3)(4) === 7, 'Test for curry failed');
+
+// match
+const matchDigits = b.match()(/\d+/g);
+console.assert(JSON.stringify(matchDigits('a1b2c3')) === JSON.stringify(['1', '2', '3']), 'Test for match failed');
+
+// replace
+const censor = b.replace()(/badword/g, '****');
+console.assert(censor('This is a badword in a sentence.') === 'This is a **** in a sentence.', 'Test for replace failed');
+
+// filter
+const isEven = (x) => x % 2 === 0;
+const filterEvens = b.filter()(isEven);
+console.assert(JSON.stringify(filterEvens([1, 2, 3, 4])) === JSON.stringify([2, 4]), 'Test for filter failed');
+
+// map
+const mapDoubles = b.map()(double);
+console.assert(JSON.stringify(mapDoubles([1, 2, 3])) === JSON.stringify([2, 4, 6]), 'Test for map failed');
+
+// 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]]), 'Test for deepMap failed');
\ No newline at end of file