home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a009 / 6.ddi / SAMPLE.LIF / ASRTDEMO.PRG < prev    next >
Encoding:
Text File  |  1991-04-14  |  1.3 KB  |  58 lines

  1. ***
  2. *  Asrtdemo.prg
  3. *  Sample program to demostrate assertions for error checking.
  4. *  Copyright (c) 1990 Nantucket Corp. All rights reserved.
  5. *
  6. *
  7. *  Assertions are used to verify conditions that must be true
  8. *  for a function to work (or to verify that a function has
  9. *  worked). This simple test program takes two integers as
  10. *  command line parameters. It compares them numerically and
  11. *  displays a symbol representing the relationship between
  12. *  them. The function uses assertions to verify that the
  13. *  command line parameters are present and that they are
  14. *  valid integer values.
  15. *
  16. *  Note: compile with /n
  17. *
  18.  
  19. #include "Assert.ch"
  20.  
  21.  
  22.  
  23. ***
  24. *  AssertTest()
  25. *  Convert parameters to numeric values and show the
  26. *  relationship between them.
  27. *
  28. PROCEDURE AssertTest(p1, p2)
  29.  
  30.    LOCAL n
  31.  
  32.  
  33.    // fail if 2 params were not supplied
  34.    ASSERT ( PCOUNT() == 2, "requires two params" )
  35.  
  36.    // fail if params don't begin with numeric characters
  37.    ASSERT ( ISDIGIT(p1) .AND. ISDIGIT(p2) )
  38.  
  39.  
  40.    // everything looks good, compare the values
  41.    n = Val(p1) - Val(p2)
  42.  
  43.    IF (n == 0)
  44.       ?? "="
  45.  
  46.    ELSEIF (n > 0)
  47.       ?? ">"
  48.  
  49.    ELSEIF (n < 0)
  50.       ?? "<"
  51.  
  52.    ELSE
  53.       // something must have gone haywire, force a failure
  54.       ASSERT ( .F., "this can't happen but it did" )
  55.  
  56.    END
  57.  
  58.