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

/* Basic functions for testing */
double_func : x -> x * 2;
square_func : x -> x * x;
add_func : x y -> x + y;
isPositive : x -> x > 0;

/* Map function */
mapped1 : map @double_func 5;
mapped2 : map @square_func 3;

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

/* Compose function */
composed : compose @double_func @square_func 3;
..assert composed = 18;

/* Pipe function */
piped : pipe @double_func @square_func 2;
..assert piped = 16;

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

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

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

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

..out "Standard library test completed";