about summary refs log tree commit diff stats
path: root/js/scripting-lang/tests/integration_03_functional_programming.txt
diff options
context:
space:
mode:
Diffstat (limited to 'js/scripting-lang/tests/integration_03_functional_programming.txt')
-rw-r--r--js/scripting-lang/tests/integration_03_functional_programming.txt68
1 files changed, 68 insertions, 0 deletions
diff --git a/js/scripting-lang/tests/integration_03_functional_programming.txt b/js/scripting-lang/tests/integration_03_functional_programming.txt
new file mode 100644
index 0000000..a0e3668
--- /dev/null
+++ b/js/scripting-lang/tests/integration_03_functional_programming.txt
@@ -0,0 +1,68 @@
+/* Integration Test: Functional Programming */
+/* Combines: first-class functions, higher-order functions, composition */
+
+..out "=== Integration Test: Functional Programming ===";
+
+/* Basic functions */
+double_func : x -> x * 2;
+square_func : x -> x * x;
+add1 : x -> x + 1;
+identity_func : x -> x;
+isEven : x -> x % 2 = 0;
+
+/* Function composition */
+composed1 : compose @double_func @square_func 3;
+composed2 : compose @square_func @double_func 2;
+composed3 : compose @add1 @double_func 5;
+
+..assert composed1 = 18;
+..assert composed2 = 16;
+..assert composed3 = 11;
+
+/* Function piping */
+piped1 : pipe @double_func @square_func 3;
+piped2 : pipe @square_func @double_func 2;
+piped3 : pipe @add1 @double_func 5;
+
+..assert piped1 = 36;
+..assert piped2 = 8;
+..assert piped3 = 12;
+
+/* Function application */
+applied1 : apply @double_func 7;
+applied2 : apply @square_func 4;
+applied3 : apply @add1 10;
+
+..assert applied1 = 14;
+..assert applied2 = 16;
+..assert applied3 = 11;
+
+/* Function selection with case expressions */
+getOperation : type -> 
+  when type is
+    "double" then @double_func
+    "square" then @square_func
+    "add1"   then @add1
+    _        then @identity_func;
+
+/* Test function selection */
+op1 : getOperation "double";
+op2 : getOperation "square";
+op3 : getOperation "add1";
+op4 : getOperation "unknown";
+
+result1 : op1 5;
+result2 : op2 4;
+result3 : op3 7;
+result4 : op4 3;
+
+..assert result1 = 10;
+..assert result2 = 16;
+..assert result3 = 8;
+..assert result4 = 3;
+
+/* Complex functional composition */
+complex : compose @double_func (compose @square_func @add1) 3;
+..assert complex = 32;
+
+..out "Functional programming integration test completed"; 
\ No newline at end of file
ss='alt'>
5f128523 ^
9a31c34f ^
9ba313ab ^

5f128523 ^
1ed9af83 ^
9a31c34f ^

5f128523 ^
9a31c34f ^






1ed9af83 ^
9a31c34f ^


e709c65e ^



1ed9af83 ^
e709c65e ^




1ed9af83 ^
e709c65e ^

4d6b5173 ^


1ed9af83 ^
4d6b5173 ^




1ed9af83 ^
4d6b5173 ^




1ed9af83 ^
4d6b5173 ^




1ed9af83 ^
4d6b5173 ^

5cee5562 ^





e709c65e ^
1ed9af83 ^







5f128523 ^

8e7827df ^
5f128523 ^
9a31c34f ^



5f128523 ^
e709c65e ^




9a31c34f ^

1ed9af83 ^
4d6b5173 ^
1ed9af83 ^



9a31c34f ^
1ed9af83 ^

9a31c34f ^
5f128523 ^
9a31c34f ^

5f128523 ^
9a31c34f ^









5f128523 ^
9a31c34f ^
5f128523 ^
9a31c34f ^







5f128523 ^
9a31c34f ^


5f128523 ^
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185