blob: 1ace68aff0f45c7ea609ba70f7d2cc24c3e4adfb (
plain)
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
|
{ Test for overflow/underflow in loops with implicit and explicit
iterators. }
begin int count;
{ Overflow. }
count := 0;
by 1 while true do count +:= 1 od;
assert (count = max_int);
count := 0;
from max_int do count +:= 1 od;
assert (count = 1);
count := 0;
by max_int do count +:= 1 od;
assert (count = 1);
count := 0;
for i by max_int do count +:= 1 od;
assert (count = 1);
count := 0;
by max_int % 2 do count +:= 1 od;
assert (count = 3);
count := 0;
by max_int - 1 do count +:= 1 od;
assert (count = 2);
{ Underflow. }
count := 0;
by -1 while true do count +:= 1 od;
assert (count = -min_int + 2);
count := 0;
from min_int by -1 do count +:= 1 od;
assert (count = 1);
count := 0;
by min_int do count +:= 1 od;
assert (count = 2);
count := 0;
for i by min_int do count +:= 1 od;
assert (count = 2);
count := 0;
by min_int % 2 do count +:= 1 od;
assert (count = 3);
count := 0;
by min_int + 1 do count +:= 1 od;
assert (count = 2)
end
|