about summary refs log tree commit diff stats
path: root/js/scripting-lang/tests/15_performance_stress.txt
blob: 0682d3d5b0f8fc718c1af17603884098beb3c7d2 (plain) (blame)
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
/* 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";