home *** CD-ROM | disk | FTP | other *** search
- ***
- * Asrtdemo.prg
- * Sample program to demostrate assertions for error checking.
- * Copyright (c) 1990 Nantucket Corp. All rights reserved.
- *
- *
- * Assertions are used to verify conditions that must be true
- * for a function to work (or to verify that a function has
- * worked). This simple test program takes two integers as
- * command line parameters. It compares them numerically and
- * displays a symbol representing the relationship between
- * them. The function uses assertions to verify that the
- * command line parameters are present and that they are
- * valid integer values.
- *
- * Note: compile with /n
- *
-
- #include "Assert.ch"
-
-
-
- ***
- * AssertTest()
- * Convert parameters to numeric values and show the
- * relationship between them.
- *
- PROCEDURE AssertTest(p1, p2)
-
- LOCAL n
-
-
- // fail if 2 params were not supplied
- ASSERT ( PCOUNT() == 2, "requires two params" )
-
- // fail if params don't begin with numeric characters
- ASSERT ( ISDIGIT(p1) .AND. ISDIGIT(p2) )
-
-
- // everything looks good, compare the values
- n = Val(p1) - Val(p2)
-
- IF (n == 0)
- ?? "="
-
- ELSEIF (n > 0)
- ?? ">"
-
- ELSEIF (n < 0)
- ?? "<"
-
- ELSE
- // something must have gone haywire, force a failure
- ASSERT ( .F., "this can't happen but it did" )
-
- END
-