tester
Class Tester

java.lang.Object
  extended by tester.Tester

public class Tester
extends Object

A test harness that compares arbitrary objects for extensional equality.

It catches exceptions in tests - the remaining tests are omitted.

It uses the visitor pattern to accept test cases.

Displays the data even if no tests are present.

Since:
21 March 2008, 11 June 2008, 24 June 2008, 16 October 2008, 11 November 2008, 23 November 2008, 12 December 2008, 20 January 2009, 18 May 2009, 19 October 2009, 10 November 2009, 16 November 2009, 5 February 2010, 15 March 2010, 12 May 2010, 5 October 2010, 18 February 2011, 5 July 2011, 12 January 2012, 17 June 2012, 20 September 2012
Author:
Viera K. Proulx, Weston Jossey, Shayne Caswell, Sachin Venugopalan Virag Shah

Field Summary
protected  int errors
          the total number of errors
protected  StringBuilder failedResults
          A String that records the results for all failed tests
protected  StringBuilder fullTestResults
          A String that records all test results
protected  int numberOfTests
          the total number of tests
protected  String testname
          the name of the current test
protected  int warnings
          the total number of warnings of inexact comparisons
 
Constructor Summary
Tester()
          start with no tests and no failures
 
Method Summary
<T> boolean
checkConstructorException(Exception e, String className, Object... args)
          Test that verifies that when the constructor for the given class is invoked with the given arguments, it throws the expected exception with the expected message.
<T> boolean
checkConstructorException(String testname, Exception e, String className, Object... args)
          Test that verifies that when the constructor for the given class is invoked with the given arguments, it throws the expected exception with the expected message.
<T> boolean
checkEquivalent(T obj1, T obj2, Equivalence<T> equiv)
          Use the given Equivalence function object to determine the equivalence of the two given objects.
<T> boolean
checkEquivalent(T obj1, T obj2, Equivalence<T> equiv, String testname)
          Use the given Equivalence function object to determine the equivalence of the two given objects.
<T> boolean
checkException(Exception e, T object, String method, Object... args)
          Test that verifies that when the given object invokes the given method with the given arguments, it throws the expected exception with the expected message.
<T> boolean
checkException(String testname, Exception e, T object, String method, Object... args)
          Test that verifies that when the given object invokes the given method with the given arguments, it throws the expected exception with the expected message.
 boolean checkExpect(boolean result)
          Test that only reports success or failure
 boolean checkExpect(boolean result, String testname)
          Test that only reports success or failure
<T> boolean
checkExpect(T actual, T expected)
          Test that compares two objects of any kind -- exact values only
<T> boolean
checkExpect(T actual, T expected, String testname)
          Test that compares two objects of any kind -- exact values only
 boolean checkFail(boolean result)
          Test that only reports success or failure
 boolean checkFail(boolean result, String testname)
          Test that only reports success or failure
<T> boolean
checkFail(T actual, T expected)
          Test that compares two objects of any kind and is expected to fail: comparison failure constitutes a successful test.
<T> boolean
checkFail(T actual, T expected, String testname)
          Test that compares two objects of any kind and is expected to fail: comparison failure constitutes a successful test.
<T> boolean
checkInequivalent(T obj1, T obj2, Equivalence<T> equiv)
          Use the given Equivalence function object to determine the NON-equivalence of the two given objects.
<T> boolean
checkInequivalent(T obj1, T obj2, Equivalence<T> equiv, String testname)
          Use the given Equivalence function object to determine the equivalence of the two given objects.
<T> boolean
checkInexact(T actual, T expected, double tolerance)
          Test that compares two objects of any kind.
<T> boolean
checkInexact(T actual, T expected, double tolerance, String testname)
          Test that compares two objects of any kind.
<T> boolean
checkInexactFail(T actual, T expected, double tolerance)
          Test that compares two objects of any kind and is expected to fail: comparison failure constitutes a successful test.
<T> boolean
checkInexactFail(T actual, T expected, double tolerance, String testname)
          Test that compares two objects of any kind and is expected to fail: comparison failure constitutes a successful test.
<T> boolean
checkInexactIterable(Iterable<T> actual, Iterable<T> expected, double tolerance)
          Test that compares two objects that implement Iterable interface by traversing over the data.
<T> boolean
checkInexactIterable(Iterable<T> actual, Iterable<T> expected, double tolerance, String testname)
          Test that compares two objects that implement Iterable interface by traversing over the data.
<T> boolean
checkInexactMethod(Object expected, double tolerance, T object, String method, Object... args)
          Invoke the method with the given name on a given object with the given arguments - check if it produces the expected value
<T> boolean
checkInexactMethod(String testname, Object expected, double tolerance, T object, String method, Object... args)
          Invoke the method with the given name on a given object with the given arguments - check if it produces the expected value
<T> boolean
checkInexactNoneOf(double tolerance, T actual, T... expected)
          Test that determines whether the value of the given object (of any kind) is not equal to any of the expected results
<T> boolean
checkInexactNoneOf(String testname, double tolerance, T actual, T... expected)
          Test that determines whether the value of the given object (of any kind) is not equal to any of the expected results
<T> boolean
checkInexactOneOf(double tolerance, T actual, T... expected)
          Test that determines whether the value of the given object (of any kind) is the same as one of the expected results
<T> boolean
checkInexactOneOf(String testname, double tolerance, T actual, T... expected)
          Test that determines whether the value of the given object (of any kind) is the same as one of the expected results
<T> boolean
checkInexactTraversal(Traversal<T> actual, Traversal<T> expected, double tolerance)
          Test that compares two objects that implement Traversal interface by traversing over the data.
<T> boolean
checkInexactTraversal(Traversal<T> actual, Traversal<T> expected, double tolerance, String testname)
          Test that compares two objects that implement Traversal interface by traversing over the data.
<T> boolean
checkIterable(Iterable<T> actual, Iterable<T> expected)
          Test that compares two objects that implement Iterable interface by traversing over the data -- objects must be composed of exact values only
<T> boolean
checkIterable(Iterable<T> actual, Iterable<T> expected, String testname)
          Test that compares two objects that implement Iterable interface by traversing over the data -- objects must be composed of exact values only
<T> boolean
checkMethod(Object expected, T object, String method, Object... args)
          Invoke the method with the given name on a given object with the given arguments - check if it produces the expected result
<T> boolean
checkMethod(String testname, Object expected, T object, String method, Object... args)
          Invoke the method with the given name on a given object with the given arguments - check if it produces the expected result
<T> boolean
checkNoneOf(String testname, T actual, T... expected)
          Test that determines whether the value of the given object (of any kind) is not equal to any of the expected results
<T> boolean
checkNoneOf(T actual, T... expected)
          Test that determines whether the value of the given object (of any kind) is not equal to any of the expected results
<T> boolean
checkNumRange(Number actual, Number low, Number high)
          Test that determines whether the value of the given numerical object (of any kind) is the range between low (inclusive) and high (exclusive) values.
<T> boolean
checkNumRange(Number actual, Number low, Number high, boolean lowIncl, boolean highIncl)
          Test that determines whether the value of the given object (of any kind) is the range between low and high values.
<T> boolean
checkNumRange(Number actual, Number low, Number high, boolean lowIncl, boolean highIncl, String testname)
          Test that determines whether the value of the given object (of any kind) is the range between low and high values.
<T> boolean
checkNumRange(Number actual, Number low, Number high, String testname)
          Test that determines whether the value of the given numerical object (of any kind) is the range between low (inclusive) and high (exclusive) values.
<T> boolean
checkOneOf(String testname, T actual, T... expected)
          Test that determines whether the value of the given object (of any kind) is the same as one of the expected results
<T> boolean
checkOneOf(T actual, T... expected)
          Test that determines whether the value of the given object (of any kind) is the same as one of the expected results
<T> boolean
checkRange(Comparable<T> actual, T low, T high)
          Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values
<T> boolean
checkRange(Comparable<T> actual, T low, T high, boolean lowIncl, boolean highIncl)
          Test that determines whether the value of the given object (of any kind) is the range between low and high values.
<T> boolean
checkRange(Comparable<T> actual, T low, T high, boolean lowIncl, boolean highIncl, String testname)
          Test that determines whether the value of the given object (of any kind) is the range between low and high values.
<T> boolean
checkRange(Comparable<T> actual, T low, T high, String testname)
          Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values
<T> boolean
checkRange(T actual, T low, T high, boolean lowIncl, boolean highIncl, Comparator<T> comp)
          Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values
<T> boolean
checkRange(T actual, T low, T high, boolean lowIncl, boolean highIncl, Comparator<T> comp, String testname)
          Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values
<T> boolean
checkRange(T actual, T low, T high, Comparator<T> comp)
          Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values
<T> boolean
checkRange(T actual, T low, T high, Comparator<T> comp, String testname)
          Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values
<T> boolean
checkSet(Set<T> actual, Set<T> expected)
          Test that compares two objects that implement Set interface by comparing data using the equals method for comparing the elements of the two sets.
<T> boolean
checkSet(Set<T> actual, Set<T> expected, String testname)
          Test that compares two objects that implement Set interface by comparing data using the equals method for comparing the elements of the two sets.
<T> boolean
checkTraversal(Traversal<T> actual, Traversal<T> expected)
          Test that compares two objects that implement Traversal interface by traversing over the data -- objects must be composed of exact values only
<T> boolean
checkTraversal(Traversal<T> actual, Traversal<T> expected, String testname)
          Test that compares two objects that implement Traversal interface by traversing over the data -- objects must be composed of exact values only
protected  void done(boolean failed)
          If the test evaluation terminated due to an exception, report the test that threw the exception..
 boolean fail()
          Test nothing, just report failure.
 boolean fail(String testname)
          Test nothing, just report failure.
protected  void fullTestReport()
          Produce test names and values compared for all tests
static boolean run(Object obj)
          A hook to run the tester for any object --- needed to run from BlueJ.
protected  void runAnyTests(Object f)
          Find all test methods in the class of the given object; run tests and report results.
protected  void runAnyTests(Object f, boolean full)
          Find all test methods in the class of the given object; run tests and report results.
protected  void runAnyTests(Object f, boolean full, boolean printall)
          Find all test methods in the class of the given object; run tests and report results.
static boolean runFullReport(Object... objs)
          A hook to run the tester for a collection of objects and produce a full test report
static boolean runReport(Object obj, boolean full, boolean printall)
          A hook to run the tester for any object and produce a test report.
static boolean runReports(boolean full, boolean printall, Object... objs)
          A hook to run the tester for a collection of objects and produce the specified test reports
protected  void runTests(IExamples f, boolean full, boolean printall)
          Run the tests, accept the class to be tested as a visitor
 boolean same(Object obj1, Object obj2)
          Provide a general extensional equality comparison for arbitrary pair of objects
protected  boolean setTolerance(double epsilon)
          Set the relative tolerance for the comparison of inexact numbers
 boolean success()
          Test nothing, just report success.
 boolean success(String testname)
          Test nothing, just report success.
protected  void testReport()
          Report on the number and nature of failed tests
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

errors

protected int errors
the total number of errors


failedResults

protected StringBuilder failedResults
A String that records the results for all failed tests


fullTestResults

protected StringBuilder fullTestResults
A String that records all test results


numberOfTests

protected int numberOfTests
the total number of tests


testname

protected String testname
the name of the current test


warnings

protected int warnings
the total number of warnings of inexact comparisons

Constructor Detail

Tester

public Tester()
start with no tests and no failures

Method Detail

checkConstructorException

public <T> boolean checkConstructorException(Exception e,
                                             String className,
                                             Object... args)

Test that verifies that when the constructor for the given class is invoked with the given arguments, it throws the expected exception with the expected message.

Parameters:
e - An instance of the expected exception -- including the expected message
className - the name of the class whose constructor is tested
args - An Ellipsis of arguments for the method
Returns:
true if the test succeeds

checkConstructorException

public <T> boolean checkConstructorException(String testname,
                                             Exception e,
                                             String className,
                                             Object... args)

Test that verifies that when the constructor for the given class is invoked with the given arguments, it throws the expected exception with the expected message.

Parameters:
testname - The description of this test
e - An instance of the expected exception -- including the expected message
className - the name of the class whose constructor is tested
args - An Ellipsis of arguments for the method
Returns:
true if the test succeeds

checkEquivalent

public <T> boolean checkEquivalent(T obj1,
                                   T obj2,
                                   Equivalence<T> equiv)
Use the given Equivalence function object to determine the equivalence of the two given objects.

Parameters:
obj1 - the first object to compare
obj2 - the second object to compare
equiv - the function object that implements the Equivalence comparison
Returns:
true if the two objects are equivalent

checkEquivalent

public <T> boolean checkEquivalent(T obj1,
                                   T obj2,
                                   Equivalence<T> equiv,
                                   String testname)
Use the given Equivalence function object to determine the equivalence of the two given objects.

Parameters:
obj1 - the first object to compare
obj2 - the second object to compare
equiv - the function object that implements the Equivalence comparison
testname - the String that describes this test
Returns:
true if the two objects are equivalent

checkException

public <T> boolean checkException(Exception e,
                                  T object,
                                  String method,
                                  Object... args)

Test that verifies that when the given object invokes the given method with the given arguments, it throws the expected exception with the expected message.

Type Parameters:
T - The type of the object that invokes the given method
Parameters:
object - The object that invokes the method to be tested
method - The name of the method to test
e - An instance of the expected exception -- including the expected message
args - An Ellipsis of arguments for the method
Returns:
true if the test succeeds

checkException

public <T> boolean checkException(String testname,
                                  Exception e,
                                  T object,
                                  String method,
                                  Object... args)

Test that verifies that when the given object invokes the given method with the given arguments, it throws the expected exception with the expected message.

Type Parameters:
T - The type of the object that invokes the given method
Parameters:
testname - The description of this test
e - An instance of the expected exception -- including the expected message
object - The object that invokes the method to be tested
method - The name of the method to test
args - An Ellipsis of arguments for the method
Returns:
true if the test succeeds

checkExpect

public boolean checkExpect(boolean result)
Test that only reports success or failure

Parameters:
result - the test result
Returns:
true if the test succeeds

checkExpect

public boolean checkExpect(boolean result,
                           String testname)
Test that only reports success or failure

Parameters:
testname - the name of this test
result - the test result
Returns:
true if the test succeeds

checkExpect

public <T> boolean checkExpect(T actual,
                               T expected)
Test that compares two objects of any kind -- exact values only

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected value of the type T
Returns:
true if the test succeeds

checkExpect

public <T> boolean checkExpect(T actual,
                               T expected,
                               String testname)
Test that compares two objects of any kind -- exact values only

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected value of the type T
testname - the name of this test
Returns:
true if the test succeeds

checkFail

public boolean checkFail(boolean result)
Test that only reports success or failure

Parameters:
result - the test result that should fail
Returns:
true if the test fails

checkFail

public boolean checkFail(boolean result,
                         String testname)
Test that only reports success or failure

Parameters:
result - the test result that should fail
Returns:
true if the test fails

checkFail

public <T> boolean checkFail(T actual,
                             T expected)

Test that compares two objects of any kind and is expected to fail: comparison failure constitutes a successful test.

Assumes all values that are compared are exact.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected value of the type T
Returns:
true if the test fails

checkFail

public <T> boolean checkFail(T actual,
                             T expected,
                             String testname)

Test that compares two objects of any kind and is expected to fail: comparison failure constitutes a successful test.

Assumes all values that are compared are exact.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected value of the type T
testname - the name of this test
Returns:
true if the test fails

checkInequivalent

public <T> boolean checkInequivalent(T obj1,
                                     T obj2,
                                     Equivalence<T> equiv)
Use the given Equivalence function object to determine the NON-equivalence of the two given objects.

Parameters:
obj1 - the first object to compare
obj2 - the second object to compare
equiv - the function object that implements the Equivalence comparison
Returns:
true if the two objects are equivalent

checkInequivalent

public <T> boolean checkInequivalent(T obj1,
                                     T obj2,
                                     Equivalence<T> equiv,
                                     String testname)
Use the given Equivalence function object to determine the equivalence of the two given objects.

Parameters:
obj1 - the first object to compare
obj2 - the second object to compare
equiv - the function object that implements the Equivalence comparison
testname - the String that describes this test
Returns:
true if the two objects are equivalent

checkInexact

public <T> boolean checkInexact(T actual,
                                T expected,
                                double tolerance)

Test that compares two objects of any kind.

The objects can contain inexact values (of the types double or float). These will be compared within the given relative tolerance. The relative tolerance used in the comparison will appear on the test report.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected value of the type T
tolerance - the desired relative tolerance
Returns:
true if the test succeeds

checkInexact

public <T> boolean checkInexact(T actual,
                                T expected,
                                double tolerance,
                                String testname)

Test that compares two objects of any kind.

The objects can contain inexact values (of the types double or float). These will be compared within the given relative tolerance. The relative tolerance used in the comparison will appear on the test report.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected value of the type T
tolerance - the desired relative tolerance
testname - the name of this test
Returns:
true if the test succeeds

checkInexactFail

public <T> boolean checkInexactFail(T actual,
                                    T expected,
                                    double tolerance)

Test that compares two objects of any kind and is expected to fail: comparison failure constitutes a successful test.

Allows comparison of inexact values.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected value of the type T
Returns:
true if the test fails

checkInexactFail

public <T> boolean checkInexactFail(T actual,
                                    T expected,
                                    double tolerance,
                                    String testname)

Test that compares two objects of any kind and is expected to fail: comparison failure constitutes a successful test.

Allows comparison of inexact values.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected value of the type T
testname - the name of this test
Returns:
true if the test fails

checkInexactIterable

public <T> boolean checkInexactIterable(Iterable<T> actual,
                                        Iterable<T> expected,
                                        double tolerance)

Test that compares two objects that implement Iterable interface by traversing over the data.

The objects can contain inexact values (of the types double or float). These will be compared within the given relative tolerance. The relative tolerance used in the comparison will appear on the test report.

Parameters:
actual - the computed value of the type Iterable
expected - the expected value of the type Iterable
tolerance - the desired relative tolerance
Returns:
true if the test succeeds

checkInexactIterable

public <T> boolean checkInexactIterable(Iterable<T> actual,
                                        Iterable<T> expected,
                                        double tolerance,
                                        String testname)

Test that compares two objects that implement Iterable interface by traversing over the data.

The objects can contain inexact values (of the types double or float). These will be compared within the given relative tolerance. The relative tolerance used in the comparison will appear on the test report.

Parameters:
actual - the computed value of the type Iterable
expected - the expected value of the type Iterable
tolerance - the desired relative tolerance
testname - the name of this test
Returns:
true if the test succeeds

checkInexactMethod

public <T> boolean checkInexactMethod(Object expected,
                                      double tolerance,
                                      T object,
                                      String method,
                                      Object... args)
Invoke the method with the given name on a given object with the given arguments - check if it produces the expected value

The resulting object can contain inexact values (of the types double or float). These will be compared within the given relative tolerance. The relative tolerance used in the comparison will appear on the test report.

Type Parameters:
T - The type of the object that invokes the given method
Parameters:
expected - The expected result of the method being tested
object - The object that invokes the method to be tested
method - The name of the method to test
args - An array of arguments for the method - use Array of length 0 if no arguments are needed
Returns:
true if the test succeeds

checkInexactMethod

public <T> boolean checkInexactMethod(String testname,
                                      Object expected,
                                      double tolerance,
                                      T object,
                                      String method,
                                      Object... args)
Invoke the method with the given name on a given object with the given arguments - check if it produces the expected value

The resulting object can contain inexact values (of the types double or float). These will be compared within the given relative tolerance. The relative tolerance used in the comparison will appear on the test report.

Type Parameters:
T - The type of the object that invokes the given method
Parameters:
testname - The description of this test
expected - The expected result of the method being tested
object - The object that invokes the method to be tested
method - The name of the method to test
args - An array of arguments for the method - use Array of length 0 if no arguments are needed
Returns:
true if the test succeeds

checkInexactNoneOf

public <T> boolean checkInexactNoneOf(double tolerance,
                                      T actual,
                                      T... expected)

Test that determines whether the value of the given object (of any kind) is not equal to any of the expected results

The expected results can include inexact values.

Providing tolerance < 0 results in an automatic success of the test.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected values of the type T
Returns:
true if the test succeeds

checkInexactNoneOf

public <T> boolean checkInexactNoneOf(String testname,
                                      double tolerance,
                                      T actual,
                                      T... expected)

Test that determines whether the value of the given object (of any kind) is not equal to any of the expected results

The expected results can include inexact values.

Providing tolerance < 0 results in an automatic success of the test.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected values of the type T
Returns:
true if the test succeeds

checkInexactOneOf

public <T> boolean checkInexactOneOf(double tolerance,
                                     T actual,
                                     T... expected)

Test that determines whether the value of the given object (of any kind) is the same as one of the expected results

The expected results must be composed of exact values only.

Type Parameters:
T - The type of the objects being compared
Parameters:
actual - The computed value of the type T
expected - An Ellipsis of the expected values of the type T
Returns:
true if the test succeeds

checkInexactOneOf

public <T> boolean checkInexactOneOf(String testname,
                                     double tolerance,
                                     T actual,
                                     T... expected)

Test that determines whether the value of the given object (of any kind) is the same as one of the expected results

The expected results must be composed of exact values only.

Type Parameters:
T - The type of the objects being compared
Parameters:
testname - The name of this test
actual - The computed value of the type T
expected - An Ellipsis of the expected values of the type T
Returns:
true if the test succeeds

checkInexactTraversal

public <T> boolean checkInexactTraversal(Traversal<T> actual,
                                         Traversal<T> expected,
                                         double tolerance)

Test that compares two objects that implement Traversal interface by traversing over the data.

The objects can contain inexact values (of the types double or float). These will be compared within the given relative tolerance. The relative tolerance used in the comparison will appear on the test report.

Parameters:
actual - the computed value of the type Traversal
expected - the expected value of the type Traversal
tolerance - the desired relative tolerance
Returns:
true if the test succeeds

checkInexactTraversal

public <T> boolean checkInexactTraversal(Traversal<T> actual,
                                         Traversal<T> expected,
                                         double tolerance,
                                         String testname)

Test that compares two objects that implement Traversal interface by traversing over the data.

The objects can contain inexact values (of the types double or float). These will be compared within the given relative tolerance. The relative tolerance used in the comparison will appear on the test report.

Parameters:
actual - the computed value of the type Traversal
expected - the expected value of the type Traversal
tolerance - the desired relative tolerance
testname - the name of this test
Returns:
true if the test succeeds

checkIterable

public <T> boolean checkIterable(Iterable<T> actual,
                                 Iterable<T> expected)
Test that compares two objects that implement Iterable interface by traversing over the data -- objects must be composed of exact values only

Parameters:
actual - the computed value of the type Iterable
expected - the expected value of the type Iterable
Returns:
true if the test succeeds

checkIterable

public <T> boolean checkIterable(Iterable<T> actual,
                                 Iterable<T> expected,
                                 String testname)
Test that compares two objects that implement Iterable interface by traversing over the data -- objects must be composed of exact values only

Parameters:
actual - the computed value of the type Iterable
expected - the expected value of the type Iterable
testname - the name of this test
Returns:
true if the test succeeds

checkMethod

public <T> boolean checkMethod(Object expected,
                               T object,
                               String method,
                               Object... args)

Invoke the method with the given name on a given object with the given arguments - check if it produces the expected result

The expected result must be composed of exact values only

Type Parameters:
T - The type of the object that invokes the given method
Parameters:
expected - The expected result of the method being tested
object - The object that invokes the method to be tested
method - The name of the method to test
args - An array of arguments for the method - use Array of length 0 if no arguments are needed
Returns:
true if the test succeeds

checkMethod

public <T> boolean checkMethod(String testname,
                               Object expected,
                               T object,
                               String method,
                               Object... args)

Invoke the method with the given name on a given object with the given arguments - check if it produces the expected result

The expected result must be composed of exact values only

Type Parameters:
T - The type of the object that invokes the given method
Parameters:
testname - The description of this test
expected - The expected result of the method being tested
object - The object that invokes the method to be tested
method - The name of the method to test
args - An array of arguments for the method - use Array of length 0 if no arguments are needed
Returns:
true if the test succeeds

checkNoneOf

public <T> boolean checkNoneOf(String testname,
                               T actual,
                               T... expected)

Test that determines whether the value of the given object (of any kind) is not equal to any of the expected results

The expected results must be composed of exact values only.

A 'same' item that involved inexact comparison is not considered a match.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected values of the type T
Returns:
true if the test succeeds

checkNoneOf

public <T> boolean checkNoneOf(T actual,
                               T... expected)

Test that determines whether the value of the given object (of any kind) is not equal to any of the expected results

The expected results must be composed of exact values only.

A 'same' item that involved inexact comparison is not considered a match.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
expected - the expected values of the type T
Returns:
true if the test succeeds

checkNumRange

public <T> boolean checkNumRange(Number actual,
                                 Number low,
                                 Number high)
Test that determines whether the value of the given numerical object (of any kind) is the range between low (inclusive) and high (exclusive) values. Allows for comparison of mixed numeric types.

Parameters:
actual - the computed value of the type Number
low - the lower limit of the type Number (inclusive) for this range
high - the upper limit of the type Number (exclusive) for this range
Returns:
true if the test succeeds

checkNumRange

public <T> boolean checkNumRange(Number actual,
                                 Number low,
                                 Number high,
                                 boolean lowIncl,
                                 boolean highIncl)
Test that determines whether the value of the given object (of any kind) is the range between low and high values. User must specify whether the low and high bounds are inclusive or exclusive.

Parameters:
actual - the computed value of the type Number
low - the lower limit of the type Number (inclusive) for this range
high - the upper limit of the type Number (exclusive) for this range
lowIncl - is the low limit inclusive for this range?
highIncl - is the upper limit inclusive for this range?
Returns:
true if the test succeeds

checkNumRange

public <T> boolean checkNumRange(Number actual,
                                 Number low,
                                 Number high,
                                 boolean lowIncl,
                                 boolean highIncl,
                                 String testname)
Test that determines whether the value of the given object (of any kind) is the range between low and high values. User must specify whether the low and high bounds are inclusive or exclusive.

Parameters:
actual - the computed value of the type Number
low - the lower limit of the type Number (inclusive) for this range
high - the upper limit of the type Number (exclusive) for this range
lowIncl - is the low limit inclusive for this range?
highIncl - is the upper limit inclusive for this range?
Returns:
true if the test succeeds

checkNumRange

public <T> boolean checkNumRange(Number actual,
                                 Number low,
                                 Number high,
                                 String testname)
Test that determines whether the value of the given numerical object (of any kind) is the range between low (inclusive) and high (exclusive) values. Allows for comparison of mixed numeric types.

Parameters:
actual - the computed value of the type Number
low - the lower limit of the type Number (inclusive) for this range
high - the upper limit of the type Number (exclusive) for this range
Returns:
true if the test succeeds

checkOneOf

public <T> boolean checkOneOf(String testname,
                              T actual,
                              T... expected)

Test that determines whether the value of the given object (of any kind) is the same as one of the expected results

The expected results must be composed of exact values only.

Warning: If the actual and expected values are String-s, the programmer must provide the test name --- there is no way the tester can determine whether or not the test name has been included.

Type Parameters:
T - The type of the objects being compared
Parameters:
testname - The name of this test
actual - The computed value of the type T
expected - An Ellipsis of the expected values of the type T
Returns:
true if the test succeeds

checkOneOf

public <T> boolean checkOneOf(T actual,
                              T... expected)

Test that determines whether the value of the given object (of any kind) is the same as one of the expected results

The expected results must be composed of exact values only.

Warning: If the actual and expected values are String-s, the programmer must provide the test name --- there is no way the tester can determine whether or not the test name has been included.

Type Parameters:
T - The type of the objects being compared
Parameters:
actual - The computed value of the type T
expected - An Ellipsis of the expected values of the type T
Returns:
true if the test succeeds

checkRange

public <T> boolean checkRange(Comparable<T> actual,
                              T low,
                              T high)
Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
low - the lower limit of the type T (inclusive) for this range
high - the upper limit of the type T (exclusive) for this range
Returns:
true if the test succeeds

checkRange

public <T> boolean checkRange(Comparable<T> actual,
                              T low,
                              T high,
                              boolean lowIncl,
                              boolean highIncl)
Test that determines whether the value of the given object (of any kind) is the range between low and high values. User must specify whether the low and high bounds are inclusive or exclusive.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
low - the lower limit of the type T for this range
high - the upper limit of the type T for this range
lowIncl - is the low limit inclusive for this range?
highIncl - is the upper limit inclusive for this range?
Returns:
true if the test succeeds

checkRange

public <T> boolean checkRange(Comparable<T> actual,
                              T low,
                              T high,
                              boolean lowIncl,
                              boolean highIncl,
                              String testname)
Test that determines whether the value of the given object (of any kind) is the range between low and high values. User must specify whether the low and high bounds are inclusive or exclusive.

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
low - the lower limit of the type T for this range
high - the upper limit of the type T for this range
lowIncl - is the low limit inclusive for this range?
highIncl - is the upper limit inclusive for this range?
testname - the name of this test
Returns:
true if the test succeeds

checkRange

public <T> boolean checkRange(Comparable<T> actual,
                              T low,
                              T high,
                              String testname)
Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
low - the lower limit of the type T (inclusive) for this range
high - the upper limit of the type T (exclusive) for this range
testname - the name of this test
Returns:
true if the test succeeds

checkRange

public <T> boolean checkRange(T actual,
                              T low,
                              T high,
                              boolean lowIncl,
                              boolean highIncl,
                              Comparator<T> comp)
Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
low - the lower limit of the type T (inclusive) for this range
high - the upper limit of the type T (exclusive) for this range
lowIncl - is the low limit inclusive for this range?
highIncl - is the upper limit inclusive for this range?
comp - The Comparator used to compare the values
Returns:
true if the test succeeds

checkRange

public <T> boolean checkRange(T actual,
                              T low,
                              T high,
                              boolean lowIncl,
                              boolean highIncl,
                              Comparator<T> comp,
                              String testname)
Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
low - the lower limit of the type T (inclusive) for this range
high - the upper limit of the type T (exclusive) for this range
lowIncl - is the low limit inclusive for this range?
highIncl - is the upper limit inclusive for this range?
comp - The Comparator used to compare the values
testname - the name of this test
Returns:
true if the test succeeds

checkRange

public <T> boolean checkRange(T actual,
                              T low,
                              T high,
                              Comparator<T> comp)
Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
low - the lower limit of the type T (inclusive) for this range
high - the upper limit of the type T (exclusive) for this range
Returns:
true if the test succeeds

checkRange

public <T> boolean checkRange(T actual,
                              T low,
                              T high,
                              Comparator<T> comp,
                              String testname)
Test that determines whether the value of the given object (of any kind) is the range between low (inclusive) and high (exclusive) values

Type Parameters:
T - the type of the objects being compared
Parameters:
actual - the computed value of the type T
low - the lower limit of the type T (inclusive) for this range
high - the upper limit of the type T (exclusive) for this range
testname - the name of this test
Returns:
true if the test succeeds

checkSet

public <T> boolean checkSet(Set<T> actual,
                            Set<T> expected)
Test that compares two objects that implement Set interface by comparing data using the equals method for comparing the elements of the two sets.

Parameters:
actual - the computed value of the type Set
expected - the expected value of the type Set
Returns:
true if the test succeeds

checkSet

public <T> boolean checkSet(Set<T> actual,
                            Set<T> expected,
                            String testname)
Test that compares two objects that implement Set interface by comparing data using the equals method for comparing the elements of the two sets.

Parameters:
actual - the computed value of the type Set
expected - the expected value of the type Set
testname - the name of this test
Returns:
true if the test succeeds

checkTraversal

public <T> boolean checkTraversal(Traversal<T> actual,
                                  Traversal<T> expected)
Test that compares two objects that implement Traversal interface by traversing over the data -- objects must be composed of exact values only

Parameters:
actual - the computed value of the type Traversal
expected - the expected value of the type Traversal
Returns:
true if the test succeeds

checkTraversal

public <T> boolean checkTraversal(Traversal<T> actual,
                                  Traversal<T> expected,
                                  String testname)
Test that compares two objects that implement Traversal interface by traversing over the data -- objects must be composed of exact values only

Parameters:
actual - the computed value of the type Traversal
expected - the expected value of the type Traversal
testname - the name of this test
Returns:
true if the test succeeds

done

protected void done(boolean failed)
If the test evaluation terminated due to an exception, report the test that threw the exception..


fail

public boolean fail()
Test nothing, just report failure.

Returns:
always returns false

fail

public boolean fail(String testname)
Test nothing, just report failure.

Parameters:
testname - the name of the test
Returns:
always returns false

fullTestReport

protected void fullTestReport()
Produce test names and values compared for all tests


run

public static boolean run(Object obj)
A hook to run the tester for any object --- needed to run from BlueJ. Print all fields of the 'Examples' class and a report of all failed tests.

Parameters:
obj - The 'Examples' class instance where the tests are defined

runAnyTests

protected void runAnyTests(Object f)

Find all test methods in the class of the given object; run tests and report results.

If the class extends the IExamples all tests within the void tests(Tester t) method are performed. Otherwise we locate all methods with names that start with test and consume one parameter of the type Tester and perform the desired tests.

Report only the results of failed tests.

Parameters:
f - the instance of a class that defines all tests and the data for them

runAnyTests

protected void runAnyTests(Object f,
                           boolean full)

Find all test methods in the class of the given object; run tests and report results.

If the class extends the IExamples all tests within the void tests(Tester t) method are performed. Otherwise we locate all methods with names that start with test and consume one parameter of the type Tester and perform the desired tests.

Report test results --- failed or all as specified.

Parameters:
f - the instance of a class that defines all tests and the data for them
full - true if full test report is desired

runAnyTests

protected void runAnyTests(Object f,
                           boolean full,
                           boolean printall)

Find all test methods in the class of the given object; run tests and report results.

If the class extends the IExamples all tests within the void tests(Tester t) method are performed. Otherwise we locate all methods with names that start with test and consume one parameter of the type Tester and perform the desired tests.

Report test results --- failed or all as specified.

Print all data in the class that defines the tests - as specified.

Parameters:
f - the instance of a class that defines all tests and the data for them
full - true if full test report is desired
printall - true if Examples class data is to be printed

runFullReport

public static boolean runFullReport(Object... objs)
A hook to run the tester for a collection of objects and produce a full test report

Parameters:
objs - An array of 'Examples' class instances where tests are defined

runReport

public static boolean runReport(Object obj,
                                boolean full,
                                boolean printall)
A hook to run the tester for any object and produce a test report. The user selects whether to print all tests and all data

Parameters:
obj - The 'Examples' class instance where the tests are defined

runReports

public static boolean runReports(boolean full,
                                 boolean printall,
                                 Object... objs)
A hook to run the tester for a collection of objects and produce the specified test reports

Parameters:
full - true if all test results should be reported
printall - true if all data should be displayed
objs - An array of 'Examples' class instances where tests are defined

runTests

protected void runTests(IExamples f,
                        boolean full,
                        boolean printall)

Run the tests, accept the class to be tested as a visitor

An alternative method for running all tests.

Parameters:
f - the class to be tested -- it defines the method void tests(Tester t) that invokes all test cases.
full - true if full test report is desired

same

public boolean same(Object obj1,
                    Object obj2)

Provide a general extensional equality comparison for arbitrary pair of objects

Inspector invokes the user-defined same method, if the corresponding classes implement the ISame interface.

Parameters:
obj1 - the first object
obj2 - the second object
Returns:
true if the two objects represent the same data

setTolerance

protected boolean setTolerance(double epsilon)
Set the relative tolerance for the comparison of inexact numbers

Parameters:
epsilon - the desired tolerance

success

public boolean success()
Test nothing, just report success.

Returns:
always returns true

success

public boolean success(String testname)
Test nothing, just report success.

Parameters:
testname - the name of the test
Returns:
always returns true

testReport

protected void testReport()
Report on the number and nature of failed tests