about summary refs log tree commit diff stats
path: root/js/scripting-lang/baba-yaga-c/tests/13_standard_library_complete.txt
blob: 451dc0a73682e8c29a2e73153df638f8df1e158b (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
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
/* Unit Test: Complete Standard Library */
/* Tests: All built-in higher-order functions including reduce, fold, curry */

/* Basic functions for testing */
double_func : x -> x * 2;
square_func : x -> x * x;
add_func : x y -> x + y;
isPositive : x -> x > 0;
isEven : x -> x % 2 = 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;

/* Filter function */
filtered1 : filter @isPositive 5;
filtered2 : filter @isPositive (-3);

..assert filtered1 = 5;
..assert filtered2 = 0;

/* Reduce function */
reduced : reduce @add_func 0 5;
..assert reduced = 5;

/* Fold function */
folded : fold @add_func 0 5;
..assert folded = 5;

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

/* Test partial application */
compose_partial : compose @double_func @square_func;
compose_result : compose_partial 3;
..assert compose_result = 18;

pipe_partial : pipe @double_func @square_func;
pipe_result : pipe_partial 2;
..assert pipe_result = 16;

/* Test with negative numbers */
negate_func : x -> -x;
negative_compose : compose @double_func @negate_func 5;
negative_pipe : pipe @negate_func @double_func 5;

..assert negative_compose = -10;
..assert negative_pipe = -10;

/* Test with complex functions */
complex_func : x -> x * x + 1;
complex_compose : compose @double_func @complex_func 3;
complex_pipe : pipe @complex_func @double_func 3;

..assert complex_compose = 20;
..assert complex_pipe = 20;

/* Test filter with complex predicates */
isLarge : x -> x > 10;
filtered_large : filter @isLarge 15;
filtered_small : filter @isLarge 5;

..assert filtered_large = 15;
..assert filtered_small = 0;

/* Test reduce with different initial values */
multiply_func : x y -> x * y;
reduced_sum : reduce @add_func 10 5;
reduced_mult : reduce @multiply_func 1 5;

..assert reduced_sum = 15;
..assert reduced_mult = 5;

/* Test fold with different initial values */
folded_sum : fold @add_func 10 5;
folded_mult : fold @multiply_func 1 5;

..assert folded_sum = 15;
..assert folded_mult = 5;

..out "Complete standard library test completed";