/* Unit Test: Performance and Stress Testing */ /* Tests: Large computations, nested functions, complex expressions */ /* Test large arithmetic computations */ large_sum : 0; large_sum : large_sum + 1; large_sum : large_sum + 2; large_sum : large_sum + 3; large_sum : large_sum + 4; large_sum : large_sum + 5; ..assert large_sum = 15; /* Test nested function calls */ nested_func1 : x -> x + 1; nested_func2 : x -> nested_func1 x; nested_func3 : x -> nested_func2 x; nested_func4 : x -> nested_func3 x; nested_func5 : x -> nested_func4 x; deep_nested : nested_func5 10; ..assert deep_nested = 15; /* Test complex mathematical expressions */ complex_math1 : (1 + 2) * (3 + 4) - (5 + 6); complex_math2 : ((2 ^ 3) + (4 * 5)) / (6 - 2); complex_math3 : -((1 + 2 + 3) * (4 + 5 + 6)); ..assert complex_math1 = 10; ..assert complex_math2 = 7; ..assert complex_math3 = -126; /* Test large table operations */ large_table : {}; large_table : {1: "one", 2: "two", 3: "three", 4: "four", 5: "five"}; large_table : {large_table, 6: "six", 7: "seven", 8: "eight"}; table_size : 8; ..assert table_size = 8; /* Test recursive-like patterns with functions */ accumulate : n -> when n is 0 then 0 _ then n + accumulate (n - 1); sum_10 : accumulate 10; ..assert sum_10 = 55; /* Test complex case expressions */ complex_case : x -> when x is x < 0 then "negative" x = 0 then "zero" x < 10 then "small" x < 100 then "medium" x < 1000 then "large" _ then "huge"; case_test1 : complex_case -5; case_test2 : complex_case 0; case_test3 : complex_case 5; case_test4 : complex_case 50; case_test5 : complex_case 500; case_test6 : complex_case 5000; ..assert case_test1 = "negative"; ..assert case_test2 = "zero"; ..assert case_test3 = "small"; ..assert case_test4 = "medium"; ..assert case_test5 = "large"; ..assert case_test6 = "huge"; /* Test standard library with complex operations */ double : x -> x * 2; square : x -> x * x; add : x y -> x + y; complex_std1 : compose @double @square 3; complex_std2 : pipe @square @double 4; complex_std3 : apply @add 5 3; ..assert complex_std1 = 18; ..assert complex_std2 = 32; ..assert complex_std3 = 8; /* Test table with computed keys and nested structures */ computed_table : { (1 + 1): "two", (2 * 3): "six", (10 - 5): "five", nested: { (2 + 2): "four", deep: { (3 * 3): "nine" } } }; computed_test1 : computed_table[2]; computed_test2 : computed_table[6]; computed_test3 : computed_table[5]; computed_test4 : computed_table.nested[4]; computed_test5 : computed_table.nested.deep[9]; ..assert computed_test1 = "two"; ..assert computed_test2 = "six"; ..assert computed_test3 = "five"; ..assert computed_test4 = "four"; ..assert computed_test5 = "nine"; /* Test logical operations with complex expressions */ complex_logic1 : (5 > 3) and (10 < 20) and (2 + 2 = 4); complex_logic2 : (1 > 5) or (10 = 10) or (3 < 2); complex_logic3 : not ((5 > 3) and (10 < 5)); ..assert complex_logic1 = true; ..assert complex_logic2 = true; ..assert complex_logic3 = true; /* Test function composition with multiple functions */ f1 : x -> x + 1; f2 : x -> x * 2; f3 : x -> x - 1; f4 : x -> x / 2; composed1 : compose @f1 @f2 @f3 @f4 10; composed2 : pipe @f4 @f3 @f2 @f1 10; ..assert composed1 = 10; ..assert composed2 = 10; ..out "Performance and stress test completed successfully";