about summary refs log tree commit diff stats
path: root/js/scripting-lang/tests/10_standard_library.txt
blob: e6f7160a0a0a66ad0fb89d2b380ed8bc2b4b4315 (plain) (blame)
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
/* Unit Test: Standard Library */
/* Tests: All built-in higher-order functions */

/* Basic functions for testing */
double : x -> x * 2;
square : x -> x * x;
add : x y -> x + y;
isPositive : x -> x > 0;

/* Filter function - TESTING FAILING CASE */
filtered1 : filter @isPositive 5;
filtered2 : filter @isPositive -3;

..out "filtered1 = ";
..out filtered1;
..out "filtered2 = ";
..out filtered2;

/* Map function */
mapped1 : map @double 5;
mapped2 : map @square 3;

..assert mapped1 = 10;
..assert mapped2 = 9;

/* Compose function */
composed : compose @double @square 3;
..assert composed = 18;

/* Pipe function */
piped : pipe @double @square 2;
..assert piped = 16;

/* Apply function */
applied : apply @double 7;
..assert applied = 14;

/* Reduce and Fold functions */
reduced : reduce @add 0 5;
folded : fold @add 0 5;

..assert reduced = 5;
..assert folded = 5;

/* Curry function */
curried : curry @add 3 4;
..assert curried = 7;

..out "Standard library test completed";