diff options
Diffstat (limited to 'js/scripting-lang/tests')
9 files changed, 174 insertions, 71 deletions
diff --git a/js/scripting-lang/tests/02_arithmetic_operations.txt b/js/scripting-lang/tests/02_arithmetic_operations.txt index 9c6ab37..d4c0648 100644 --- a/js/scripting-lang/tests/02_arithmetic_operations.txt +++ b/js/scripting-lang/tests/02_arithmetic_operations.txt @@ -8,16 +8,16 @@ sum : a + b; diff : a - b; product : a * b; quotient : a / b; -modulo : a % b; -power : a ^ b; +moduloResult : a % b; +powerResult : a ^ b; /* Test results */ ..assert sum = 13; ..assert diff = 7; ..assert product = 30; ..assert quotient = 3.3333333333333335; -..assert modulo = 1; -..assert power = 1000; +..assert moduloResult = 1; +..assert powerResult = 1000; /* Complex expressions with parentheses */ complex1 : (5 + 3) * 2; diff --git a/js/scripting-lang/tests/06_function_definitions.txt b/js/scripting-lang/tests/06_function_definitions.txt index 6ce8677..a34da72 100644 --- a/js/scripting-lang/tests/06_function_definitions.txt +++ b/js/scripting-lang/tests/06_function_definitions.txt @@ -2,18 +2,18 @@ /* Tests: Function syntax, parameters, calls */ /* Basic function definitions */ -add : x y -> x + y; -multiply : x y -> x * y; -double : x -> x * 2; -square : x -> x * x; -identity : x -> x; +add_func : x y -> x + y; +multiply_func : x y -> x * y; +double_func : x -> x * 2; +square_func : x -> x * x; +identity_func : x -> x; /* Test function calls */ -result1 : add 3 4; -result2 : multiply 5 6; -result3 : double 8; -result4 : square 4; -result5 : identity 42; +result1 : add_func 3 4; +result2 : multiply_func 5 6; +result3 : double_func 8; +result4 : square_func 4; +result5 : identity_func 42; /* Test results */ ..assert result1 = 7; @@ -23,8 +23,8 @@ result5 : identity 42; ..assert result5 = 42; /* Test function calls with parentheses */ -result6 : add (3 + 2) (4 + 1); -result7 : multiply (double 3) (square 2); +result6 : add_func (3 + 2) (4 + 1); +result7 : multiply_func (double_func 3) (square_func 2); ..assert result6 = 10; ..assert result7 = 24; diff --git a/js/scripting-lang/tests/10_standard_library.txt b/js/scripting-lang/tests/10_standard_library.txt index e6f7160..6006b59 100644 --- a/js/scripting-lang/tests/10_standard_library.txt +++ b/js/scripting-lang/tests/10_standard_library.txt @@ -2,9 +2,9 @@ /* Tests: All built-in higher-order functions */ /* Basic functions for testing */ -double : x -> x * 2; -square : x -> x * x; -add : x y -> x + y; +double_func : x -> x * 2; +square_func : x -> x * x; +add_func : x y -> x + y; isPositive : x -> x > 0; /* Filter function - TESTING FAILING CASE */ @@ -17,33 +17,33 @@ filtered2 : filter @isPositive -3; ..out filtered2; /* Map function */ -mapped1 : map @double 5; -mapped2 : map @square 3; +mapped1 : map @double_func 5; +mapped2 : map @square_func 3; ..assert mapped1 = 10; ..assert mapped2 = 9; /* Compose function */ -composed : compose @double @square 3; +composed : compose @double_func @square_func 3; ..assert composed = 18; /* Pipe function */ -piped : pipe @double @square 2; +piped : pipe @double_func @square_func 2; ..assert piped = 16; /* Apply function */ -applied : apply @double 7; +applied : apply @double_func 7; ..assert applied = 14; /* Reduce and Fold functions */ -reduced : reduce @add 0 5; -folded : fold @add 0 5; +reduced : reduce @add_func 0 5; +folded : fold @add_func 0 5; ..assert reduced = 5; ..assert folded = 5; /* Curry function */ -curried : curry @add 3 4; +curried : curry @add_func 3 4; ..assert curried = 7; ..out "Standard library test completed"; \ No newline at end of file diff --git a/js/scripting-lang/tests/13_standard_library_complete.txt b/js/scripting-lang/tests/13_standard_library_complete.txt index ed7749a..c73396a 100644 --- a/js/scripting-lang/tests/13_standard_library_complete.txt +++ b/js/scripting-lang/tests/13_standard_library_complete.txt @@ -2,29 +2,29 @@ /* 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; +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 5; -mapped2 : map @square 3; +mapped1 : map @double_func 5; +mapped2 : map @square_func 3; ..assert mapped1 = 10; ..assert mapped2 = 9; /* Compose function */ -composed : compose @double @square 3; +composed : compose @double_func @square_func 3; ..assert composed = 18; /* Pipe function */ -piped : pipe @double @square 2; +piped : pipe @double_func @square_func 2; ..assert piped = 16; /* Apply function */ -applied : apply @double 7; +applied : apply @double_func 7; ..assert applied = 14; /* Filter function */ @@ -35,38 +35,38 @@ filtered2 : filter @isPositive -3; ..assert filtered2 = 0; /* Reduce function */ -reduced : reduce @add 0 5; +reduced : reduce @add_func 0 5; ..assert reduced = 5; /* Fold function */ -folded : fold @add 0 5; +folded : fold @add_func 0 5; ..assert folded = 5; /* Curry function */ -curried : curry @add 3 4; +curried : curry @add_func 3 4; ..assert curried = 7; /* Test partial application */ -compose_partial : compose @double @square; +compose_partial : compose @double_func @square_func; compose_result : compose_partial 3; ..assert compose_result = 18; -pipe_partial : pipe @double @square; +pipe_partial : pipe @double_func @square_func; 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; +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 @complex_func 3; -complex_pipe : pipe @complex_func @double 3; +complex_compose : compose @double_func @complex_func 3; +complex_pipe : pipe @complex_func @double_func 3; ..assert complex_compose = 20; ..assert complex_pipe = 20; @@ -80,16 +80,16 @@ filtered_small : filter @isLarge 5; ..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; +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 10 5; -folded_mult : fold @multiply 1 5; +folded_sum : fold @add_func 10 5; +folded_mult : fold @multiply_func 1 5; ..assert folded_sum = 15; ..assert folded_mult = 5; diff --git a/js/scripting-lang/tests/16_function_composition.txt b/js/scripting-lang/tests/16_function_composition.txt new file mode 100644 index 0000000..cac7ddd --- /dev/null +++ b/js/scripting-lang/tests/16_function_composition.txt @@ -0,0 +1,59 @@ +/* Function Composition Test Suite */ + +/* Test basic function definitions */ +double : x -> x * 2; +add1 : x -> x + 1; +square : x -> x * x; + +/* Test 1: Basic composition with via */ +result1 : double via add1 5; +..out result1; + +/* Test 2: Multiple composition with via */ +result2 : double via add1 via square 3; +..out result2; + +/* Test 3: Function references */ +ref1 : @double; +..out ref1; + +/* Test 4: Function references in composition */ +result3 : @double via @add1 5; +..out result3; + +/* Test 5: Pipe function (binary) */ +result4 : pipe double add1 5; +..out result4; + +/* Test 6: Compose function (binary) */ +result5 : compose double add1 2; +..out result5; + +/* Test 7: Multiple composition with via */ +result6 : square via add1 via double 2; +..out result6; + +/* Test 8: Backward compatibility - arithmetic */ +x : 10; +result7 : x + 5; +..out result7; + +/* Test 9: Backward compatibility - function application */ +result8 : double x; +..out result8; + +/* Test 10: Backward compatibility - nested application */ +result9 : double (add1 x); +..out result9; + +/* Test 11: Backward compatibility - unary operators */ +result10 : -x; +..out result10; + +/* Test 12: Backward compatibility - logical operators */ +result11 : not true; +..out result11; + +/* Test 13: Complex composition chain */ +result12 : square via add1 via double via add1 3; +..out result12; \ No newline at end of file diff --git a/js/scripting-lang/tests/dev_01_simple_test.txt b/js/scripting-lang/tests/dev_01_simple_test.txt new file mode 100644 index 0000000..74edad2 --- /dev/null +++ b/js/scripting-lang/tests/dev_01_simple_test.txt @@ -0,0 +1,9 @@ +/* Simple test for function call parsing */ + +factorial : n -> + when n is + 0 then 1 + _ then n * (factorial (n - 1)); + +result : factorial 5; +..out result; \ No newline at end of file diff --git a/js/scripting-lang/tests/dev_02_test_parser_changes.txt b/js/scripting-lang/tests/dev_02_test_parser_changes.txt new file mode 100644 index 0000000..a4af8bb --- /dev/null +++ b/js/scripting-lang/tests/dev_02_test_parser_changes.txt @@ -0,0 +1,35 @@ +/* Test: Parser Changes */ +/* Tests: Operator expressions are now translated to combinator calls */ + +/* Test arithmetic operations */ +result1 : 3 + 4; +result2 : 10 - 3; +result3 : 5 * 6; +result4 : 20 / 4; +result5 : -7; + +..out result1; +..out result2; +..out result3; +..out result4; +..out result5; + +/* Test comparison operations */ +test1 : 5 = 5; +test2 : 3 != 7; +test3 : 2 < 8; +test4 : 10 > 3; + +..out test1; +..out test2; +..out test3; +..out test4; + +/* Test logical operations */ +logic1 : true and true; +logic2 : false or true; +logic3 : not false; + +..out logic1; +..out logic2; +..out logic3; \ No newline at end of file diff --git a/js/scripting-lang/tests/integration_01_basic_features.txt b/js/scripting-lang/tests/integration_01_basic_features.txt index cb215ab..f669f8a 100644 --- a/js/scripting-lang/tests/integration_01_basic_features.txt +++ b/js/scripting-lang/tests/integration_01_basic_features.txt @@ -4,15 +4,15 @@ ..out "=== Integration Test: Basic Features ==="; /* Define utility functions */ -add : x y -> x + y; -multiply : x y -> x * y; +add_func : x y -> x + y; +multiply_func : x y -> x * y; isEven : x -> x % 2 = 0; isPositive : x -> x > 0; /* Test arithmetic with functions */ -sum : add 10 5; -product : multiply 4 6; -doubled : multiply 2 sum; +sum : add_func 10 5; +product : multiply_func 4 6; +doubled : multiply_func 2 sum; ..assert sum = 15; ..assert product = 24; @@ -30,7 +30,7 @@ negative_test : isPositive -3; ..assert negative_test = false; /* Test complex expressions */ -complex : add (multiply 3 4) (isEven 10 and isPositive 5); +complex : add_func (multiply_func 3 4) (isEven 10 and isPositive 5); ..assert complex = 13; diff --git a/js/scripting-lang/tests/integration_03_functional_programming.txt b/js/scripting-lang/tests/integration_03_functional_programming.txt index 1d4671e..a0e3668 100644 --- a/js/scripting-lang/tests/integration_03_functional_programming.txt +++ b/js/scripting-lang/tests/integration_03_functional_programming.txt @@ -4,33 +4,33 @@ ..out "=== Integration Test: Functional Programming ==="; /* Basic functions */ -double : x -> x * 2; -square : x -> x * x; +double_func : x -> x * 2; +square_func : x -> x * x; add1 : x -> x + 1; -identity : x -> x; +identity_func : x -> x; isEven : x -> x % 2 = 0; /* Function composition */ -composed1 : compose @double @square 3; -composed2 : compose @square @double 2; -composed3 : compose @add1 @double 5; +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 @square 3; -piped2 : pipe @square @double 2; -piped3 : pipe @add1 @double 5; +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 7; -applied2 : apply @square 4; +applied1 : apply @double_func 7; +applied2 : apply @square_func 4; applied3 : apply @add1 10; ..assert applied1 = 14; @@ -40,10 +40,10 @@ applied3 : apply @add1 10; /* Function selection with case expressions */ getOperation : type -> when type is - "double" then @double - "square" then @square + "double" then @double_func + "square" then @square_func "add1" then @add1 - _ then @identity; + _ then @identity_func; /* Test function selection */ op1 : getOperation "double"; @@ -62,7 +62,7 @@ result4 : op4 3; ..assert result4 = 3; /* Complex functional composition */ -complex : compose @double (compose @square @add1) 3; +complex : compose @double_func (compose @square_func @add1) 3; ..assert complex = 32; ..out "Functional programming integration test completed"; \ No newline at end of file |