about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--js/b/tests.js25
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
in&id=9a77780158842db6e4aa098f5027e030fc3bd878'>9a777801 ^
762107fd ^
9a777801 ^

de8a15e9 ^

9a777801 ^































91a5f3e1 ^
9a777801 ^


91a5f3e1 ^









5396e24c ^
91a5f3e1 ^










9a777801 ^



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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122