becker.util
Class Test

java.lang.Object
  extended by becker.util.Test

public class Test
extends Object

Methods to assist in testing code. Example usage:

public static void main(String[] args)
 {  Patron p = new Patron(1001);
    Test.ckEquals("patron ID#", 1001, p.getID());
 }
 
Each method prints a message on the console indicating whether the test passed or failed and what the expected and actual values were compared.

Author:
Byron Weber Becker

Field Summary
static double EPSILON
          The default value for testing doubles for equality.
 
Constructor Summary
Test()
          An instance may be created, but is not required as all the methods are declared static.
 
Method Summary
static void ckEquals(String idString, boolean expected, boolean actual)
          Check two booleans for equality.
static void ckEquals(String idString, char expected, char actual)
          Check two characters for equality.
static void ckEquals(String idString, double expected, double actual)
          Check two doubles for equality, using EPSILON as a tolerance.
static void ckEquals(String idString, double expected, double actual, double epsilon)
          Check two doubles for equality within a specified tolerance.
static void ckEquals(String idString, int expected, int actual)
          Check two integers for equality.
static void ckEquals(String idString, Object expected, Object actual)
          Check two Objects for equality using the .equals method.
static void ckEquals(String idString, String expected, String actual)
          Check two strings for equality.
static void ckEqualsIgnoreCase(String idString, String expected, String actual)
          Check two strings for equality, ignoring any differences in case.
static void ckIdentical(String idString, Object expected, Object actual)
          Check that two Objects are identical using ==.
static void ckIsBetween(String idString, char minExpected, char actual, char maxExpected)
          Check that a char is between a given minimum and maximum.
static void ckIsBetween(String idString, double minExpected, double actual, double maxExpected)
          Check that a double is between a given minimum and maximum.
static void ckIsBetween(String idString, int minExpected, int actual, int maxExpected)
          Check an integer is between a given minimum and maximum.
static void ckIsBetween(String idString, String minExpected, String actual, String maxExpected)
          Check that a String is between a given minimum and maximum.
static void ckIsNotNull(String idString, Object actual)
          Check that a value is not null.
static void ckIsNull(String idString, Object actual)
          Check that a value is null.
static void fail(String idString)
          Indicate that a test failed.
static int getNumErrors()
          Get the number of errors found in this program.
static void pass(String idString)
          Indicate that a test passed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EPSILON

public static final double EPSILON
The default value for testing doubles for equality. If the absolute value of the difference is less than EPSILON, they are deemed to be the 'same'.

See Also:
Constant Field Values
Constructor Detail

Test

public Test()
An instance may be created, but is not required as all the methods are declared static. This is here to enable using the class before class methods are covered.

Method Detail

ckEquals

public static void ckEquals(String idString,
                            int expected,
                            int actual)
Check two integers for equality. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
expected - the value expected for this test
actual - the value actually obtained for this test

ckEquals

public static void ckEquals(String idString,
                            double expected,
                            double actual,
                            double epsilon)
Check two doubles for equality within a specified tolerance. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
expected - the value expected for this test
actual - the value actually obtained for this test
epsilon - the value by which the two doubles are allowed to deviate

ckEquals

public static void ckEquals(String idString,
                            double expected,
                            double actual)
Check two doubles for equality, using EPSILON as a tolerance. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
expected - the value expected for this test
actual - the value actually obtained for this test

ckEquals

public static void ckEquals(String idString,
                            boolean expected,
                            boolean actual)
Check two booleans for equality. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
expected - the value expected for this test
actual - the value actually obtained for this test

ckEquals

public static void ckEquals(String idString,
                            char expected,
                            char actual)
Check two characters for equality. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
expected - the value expected for this test
actual - the value actually obtained for this test

ckEquals

public static void ckEquals(String idString,
                            String expected,
                            String actual)
Check two strings for equality. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
expected - the value expected for this test
actual - the value actually obtained for this test

ckEqualsIgnoreCase

public static void ckEqualsIgnoreCase(String idString,
                                      String expected,
                                      String actual)
Check two strings for equality, ignoring any differences in case. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
expected - the value expected for this test
actual - the value actually obtained for this test

ckEquals

public static void ckEquals(String idString,
                            Object expected,
                            Object actual)
Check two Objects for equality using the .equals method. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
expected - the value expected for this test (not null)
actual - the value actually obtained for this test (not null)

ckIdentical

public static void ckIdentical(String idString,
                               Object expected,
                               Object actual)
Check that two Objects are identical using ==. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
expected - the value expected for this test (not null)
actual - the value actually obtained for this test (not null)

ckIsBetween

public static void ckIsBetween(String idString,
                               int minExpected,
                               int actual,
                               int maxExpected)
Check an integer is between a given minimum and maximum. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
minExpected - the smallest expected value
actual - the actual value obtained for the test
maxExpected - the largest expected value

ckIsBetween

public static void ckIsBetween(String idString,
                               double minExpected,
                               double actual,
                               double maxExpected)
Check that a double is between a given minimum and maximum. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
minExpected - the smallest expected value
actual - the actual value obtained for the test
maxExpected - the largest expected value

ckIsBetween

public static void ckIsBetween(String idString,
                               char minExpected,
                               char actual,
                               char maxExpected)
Check that a char is between a given minimum and maximum. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
minExpected - the smallest expected value
actual - the actual value obtained for the test
maxExpected - the largest expected value

ckIsBetween

public static void ckIsBetween(String idString,
                               String minExpected,
                               String actual,
                               String maxExpected)
Check that a String is between a given minimum and maximum. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
minExpected - the smallest expected value
actual - the actual value obtained for the test
maxExpected - the largest expected value

ckIsNull

public static void ckIsNull(String idString,
                            Object actual)
Check that a value is null. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
actual - the value actually obtained for this test

ckIsNotNull

public static void ckIsNotNull(String idString,
                               Object actual)
Check that a value is not null. Print a message indicating whether the test passed or failed.

Parameters:
idString - a string identifying this test
actual - the value actually obtained for this test

fail

public static void fail(String idString)
Indicate that a test failed.

Parameters:
idString - a string identifying this test

pass

public static void pass(String idString)
Indicate that a test passed.

Parameters:
idString - a string identifying this test

getNumErrors

public static int getNumErrors()
Get the number of errors found in this program.

Returns:
the number of errors