about summary refs log tree commit diff stats
path: root/js/scripting-lang/c/test_copy.txt
blob: a67bf594323e273fe57f8e2074db043df7b40ef9 (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
/* Integration Test: Pattern Matching */
/* Combines: case expressions, functions, recursion, complex patterns */

..out "=== Integration Test: Pattern Matching ===";

/* Recursive factorial with case expressions */
factorial : n -> 
  when n is
    0 then 1
    _ then n * (factorial (n - 1));

/* Pattern matching with multiple parameters */
classify : x y -> 
  when x y is
    0 0 then "both zero"
    0 _ then "x is zero"
    _ 0 then "y is zero"
    _ _ then when x is
            0 then "x is zero (nested)"
            _ then when y is
                  0 then "y is zero (nested)"
                  _ then "neither zero";

/* Test factorial */
fact5 : factorial 5;
fact3 : factorial 3;

..assert fact5 = 120;
..assert fact3 = 6;

/* Test classification */
test1 : classify 0 0;
test2 : classify 0 5;
test3 : classify 5 0;
test4 : classify 5 5;

..assert test1 = "both zero";
..assert test2 = "x is zero";
..assert test3 = "y is zero";
..assert test4 = "neither zero";

/* Complex nested case expressions */
analyze : x y z -> 
  when x y z is
    0 0 0 then "all zero"
    0 0 _ then "x and y zero"
    0 _ 0 then "x and z zero"
    _ 0 0 then "y and z zero"
    0 _ _ then "only x zero"
    _ 0 _ then "only y zero"
    _ _ 0 then "only z zero"
    _ _ _ then "none zero";

result1 : analyze 0 0 0;
result2 : analyze 0 1 1;
result3 : analyze 1 0 1;
result4 : analyze 1 1 1;

..assert result1 = "all zero";
..assert result2 = "only x zero";
..assert result3 = "only y zero";
..assert result4 = "none zero";

..out "Pattern matching integration test completed";