blob: 09e414d725b8a77cb5e516faa04ea87060733ec7 (
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
|
/* Unit Test: Error Handling and Edge Cases */
/* Tests: Error detection and handling */
/* Test valid operations first to ensure basic functionality */
valid_test : 5 + 3;
..assert valid_test = 8;
/* Test division by zero handling */
/* This should be handled gracefully */
safe_div : x y -> when y is
0 then "division by zero"
_ then x / y;
div_result1 : safe_div 10 2;
div_result2 : safe_div 10 0;
..assert div_result1 = 5;
..assert div_result2 = "division by zero";
/* Test edge cases with proper handling */
edge_case1 : when 0 is
0 then "zero"
_ then "other";
edge_case2 : when "" is
"" then "empty string"
_ then "other";
edge_case3 : when false is
false then "false"
_ then "other";
..assert edge_case1 = "zero";
..assert edge_case2 = "empty string";
..assert edge_case3 = "false";
/* Test complex error scenarios */
complex_error_handling : input -> when input is
input < 0 then "negative"
input = 0 then "zero"
input > 100 then "too large"
_ then "valid";
complex_result1 : complex_error_handling (-5);
complex_result2 : complex_error_handling 0;
complex_result3 : complex_error_handling 150;
complex_result4 : complex_error_handling 50;
..assert complex_result1 = "negative";
..assert complex_result2 = "zero";
..assert complex_result3 = "too large";
..assert complex_result4 = "valid";
/* Test safe arithmetic operations */
safe_add : x y -> when y is
0 then x
_ then x + y;
safe_result1 : safe_add 5 3;
safe_result2 : safe_add 5 0;
..assert safe_result1 = 8;
..assert safe_result2 = 5;
..out "Error handling test completed successfully";
|