Package eu.simuline.testhelpers
Class Assert<E>
- java.lang.Object
-
- org.junit.Assert
-
- eu.simuline.testhelpers.Assert<E>
-
- Type Parameters:
E- the element type of aCollectionor the element to be compared by aComparator.
public abstract class Assert<E> extends Assert
Extends the framework of assertions provided byjunit.framework.Assert.-
The method
assertNormAbsEquals(Object,Object,String,double)generalizes the methodassertEquals(double expected, double actual, double delta)to objects with a metric defined by a method (name). There is also a variant for relative precision,assertNormRelEquals(Object,Object,String,double). -
The methods
assertRelEquals(double,double,double)provides relative tolerances suited to numerical applications. For small number applications (e.g. failure probabilities) a combination of relative tolerance and absolute one may be prescribed byassertAbsRelEquals(double,double,double,double,double). -
Sometimes equality with respect to the equals-method
differs from equality
with respect to
Comparators and thecompareTomethod (think e.g. of the packagejava.math). To fill this gapassertIs(Assert.CmpObj,Comparable,Object)is useful. This method can also check for "greater than" or that like. A variant of this usingComparators isassertIs(Assert.CmpObj,Object,Object,Comparator). -
The method
assertArraysEquals(Object,Object)tests equality of arrays recursively. -
The method
assertArraysEquals(Object,Object,double)is a combination ot the two. -
The method
assertRelEquals(double expected, double actual, double reldev)is for testing relative deviations. -
The method
assertStringEquals(String expected, String actual)is designed for testing long strings. It provides error messages suitable to find deviations quickly.
- Author:
- Ernst Reissner
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAssert.CmpObjRepresents an ordering relation.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringSTR_ASTOPprivate static java.lang.StringSTR_BUTWASprivate static java.lang.StringSTR_DN_PROVprivate static java.lang.StringSTR_IN_ABS_VALprivate static java.lang.StringSTR_OBJECTprivate static java.lang.StringSTR_RAISED
-
Constructor Summary
Constructors Constructor Description Assert()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidassertAbsEquals(double expected, double actual, double absdev)Fails if the absolute deviation betweenexpectedandactualexceedsabsdivin absolute value.static voidassertAbsEquals(java.lang.String message, double expected, double actual, double absdev)Fails if the absolute deviation betweenexpectedandactualexceedsabsdivin absolute value.static voidassertAbsRelEquals(double expected, double separateAbsRel, double actual, double absdev, double reldev)Forexpected<= separateAbsRelbehaves likeAssert.assertEquals(String,double,double,double)ignoringreldev, whereas otherwise behaves likeAssert.assertEquals(String, double, double, double)ignoringabsdev.static voidassertAbsRelEquals(java.lang.String message, double expected, double separateAbsRel, double actual, double absdev, double reldev)Forexpected<= separateAbsRelbehaves likeAssert.assertEquals(String,double,double,double)ignoringreldev, whereas otherwise behaves likeAssert.assertEquals(String, double, double, double)ignoringabsdev.static voidassertArraysEquals(java.lang.Object expected, java.lang.Object actual)static voidassertArraysEquals(java.lang.Object expected, java.lang.Object actual, double delta)Is a deep version of methodjunit.framework.Assert.assertEquals(Object, Object)for arrays: checks whether the two arguments are arrays and whether they are arrays, recursively whether the lengths coincide and if the entries do so.static voidassertArraysEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)Is a deep version of methodjunit.framework.Assert.assertEquals(Object, Object)for arrays: checks whether the two arguments are arrays and whether they are arrays, recursively whether the lengths coincide and if the entries do so.static voidassertEquals(java.lang.Object expected, java.lang.Object actual)Fails for!static voidassertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)static <E> voidassertIs(Assert.CmpObj cmpObj, E expected, E actual, java.util.Comparator<E> cmp)Fails ifcmp.compare(expected, actual)is not as expected and raises an exception if this expression cannot be evaluated.static <E> voidassertIs(Assert.CmpObj cmpObj, java.lang.Comparable<E> expected, E actual)Fails ifexpected.compareTo(actual)is not as expected and raises an exception if this expression cannot be evaluated.static <E> voidassertIs(Assert.CmpObj cmpObj, java.lang.String message, E expected, E actual, java.util.Comparator<E> cmp)Fails ifcmp.compare(expected, actual)is not as expected and raises an exception if this expression cannot be evaluated.static <E> voidassertIs(Assert.CmpObj cmpObj, java.lang.String message, java.lang.Comparable<E> expected, E actual)Fails ifexpected.compareTo(actual)is not as expected and raises an exception if this expression cannot be evaluated.static <E> voidassertIsContainedAll(java.util.Collection<E> expected, java.util.Collection<E> actual)Fails ifactualis not a subcollection ofexpected.static <E> voidassertIsIn(java.util.Collection<E> expectedContainer, java.lang.Object actualElement)Fails ifactualElementis not an element ofexpectedContainer.static voidassertNormAbsEquals(java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double delta)static voidassertNormAbsEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double delta)Fails ifactualisnulloractualdeviates fromexpectedby at leastdelta, provided the test can be executed at all.static voidassertNormRelEquals(java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double reldev)Fails ifactualisnulloractualdeviates fromexpectedby at leastdelta, provided the test can be executed at all.static voidassertNormRelEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double reldev)private static voidassertRecArraysEquals(java.lang.Object expected, java.lang.Object actual, int[] indices)Is a deep version of methodjunit.framework.Assert.assertEquals(Object, Object)for arrays: checks recursively whether the lengths coincide and if the entries do so.private static voidassertRecArraysEquals(java.lang.Object expected, java.lang.Object actual, int[] indices, double delta)Is a deep version of methodjunit.framework.Assert.assertEquals(Object, Object)for arrays: checks recursively whether the lengths coincide and if the entries do so.static voidassertRelEquals(double expected, double actual, double reldev)Fails reporting a standard message if the relative deviation betweenexpectedandactualexceedsreldivin absolute value.static voidassertRelEquals(java.lang.String message, double expected, double actual, double reldev)Fails if the relative deviation betweenexpectedandactualexceedsreldivin absolute value.static voidassertStringEquals(java.lang.String expected, java.lang.String actual)Special case ofassertEquals(Object, Object)which provides an error message specifying the common prefix ofexpectedwithactual.private static voidcheckArraysSameClass(java.lang.Object expected, java.lang.Object actual)Checks whetherexpectedis an array and whether its type coincides with the type ofactual.private static booleancheckNulls(java.lang.String message, java.lang.Object expected, java.lang.Object actual)Throws an error if exactly one of the parameters arenulland otherwise returns whether both arenull.private static voidcheckNullsB(java.lang.String norm, java.lang.Object expected, java.lang.Object actual)Fails if the test can be executed, i.e.private static doublecomputeNorm1(java.lang.String norm, java.lang.Object expected)Returns the norm ofexpecteddefined by the method namednorm.private static doublecomputeNorm2(java.lang.String norm, java.lang.Object expected, java.lang.Object actual)Returns the distance of the two objectsexpectedandactualdefined by the metric defined by the method namednorm; typically something like the norm of a kind of difference.private static java.lang.StringexpectedActual(java.lang.Object expected, java.lang.Object actual)private static java.lang.StringfailInd(int[] indices)private static java.lang.StringfailLengthMessage(java.lang.Object expectedEntry, java.lang.Object actualEntry, int[] indices)private static java.lang.StringfailMessage(java.lang.Object expectedEntry, java.lang.Object actualEntry, int[] indices)private static java.lang.StringfailMessageDelta(double expectedEntry, double actualEntry, int[] indices, double delta)Returns a failure message indicating that in comparing nested arrays of final float type asdouble[][], the corresponding entries given by index pathindicesdeviate at leastdelta.private static java.lang.StringfailMessageLength(int expectedLen, int actualLen, int[] indices)private static <E> intinvokeCompare(E obj1, E obj2, java.util.Comparator<E> cmp)Returnscmp.compare(expected, actual)if possible.static doubletest()static booleantestAbsEquals(double expected, double actual, double absdev)Returns whether the absolute deviation betweenexpectedandactualexceedsabsdivin absolute value.static booleantestRelEquals(double expected, double actual, double reldev)Returns whether the relative deviation betweenexpectedandactualexceedsreldivin absolute value.private static voidthrwAccessible(java.lang.reflect.Method method)private static voidthrwWrongArgs(java.lang.reflect.Method method)-
Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
-
-
-
-
Field Detail
-
STR_OBJECT
private static final java.lang.String STR_OBJECT
- See Also:
- Constant Field Values
-
STR_DN_PROV
private static final java.lang.String STR_DN_PROV
- See Also:
- Constant Field Values
-
STR_RAISED
private static final java.lang.String STR_RAISED
- See Also:
- Constant Field Values
-
STR_BUTWAS
private static final java.lang.String STR_BUTWAS
- See Also:
- Constant Field Values
-
STR_ASTOP
private static final java.lang.String STR_ASTOP
- See Also:
- Constant Field Values
-
STR_IN_ABS_VAL
private static final java.lang.String STR_IN_ABS_VAL
- See Also:
- Constant Field Values
-
-
Method Detail
-
thrwAccessible
private static void thrwAccessible(java.lang.reflect.Method method)
-
thrwWrongArgs
private static void thrwWrongArgs(java.lang.reflect.Method method)
-
computeNorm2
private static double computeNorm2(java.lang.String norm, java.lang.Object expected, java.lang.Object actual)Returns the distance of the two objectsexpectedandactualdefined by the metric defined by the method namednorm; typically something like the norm of a kind of difference.CAUTION: This method shall be designed to compute values close to zero, i.e. is applied to
actualcloase toexpected. This must be reflected in the definition of the method given bynorm.- Parameters:
norm- the non-null name of a metric method, i.e. of a member method of the formpublic double norm(other)with the properties of a metric:x.norm(x)yields0x.norm(y)andy.norm(x)yield the same result,x.norm(y)+y.norm(z)\(\ge\) x.norm(z).
actualclose toexpectedi.e. with a lot of extinction. For certain arithmetic types, this requires care to obtain reasonable performance.- Throws:
java.lang.IllegalArgumentException- if the test cannot be performed, i.e.-
normdoes not represent a metric method, i.e. a member method of the formpublic double norm(other). Of course, the properties of a metric cannot be proved. -
invoking
expected.norm(actual)raises an exception
-
- See Also:
assertNormAbsEquals(String, Object, Object, String, double),assertNormRelEquals(String, Object, Object, String, double),computeNorm1(String, Object)
-
assertNormAbsEquals
public static void assertNormAbsEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double delta)Fails ifactualisnulloractualdeviates fromexpectedby at leastdelta, provided the test can be executed at all. The deviation is computed with respect to the metric given byexpected.norm(actual)which is assumed to have signaturedouble norm(Cls actual)withClsthe class ofexpected.- Parameters:
message- the error message displayed if the test fails regularly, i.e. ifcomputeNorm2(norm, expected, actual)can be evaluated without throwing an exception.expected- The expected object (see the actual object).actual- The actual object which is expected to deviate fromexpectedby at mostdeltain normnorm- the name of a metric method, i.e. of a member method of the formpublic double norm(other)with the properties of a metric:x.norm(x)yields0x.norm(y)andy.norm(x)yield the same result,x.norm(y)+y.norm(z)\(\ge\) x.norm(z).
delta- the allowed deviation as adoublevalue.- Throws:
java.lang.IllegalArgumentException- if the test cannot be performed, i.e.-
normisnullor does not represent a metric method, i.e. a member method of the formpublic double norm(other). Of course, the properties of a metric cannot be proved. -
invoking
expected.norm(actual)raises an exception
-
java.lang.IllegalArgumentException- ifexpected==null.junit.framework.AssertionFailedError- if the test can be performed, i.e. no IllegalArgumentException is thrown but-
actual==nullor - the distance returned by the metric exceeds
delta.
-
-
assertNormAbsEquals
public static void assertNormAbsEquals(java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double delta)
-
computeNorm1
private static double computeNorm1(java.lang.String norm, java.lang.Object expected)Returns the norm ofexpecteddefined by the method namednorm.- Parameters:
norm- the non-null name of a norm method, i.e. of a member method of the formpublic double norm()with the properties of a norm:-
x.norm()yields0iffxrepresents the zero vector. -
(sx).norm()=s(x.norm())wheresxands(...)represent scalar multiplication. -
x.norm()+y.norm()\(\ge (x+y)\).norm(z), where \(x+y\) represents the sum of vectors.
-
expected- The object from which the norm is to be computed.- Returns:
- the norm of
expecteddefined by the method namednorm. - Throws:
java.lang.IllegalArgumentException- if the test cannot be performed, i.e.-
normdoes not represent a norm method, i.e. a member method of the formpublic double norm(other). Of course, the properties of a norm cannot be proved. -
invoking
expected.norm()raises an exception
-
-
assertNormRelEquals
public static void assertNormRelEquals(java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double reldev)Fails ifactualisnulloractualdeviates fromexpectedby at leastdelta, provided the test can be executed at all.
-
assertNormRelEquals
public static void assertNormRelEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double reldev)
-
expectedActual
private static java.lang.String expectedActual(java.lang.Object expected, java.lang.Object actual)
-
checkNullsB
private static void checkNullsB(java.lang.String norm, java.lang.Object expected, java.lang.Object actual)Fails if the test can be executed, i.e. neithernormnorexpectedisnull, andactualisnull.- Parameters:
norm- name of a member method in classClswith signaturedouble norm(Cls actual).expected- anObjectwith typeCls; in particular notnull.actual- anotherObject; in particular notnull.- Throws:
java.lang.IllegalArgumentException- ifnorm==nullorexpected==null.junit.framework.AssertionFailedError- ifnorm,expected!=nullbutactual==null.- See Also:
assertNormAbsEquals(String, Object, Object, String, double),assertNormRelEquals(String, Object, Object, String, double),checkNulls(String, Object, Object)
-
assertEquals
public static void assertEquals(java.lang.Object expected, java.lang.Object actual)Fails for!expected.equals(actual)and raises an exception if this expression cannot be evaluated.- Parameters:
expected- an instance of anObject.actual- anObjectornull.- Throws:
java.lang.IllegalArgumentException--
for
expected == null, -
if invoking
expected.equals(actual)raises an exception.
-
for
junit.framework.AssertionFailedError- for!expected.equals(actual).
-
assertEquals
public static void assertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
-
assertIsIn
public static <E> void assertIsIn(java.util.Collection<E> expectedContainer, java.lang.Object actualElement)Fails ifactualElementis not an element ofexpectedContainer.- Parameters:
expectedContainer- aCollectionthe objectactualElementis expected to be contained in.actualElement- an instance of anObject.- Throws:
junit.framework.AssertionFailedError- ifactualElementis not inexpectedContainerand in particular if it isnull.
-
assertIsContainedAll
public static <E> void assertIsContainedAll(java.util.Collection<E> expected, java.util.Collection<E> actual)Fails ifactualis not a subcollection ofexpected.- Parameters:
expected- aCollectionactual- anotherCollection- Throws:
junit.framework.AssertionFailedError- ifactualis not a subcollection ofexpectedContainer. This includes the cases where a parameter isnull.
-
assertIs
public static <E> void assertIs(Assert.CmpObj cmpObj, java.lang.String message, java.lang.Comparable<E> expected, E actual)
Fails ifexpected.compareTo(actual)is not as expected and raises an exception if this expression cannot be evaluated.- Parameters:
message- the error message displayed if the test fails regularly, i.e. ifexpected.compareTo(actual)can be evaluated without throwing an exception.cmpObj- The action that decides whether the relation is satisfied.expected- an instance of aComparable.actual- anObjectornull. Actually this should be aComparableas well.- Throws:
java.lang.IllegalArgumentException- if invokingexpected.compareTo(actual)raises an exception. In particular forexpected == nulljava.lang.IllegalStateException- ifexpected.compare(actual)is evaluated foractual == nullwithout throwing an exception as specified forComparable.compareTo(T).junit.framework.AssertionFailedError- if the value ofexpected.compareTo(actual)is not as specified bycmpObj.- See Also:
assertIs(CmpObj, Comparable, Object)
-
assertIs
public static <E> void assertIs(Assert.CmpObj cmpObj, java.lang.String message, E expected, E actual, java.util.Comparator<E> cmp)
Fails ifcmp.compare(expected, actual)is not as expected and raises an exception if this expression cannot be evaluated.- Parameters:
message- the error message displayed if the test fails regularly, i.e. ifcmp.compare(expected, actual)can be evaluated without throwing an exception.cmpObj- The action that decides whether the relation is satisfied.expected- anObject.actual- anotherObject.- Throws:
java.lang.IllegalArgumentException- if invokingcmp.compare(expected, actual)raises an exception.junit.framework.AssertionFailedError- if the value ofcmp.compare(expected, actual)is not as specified bycmpObj.- See Also:
assertIs(CmpObj, Object, Object, Comparator)
-
assertIs
public static <E> void assertIs(Assert.CmpObj cmpObj, java.lang.Comparable<E> expected, E actual)
Fails ifexpected.compareTo(actual)is not as expected and raises an exception if this expression cannot be evaluated.- Parameters:
cmpObj- The action that decides whether the relation is satisfied.expected- an instance of aComparable.actual- anObjectornull. Actually this should be aComparableas well.- Throws:
java.lang.IllegalArgumentException- if invokingexpected.compareTo(actual)raises an exception. In particular forexpected == nulljava.lang.IllegalStateException- ifexpected.compare(actual)is evaluated foractual == nullwithout throwing an exception as specified forComparable.compareTo(T).junit.framework.AssertionFailedError- if the value ofexpected.compareTo(actual)is not as specified bycmpObj.- See Also:
assertIs(CmpObj, String, Comparable, Object)
-
assertIs
public static <E> void assertIs(Assert.CmpObj cmpObj, E expected, E actual, java.util.Comparator<E> cmp)
Fails ifcmp.compare(expected, actual)is not as expected and raises an exception if this expression cannot be evaluated.- Parameters:
cmpObj- The action that decides whether the relation is satisfied.expected- anObject.actual- anotherObject.- Throws:
java.lang.IllegalArgumentException- if invokingcmp.compare(expected, actual)raises an exception.junit.framework.AssertionFailedError- if the value ofcmp.compare(expected, actual)is not as specified bycmpObj.- See Also:
assertIs(CmpObj, String, Object, Object, Comparator)
-
invokeCompare
private static <E> int invokeCompare(E obj1, E obj2, java.util.Comparator<E> cmp)Returnscmp.compare(expected, actual)if possible.- Parameters:
obj1- anObject.obj2- anotherObject.cmp- a comparator which is capable of comparingobj1withobj2.- Returns:
- the
intvalue which results in invokingcmp.compare(expected, actual). - Throws:
java.lang.IllegalArgumentException--
for
cmp == null, -
if invoking
cmp.compare(expected, actual)raises an exception.
-
for
-
checkNulls
private static boolean checkNulls(java.lang.String message, java.lang.Object expected, java.lang.Object actual)Throws an error if exactly one of the parameters arenulland otherwise returns whether both arenull.- Parameters:
message- the error message used in case the assertion fails.expected- anObject.actual- anotherObject.- Returns:
- whether both are
null, if either both,expectedandactualarenull. - Throws:
junit.framework.AssertionFailedError- if exactly one of the parameters arenull.
-
assertArraysEquals
public static void assertArraysEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)Is a deep version of methodjunit.framework.Assert.assertEquals(Object, Object)for arrays: checks- whether the two arguments are arrays and whether they are arrays,
- recursively whether the lengths coincide and if the entries do so.
- Parameters:
message- the error message used in case the assertion fails.expected- an array.actual- an array.- Throws:
java.lang.IllegalArgumentException- ifexpectedis not an array.junit.framework.AssertionFailedError- if the types of the two arguments do not coincide (e.g. because the second one is not an array). See alsoassertRecArraysEquals(java.lang.Object, java.lang.Object, int[]).junit.framework.AssertionFailedError- if the the two arrays do not coincide in their lenght or in some entry.
-
assertArraysEquals
public static void assertArraysEquals(java.lang.Object expected, java.lang.Object actual)
-
checkArraysSameClass
private static void checkArraysSameClass(java.lang.Object expected, java.lang.Object actual)Checks whetherexpectedis an array and whether its type coincides with the type ofactual. If not an exception is thrown. InvokesAssert.fail(java.lang.String)if the types ofexpectedand ofactualdo not coincide.- Parameters:
expected- the expected array.actual- the actual array.- Throws:
java.lang.IllegalArgumentException- ifexpectedis not an array.
-
assertRecArraysEquals
private static void assertRecArraysEquals(java.lang.Object expected, java.lang.Object actual, int[] indices)Is a deep version of methodjunit.framework.Assert.assertEquals(Object, Object)for arrays: checks recursively whether the lengths coincide and if the entries do so. Contract: the classes of the two arguments coincide and both are arrays.- Parameters:
expected- the expected array.actual- the actual array.indices- contains the list of indices of the arraysexpectedandactualwithin the arrays comprising them. The recursion starts withindices = new int[] {}.- Throws:
junit.framework.AssertionFailedError- if the the two arrays do not coincide in their lenght or in some entry.
-
failInd
private static java.lang.String failInd(int[] indices)
-
failLengthMessage
private static java.lang.String failLengthMessage(java.lang.Object expectedEntry, java.lang.Object actualEntry, int[] indices)
-
failMessage
private static java.lang.String failMessage(java.lang.Object expectedEntry, java.lang.Object actualEntry, int[] indices)
-
failMessageDelta
private static java.lang.String failMessageDelta(double expectedEntry, double actualEntry, int[] indices, double delta)Returns a failure message indicating that in comparing nested arrays of final float type asdouble[][], the corresponding entries given by index pathindicesdeviate at leastdelta.
-
failMessageLength
private static java.lang.String failMessageLength(int expectedLen, int actualLen, int[] indices)
-
assertArraysEquals
public static void assertArraysEquals(java.lang.Object expected, java.lang.Object actual, double delta)Is a deep version of methodjunit.framework.Assert.assertEquals(Object, Object)for arrays: checks- whether the two arguments are arrays and whether they are arrays,
- recursively whether the lengths coincide and if the entries do so.
- Parameters:
expected- the expected array.actual- the actual array which is assumed to be of same type asexpected.delta- the allowed deviation as adoublevalue.- Throws:
java.lang.IllegalArgumentException- ifexpectedis not an array.junit.framework.AssertionFailedError- if the types of the two arguments do not coincide (e.g. because the second one is not an array). See alsoassertRecArraysEquals(java.lang.Object, java.lang.Object, int[]).junit.framework.AssertionFailedError- if the the two arrays do not coincide in their lenght or in some entry.
-
assertRecArraysEquals
private static void assertRecArraysEquals(java.lang.Object expected, java.lang.Object actual, int[] indices, double delta)Is a deep version of methodjunit.framework.Assert.assertEquals(Object, Object)for arrays: checks recursively whether the lengths coincide and if the entries do so. Contract: the classes of the two arguments coincide and both are arrays.- Parameters:
expected- the expected array.actual- the actual array which is assumed to be of same type asexpected.indices- contains the list of indices of the arraysexpectedandactualwithin the arrays comprising them. The recursion starts withindices = new int[] {}. This is for generating an appropriate message for anAssertionFailedError.delta- the allowed deviation as adoublevalue.- Throws:
java.lang.IllegalArgumentException- ifexpectedoractualis not an array.junit.framework.AssertionFailedError- if the the two arrays do not coincide in their length or in some entry.eu.simuline.util.NotYetImplementedException- ifexpectedis not 'finally' of primitive type.
-
testRelEquals
public static boolean testRelEquals(double expected, double actual, double reldev)Returns whether the relative deviation betweenexpectedandactualexceedsreldivin absolute value.- Parameters:
expected- thedoublevalue expected. This may be neither0.0, nor an infinite value norNaN.actual- the actualdoublevalue.reldev- the maximum relative deviation betweenexpectedandactual. This must be a non-negative value; in particular,NaNis not allowed.- Returns:
- whether the relative deviation
between
expectedandactualexceedsreldivin absolute value. - Throws:
java.lang.IllegalArgumentException--
if
expectedis either0.0, infinite orNaN. -
if
reldevis negative orNaN.
-
if
- See Also:
assertRelEquals(String, double, double, double)
-
assertRelEquals
public static void assertRelEquals(java.lang.String message, double expected, double actual, double reldev)Fails if the relative deviation betweenexpectedandactualexceedsreldivin absolute value.- Parameters:
message- the error message used in case the assertion fails.expected- thedoublevalue expected. This may be neither0.0, nor an infinite value norNaN.actual- the actualdoublevalue.reldev- the maximum relative deviation betweenexpectedandactual. This must be a non-negative value; in particular,NaNis not allowed.- Throws:
java.lang.IllegalArgumentException--
if
expectedis either0.0, infinite orNaN. -
if
reldevis negative orNaN.
-
if
- See Also:
assertRelEquals(double, double, double),testRelEquals(double, double, double)
-
assertRelEquals
public static void assertRelEquals(double expected, double actual, double reldev)Fails reporting a standard message if the relative deviation betweenexpectedandactualexceedsreldivin absolute value.- Parameters:
expected- thedoublevalue expected. This may be neither0.0, nor an infinite value norNaN.actual- the actualdoublevalue.reldev- the maximum relative deviation betweenexpectedandactual. This must be a non-negative value; in particular,NaNis not allowed.- Throws:
java.lang.IllegalArgumentException--
if
expectedis either0.0, infinite orNaN. -
if
reldevis negative orNaN.
-
if
- See Also:
assertRelEquals(String, double, double, double)
-
assertAbsRelEquals
public static void assertAbsRelEquals(java.lang.String message, double expected, double separateAbsRel, double actual, double absdev, double reldev)Forexpected<= separateAbsRelbehaves likeAssert.assertEquals(String,double,double,double)ignoringreldev, whereas otherwise behaves likeAssert.assertEquals(String, double, double, double)ignoringabsdev.- Parameters:
message- the error message used in case the assertion fails.expected- thedoublevalue expected.separateAbsRel- a non-negativedoublevalue separating the two parts of the domain of this method.actual- the actualdoublevalue.absdev- the maximum absolute deviation betweenexpectedandactual. This is relevant forexpected<= separateAbsRelbut ignored otherwise.reldev- the maximum relative deviation betweenexpectedandactual. This is relevant forexpected > separateAbsRelbut ignored otherwise.- Throws:
java.lang.IllegalArgumentException- forseparateAbsRel < 0.
-
assertAbsRelEquals
public static void assertAbsRelEquals(double expected, double separateAbsRel, double actual, double absdev, double reldev)Forexpected<= separateAbsRelbehaves likeAssert.assertEquals(String,double,double,double)ignoringreldev, whereas otherwise behaves likeAssert.assertEquals(String, double, double, double)ignoringabsdev.- Parameters:
expected- thedoublevalue expected.separateAbsRel- a non-negativedoublevalue separating the two parts of the domain of this method.actual- the actualdoublevalue.absdev- the maximum absolute deviation betweenexpectedandactual. This is relevant forexpected<= separateAbsRelbut ignored otherwise.reldev- the maximum relative deviation betweenexpectedandactual. This is relevant forexpected > separateAbsRelbut ignored otherwise.- Throws:
java.lang.IllegalArgumentException- forseparateAbsRel < 0.
-
testAbsEquals
public static boolean testAbsEquals(double expected, double actual, double absdev)Returns whether the absolute deviation betweenexpectedandactualexceedsabsdivin absolute value.- Parameters:
expected- thedoublevalue expected. This may not beNaN.actual- the actualdoublevalue.absdev- the maximum absolute deviation betweenexpectedandactual. This must be a non-negative value; in particular,NaNis not allowed.- Returns:
- whether the absolute deviation
between
expectedandactualexceedsabsdivin absolute value. - Throws:
java.lang.IllegalArgumentException--
if
expectedisNaN. -
if
absdevis negative orNaN.
-
if
- See Also:
assertAbsEquals(String, double, double, double)
-
assertAbsEquals
public static void assertAbsEquals(java.lang.String message, double expected, double actual, double absdev)Fails if the absolute deviation betweenexpectedandactualexceedsabsdivin absolute value.- Parameters:
message- the error message used in case the assertion fails.expected- thedoublevalue expected. This may not be neitherNaN.actual- the actualdoublevalue.absdev- the maximum absolute deviation betweenexpectedandactual. This must be a non-negative value; in particular,NaNis not allowed.- Throws:
java.lang.IllegalArgumentException--
if
expectedisNaN. -
if
absdevis negative orNaN.
-
if
- See Also:
assertAbsEquals(double, double, double),testAbsEquals(double, double, double)
-
assertAbsEquals
public static void assertAbsEquals(double expected, double actual, double absdev)Fails if the absolute deviation betweenexpectedandactualexceedsabsdivin absolute value.- Parameters:
expected- thedoublevalue expected. This may not be neitherNaN.actual- the actualdoublevalue.absdev- the maximum absolute deviation betweenexpectedandactual. This must be a non-negative value; in particular,NaNis not allowed.- Throws:
java.lang.IllegalArgumentException--
if
expectedisNaN. -
if
absdevis negative orNaN.
-
if
- See Also:
assertAbsEquals(String, double, double, double)
-
assertStringEquals
public static void assertStringEquals(java.lang.String expected, java.lang.String actual)Special case ofassertEquals(Object, Object)which provides an error message specifying the common prefix ofexpectedwithactual. This is suitable for keeping long strings under control. If one of the arguments isnull, this method behaves likeAssert.assertEquals(Object, Object).- Parameters:
expected- theStringexpected. This maactual- aStringvalue
-
test
public static double test()
-
-