All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sdsu.test.Assert

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

public final class Assert
extends 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 Index

 o Assert()

Method Index

 o classInvariant(boolean)
Throws AssertException if result is false.
 o condition(boolean)
Throws AssertException if result is false.
 o postcondition(boolean)
Throws AssertException if result is false.
 o precondition(boolean)
Throws AssertException if result is false.

Constructors

 o Assert
 public Assert()

Methods

 o 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.

 o 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.

 o 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.

 o 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.


All Packages  Class Hierarchy  This Package  Previous  Next  Index