de.smartics.util.test.theories
Class CompareToTheory<T extends Comparable<T>>

Package class diagram package CompareToTheory
java.lang.Object
  extended by de.smartics.util.test.theories.CompareToTheory<T>
Type Parameters:
T - the type of the comparable to test here.

public abstract class CompareToTheory<T extends Comparable<T>>
     
     
extends Object

Tests theory on comparable instances.

Author:
Robert Reiner

Constructor Summary
CompareToTheory()
           
 
Method Summary
protected  boolean checkConsistentWithEquals()
          Determines whether or not the theory should check the Comparable.compareTo(Object) is consistent with Object.equals(Object).
 void compareToIsConsistentToEquals(T uutX, T uutY)
          Checks the optional consistent to equals property of the Comparable.compareTo(Object) method.
 void compareToIsSymmetric(T uutX, T uutY)
          Checks the symmetric property of the Comparable.compareTo(Object) method.
 void compareToIsTransitive(T uutX, T uutY, T uutZ)
          Checks the transitive property of the Comparable.compareTo(Object) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompareToTheory

public CompareToTheory()
Method Detail

checkConsistentWithEquals

protected boolean checkConsistentWithEquals()
Determines whether or not the theory should check the Comparable.compareTo(Object) is consistent with Object.equals(Object).

Override this method by your subclass.

Returns:
true per default.

compareToIsSymmetric

public void compareToIsSymmetric(T uutX,
                                 T uutY)
Checks the symmetric property of the Comparable.compareTo(Object) method.

The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)

Parameters:
uutX - the unit under test to test for symmetry.
uutY - the unit under test to test for symmetry.
See Also:
Comparable.compareTo(Object)

compareToIsTransitive

public final void compareToIsTransitive(T uutX,
                                        T uutY,
                                        T uutZ)
Checks the transitive property of the Comparable.compareTo(Object) method.

The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.

Parameters:
uutX - the unit under test to test for transitivity.
uutY - the unit under test to test for transitivity.
uutZ - the unit under test to test for transitivity.
See Also:
Comparable.compareTo(Object)

compareToIsConsistentToEquals

public final void compareToIsConsistentToEquals(T uutX,
                                                T uutY)
Checks the optional consistent to equals property of the Comparable.compareTo(Object) method.

It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."

Parameters:
uutX - the unit under test to test for consistency with equals.
uutY - the unit under test to test for consistency with equals.
See Also:
Comparable.compareTo(Object)


Copyright © 2008-2013 Kronseder & Reiner GmbH - smartics. All Rights Reserved.