diff options
Diffstat (limited to 'js/scripting-lang/tests/13_standard_library_complete.txt')
-rw-r--r-- | js/scripting-lang/tests/13_standard_library_complete.txt | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/js/scripting-lang/tests/13_standard_library_complete.txt b/js/scripting-lang/tests/13_standard_library_complete.txt new file mode 100644 index 0000000..ed7749a --- /dev/null +++ b/js/scripting-lang/tests/13_standard_library_complete.txt @@ -0,0 +1,97 @@ +/* Unit Test: Complete Standard Library */ +/* Tests: All built-in higher-order functions including reduce, fold, curry */ + +/* Basic functions for testing */ +double : x -> x * 2; +square : x -> x * x; +add : x y -> x + y; +isPositive : x -> x > 0; +isEven : x -> x % 2 = 0; + +/* 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; + +/* Filter function */ +filtered1 : filter @isPositive 5; +filtered2 : filter @isPositive -3; + +..assert filtered1 = 5; +..assert filtered2 = 0; + +/* Reduce function */ +reduced : reduce @add 0 5; +..assert reduced = 5; + +/* Fold function */ +folded : fold @add 0 5; +..assert folded = 5; + +/* Curry function */ +curried : curry @add 3 4; +..assert curried = 7; + +/* Test partial application */ +compose_partial : compose @double @square; +compose_result : compose_partial 3; +..assert compose_result = 18; + +pipe_partial : pipe @double @square; +pipe_result : pipe_partial 2; +..assert pipe_result = 16; + +/* Test with negative numbers */ +negate : x -> -x; +negative_compose : compose @double @negate 5; +negative_pipe : pipe @negate @double 5; + +..assert negative_compose = -10; +..assert negative_pipe = -10; + +/* Test with complex functions */ +complex_func : x -> x * x + 1; +complex_compose : compose @double @complex_func 3; +complex_pipe : pipe @complex_func @double 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 : x y -> x * y; +reduced_sum : reduce @add 10 5; +reduced_mult : reduce @multiply 1 5; + +..assert reduced_sum = 15; +..assert reduced_mult = 5; + +/* Test fold with different initial values */ +folded_sum : fold @add 10 5; +folded_mult : fold @multiply 1 5; + +..assert folded_sum = 15; +..assert folded_mult = 5; + +..out "Complete standard library test completed"; \ No newline at end of file |