home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database / CLIPR503.W96 / ASRTDEMO.PR_ / ASRTDEMO.PR
Text File  |  1995-06-20  |  2KB  |  63 lines

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