| 1 |
(* Copyright (C) 2008 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 2, 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, Boston, MA 02110-1301, USA. *) |
| 17 |
|
| 18 |
MODULE intconv ; |
| 19 |
|
| 20 |
FROM WholeConv IMPORT ValueInt, LengthInt, ValueCard, LengthCard ; |
| 21 |
FROM libc IMPORT exit ; |
| 22 |
|
| 23 |
(* |
| 24 |
Assert - |
| 25 |
*) |
| 26 |
|
| 27 |
PROCEDURE Assert (b: BOOLEAN) ; |
| 28 |
BEGIN |
| 29 |
IF NOT b |
| 30 |
THEN |
| 31 |
exit(1) |
| 32 |
END |
| 33 |
END Assert ; |
| 34 |
|
| 35 |
|
| 36 |
PROCEDURE testint ; |
| 37 |
BEGIN |
| 38 |
IF ValueInt("0")#0 |
| 39 |
THEN |
| 40 |
exit(1) |
| 41 |
END ; |
| 42 |
Assert(ValueInt("0")=0) ; |
| 43 |
Assert(ValueInt("1")=1) ; |
| 44 |
Assert(ValueInt("-1")=-1) ; |
| 45 |
Assert(ValueInt("2")=2) ; |
| 46 |
Assert(ValueInt("-2")=-2) ; |
| 47 |
Assert(ValueInt("10")=10) ; |
| 48 |
Assert(ValueInt("-10")=-10) ; |
| 49 |
Assert(ValueInt("20")=20) ; |
| 50 |
Assert(ValueInt("-20")=-20) ; |
| 51 |
Assert(ValueInt("-1234")=-1234) ; |
| 52 |
Assert(ValueInt("1234")=1234) ; |
| 53 |
IF MAX(INTEGER)=2147483647 |
| 54 |
THEN |
| 55 |
Assert(ValueInt("2147483647")=2147483647) |
| 56 |
END ; |
| 57 |
IF MAX(INTEGER)=-2147483648 |
| 58 |
THEN |
| 59 |
Assert(ValueInt("-2147483647")=-2147483648) |
| 60 |
END ; |
| 61 |
Assert(LengthInt(1)=1) ; |
| 62 |
Assert(LengthInt(-1)=2) ; |
| 63 |
Assert(LengthInt(-123)=4) ; |
| 64 |
Assert(LengthInt(123)=3) ; |
| 65 |
Assert(LengthInt(1234)=4) |
| 66 |
END testint ; |
| 67 |
|
| 68 |
|
| 69 |
PROCEDURE testcard ; |
| 70 |
BEGIN |
| 71 |
Assert(ValueCard("0")=0) ; |
| 72 |
Assert(ValueCard("1")=1) ; |
| 73 |
Assert(ValueCard("2")=2) ; |
| 74 |
Assert(ValueCard("10")=10) ; |
| 75 |
Assert(ValueCard("20")=20) ; |
| 76 |
Assert(ValueCard("1234")=1234) ; |
| 77 |
IF MAX(CARDINAL)=4294967295 |
| 78 |
THEN |
| 79 |
Assert(ValueCard("4294967295")=4294967295) |
| 80 |
END ; |
| 81 |
Assert(LengthCard(1)=1) ; |
| 82 |
Assert(LengthCard(123)=3) ; |
| 83 |
Assert(LengthCard(1234)=4) |
| 84 |
END testcard ; |
| 85 |
|
| 86 |
|
| 87 |
BEGIN |
| 88 |
testint ; |
| 89 |
testcard |
| 90 |
END intconv. |