diff options
Diffstat (limited to 'js/scripting-lang/tests/integration_03_functional_programming.txt')
-rw-r--r-- | js/scripting-lang/tests/integration_03_functional_programming.txt | 68 |
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..1d4671e --- /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 : x -> x * 2; +square : x -> x * x; +add1 : x -> x + 1; +identity : x -> x; +isEven : x -> x % 2 = 0; + +/* Function composition */ +composed1 : compose @double @square 3; +composed2 : compose @square @double 2; +composed3 : compose @add1 @double 5; + +..assert composed1 = 18; +..assert composed2 = 16; +..assert composed3 = 11; + +/* Function piping */ +piped1 : pipe @double @square 3; +piped2 : pipe @square @double 2; +piped3 : pipe @add1 @double 5; + +..assert piped1 = 36; +..assert piped2 = 8; +..assert piped3 = 12; + +/* Function application */ +applied1 : apply @double 7; +applied2 : apply @square 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 + "square" then @square + "add1" then @add1 + _ then @identity; + +/* 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 (compose @square @add1) 3; +..assert complex = 32; + +..out "Functional programming integration test completed"; \ No newline at end of file |