| 1 |
(* Copyright (C) 2014 Free Software Foundation, Inc. *) |
| 2 |
(* This file is part of GNU Modula-2. |
| 3 |
|
| 4 |
GNU Modula-2 is free software; you can redistribute it and/or modify it under |
| 5 |
the terms of the GNU General Public License as published by the Free |
| 6 |
Software Foundation; either version 3, or (at your option) any later |
| 7 |
version. |
| 8 |
|
| 9 |
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 |
for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License along |
| 15 |
with gm2; see the file COPYING. If not, write to the Free Software |
| 16 |
Foundation, 51 Franklin Street, Fifth Floor, |
| 17 |
Boston, MA 02110-1301, USA. *) |
| 18 |
|
| 19 |
MODULE For10 ; |
| 20 |
|
| 21 |
FROM libc IMPORT exit, printf ; |
| 22 |
FROM SYSTEM IMPORT ADR ; |
| 23 |
(* FROM EndFor IMPORT CheckCardinalInteger ; *) |
| 24 |
|
| 25 |
CONST |
| 26 |
Check = TRUE ; |
| 27 |
|
| 28 |
VAR |
| 29 |
res: INTEGER ; |
| 30 |
|
| 31 |
PROCEDURE Assert (v: BOOLEAN; f: ARRAY OF CHAR; l: CARDINAL; e: ARRAY OF CHAR) ; |
| 32 |
VAR |
| 33 |
r: INTEGER ; |
| 34 |
BEGIN |
| 35 |
IF v |
| 36 |
THEN |
| 37 |
r := printf("successfully evaluated assertion (%s)\n", ADR(e)) |
| 38 |
ELSE |
| 39 |
r := printf("%s:%d assertion failed when evaluating %s\n", ADR(f), l, ADR(e)) ; |
| 40 |
res := 1 |
| 41 |
END |
| 42 |
END Assert ; |
| 43 |
|
| 44 |
VAR |
| 45 |
c : CARDINAL ; |
| 46 |
n, i, j: CARDINAL ; |
| 47 |
BEGIN |
| 48 |
res := 0 ; |
| 49 |
n := 4 ; |
| 50 |
c := 0 ; |
| 51 |
FOR i := 30000 TO 0 BY -10000 DO |
| 52 |
j := i ; |
| 53 |
Assert(c<5, __FILE__, __LINE__, "for loop executed too many times") ; |
| 54 |
INC(c) ; |
| 55 |
(* |
| 56 |
IF i#0 |
| 57 |
THEN |
| 58 |
CheckCardinalInteger(i, -10000) (* we cannot test when i=0 *) |
| 59 |
END |
| 60 |
*) |
| 61 |
END ; |
| 62 |
Assert(c=4, __FILE__, __LINE__, "for loop executed too few times") ; |
| 63 |
Assert(i=0, __FILE__, __LINE__, "for loop index") ; |
| 64 |
exit(res) |
| 65 |
END For10. |