structure5
Class Assert

java.lang.Object
  extended by structure5.Assert

public class Assert
extends Object

A library of assertion testing and debugging procedures.

This class of static methods provides basic assertion testing facilities. An assertion is a condition that is expected to be true at a certain point in the code. Each of the assertion-based routines in this class perform a verification of the condition, and do nothing (aside from testing side-effects) if the condition holds. If the condition fails, however, the assertion throws an exception and prints the associated message, that describes the condition that failed. Basic support is provided for testing general conditions, and pre- and postconditions. There is also a facility for throwing a failed condition for code that should not be executed.

Features similar to assertion testing are expected to be incorporated into the Java 2 language beginning in SDK 1.4.

The debugging facilities provide control that is slightly improved over print statements.

Since:
Java Structures, 1st edition

Method Summary
static void condition(boolean test, String message)
          Test a general condition.
static void debug(int level, String message)
          Set up a debugging message at a specific level.
static void debug(String message)
          Set up a level 1 debugging message.
static void debugging()
          Increase the verbosity of the debugging messages.
static int debugLevel(int level)
          Explictly set the debugging level (0 = none)
static void fail(String message)
          Indicate certain failure.
static void invariant(boolean test, String message)
          Test a loop invariant.
static void post(boolean test, String message)
          Test a postcondition.
static void pre(boolean test, String message)
          Test a precondition.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

debugging

public static void debugging()
Increase the verbosity of the debugging messages.


debugLevel

public static int debugLevel(int level)
Explictly set the debugging level (0 = none)

Parameters:
level - the desired level of verosity
Returns:
the old level

debug

public static void debug(String message)
Set up a level 1 debugging message.

Parameters:
message - a string to be printed if debugging level is 1 or more

debug

public static void debug(int level,
                         String message)
Set up a debugging message at a specific level.

Parameters:
level - the level that triggers the printing of message
message - the message to be printed at the desired level

pre

public static void pre(boolean test,
                       String message)
Test a precondition. If the assertion fails the message indicates that a precondition failed. A precondition is something you require to be true for the method to be executed correctly.

Parameters:
test - A boolean expression describing precondition.
message - A string describing precondition.

post

public static void post(boolean test,
                        String message)
Test a postcondition. If the assertion fails, the message indicates that a postcondition failed. A postcondition is something expected to be true after a method invocation, provided the preconditions are met.

Parameters:
test - A boolean expression describing postcondition.
message - A string describing postcondition.

condition

public static void condition(boolean test,
                             String message)
Test a general condition. If the assertion fails, the message indicates that a general condition failed. The condition may be anything that needs to be verified during the course of program execution.

Parameters:
test - A boolean expression describing the condition.
message - A string describing the condition.

invariant

public static void invariant(boolean test,
                             String message)
Test a loop invariant. If the assertion fails, the message indicates that an invariant failed. The condition may be anything that needs to be verified during the course of program execution.

Parameters:
test - A boolean expression describing the condition.
message - A string describing the condition.

fail

public static void fail(String message)
Indicate certain failure. Stops the program with a message indicating why failure occurred.

Parameters:
message - A string describing the reason for failure.