-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestHelper.java
More file actions
26 lines (22 loc) · 792 Bytes
/
TestHelper.java
File metadata and controls
26 lines (22 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* TestHelper.java */
/**
* The purpose of this class is to provide a shorthand for writing and testing
* invariants in any program.
**/
public class TestHelper {
/**
* verify() checks an invariant and prints an error message if it fails.
* If invariant is true, this method does nothing. If invariant is false,
* the message is printed, followed by a dump of the program stack.
*
* @param invariant the condition to be verified
* @param message the error message to be printed if the invariant fails to
* hold true.
**/
static void verify(boolean invariant, String message) {
if (!invariant) {
System.out.println("*** ERROR: " + message);
Thread.dumpStack();
}
}
}