sdsu.test
Class Assert

java.lang.Object
  |
  +--sdsu.test.Assert

public final class Assert
extends java.lang.Object

This class is modeled after the ASSERT macro in C/C++. The class has four static methods. The methods are identical. Each method will throw an exception if is arguement is false. A sample use of the assert is:

		Asset.condition( (X > 5 ) && ( Z <= 10 ));
 
This asserts that the condition should be true at this point. If it is not an exception will be thrown. So the program can assume that the condition is true after the above assert.

In C/C++ ASSERT is defined as a macro. Thus the macro can be turned off with a compile switch. This allows the code to contain ASSERTS with out any runtime cost. There is no way in Java to completely eliminate the cost of the Assert calls. Hopefully future compilers will be smart enough to use tricks with classpaths and two versions of this class to "turn off" the Assert calls in productin code without modifing the program source.

See Writing Solid Code by Steve Maguire, pp 13-44 or Object-Oriented Software Construction by Bertrand Meyer, pp 111 - 163 for the use and importance of Assert.

Version:
1.0 30 December 1997
Author:
Roger Whitney (whitney@cs.sdsu.edu)
See Also:
AssertException

Constructor Summary
Assert()
           
 
Method Summary
static void classInvariant(boolean result)
          Throws AssertException if result is false.
static void condition(boolean result)
          Throws AssertException if result is false.
static void postcondition(boolean result)
          Throws AssertException if result is false.
static void precondition(boolean result)
          Throws AssertException if result is false.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Assert

public Assert()
Method Detail

condition

public static void condition(boolean result)
Throws AssertException if result is false. AssertException is runtime exception, when you are not forced to catch it.

precondition

public static void precondition(boolean result)
Throws AssertException if result is false. AssertException is runtime exception, when you are not forced to catch it.

postcondition

public static void postcondition(boolean result)
Throws AssertException if result is false. AssertException is runtime exception, when you are not forced to catch it.

classInvariant

public static void classInvariant(boolean result)
Throws AssertException if result is false. AssertException is runtime exception, when you are not forced to catch it.