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 aCollection
or 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
Comparator
s and thecompareTo
method (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 usingComparator
s 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 class
Assert.CmpObj
Represents an ordering relation.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
STR_ASTOP
private static java.lang.String
STR_BUTWAS
private static java.lang.String
STR_DN_PROV
private static java.lang.String
STR_IN_ABS_VAL
private static java.lang.String
STR_OBJECT
private static java.lang.String
STR_RAISED
-
Constructor Summary
Constructors Constructor Description Assert()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertAbsEquals(double expected, double actual, double absdev)
Fails if the absolute deviation betweenexpected
andactual
exceedsabsdiv
in absolute value.static void
assertAbsEquals(java.lang.String message, double expected, double actual, double absdev)
Fails if the absolute deviation betweenexpected
andactual
exceedsabsdiv
in absolute value.static void
assertAbsRelEquals(double expected, double separateAbsRel, double actual, double absdev, double reldev)
Forexpected<= separateAbsRel
behaves likeAssert.assertEquals(String,double,double,double)
ignoringreldev
, whereas otherwise behaves likeAssert.assertEquals(String, double, double, double)
ignoringabsdev
.static void
assertAbsRelEquals(java.lang.String message, double expected, double separateAbsRel, double actual, double absdev, double reldev)
Forexpected<= separateAbsRel
behaves likeAssert.assertEquals(String,double,double,double)
ignoringreldev
, whereas otherwise behaves likeAssert.assertEquals(String, double, double, double)
ignoringabsdev
.static void
assertArraysEquals(java.lang.Object expected, java.lang.Object actual)
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.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.static void
assertEquals(java.lang.Object expected, java.lang.Object actual)
Fails for!
static void
assertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
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.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.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.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.static <E> void
assertIsContainedAll(java.util.Collection<E> expected, java.util.Collection<E> actual)
Fails ifactual
is not a subcollection ofexpected
.static <E> void
assertIsIn(java.util.Collection<E> expectedContainer, java.lang.Object actualElement)
Fails ifactualElement
is not an element ofexpectedContainer
.static void
assertNormAbsEquals(java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double delta)
static void
assertNormAbsEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double delta)
Fails ifactual
isnull
oractual
deviates fromexpected
by at leastdelta
, provided the test can be executed at all.static void
assertNormRelEquals(java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double reldev)
Fails ifactual
isnull
oractual
deviates fromexpected
by at leastdelta
, provided the test can be executed at all.static void
assertNormRelEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual, java.lang.String norm, double reldev)
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.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.static void
assertRelEquals(double expected, double actual, double reldev)
Fails reporting a standard message if the relative deviation betweenexpected
andactual
exceedsreldiv
in absolute value.static void
assertRelEquals(java.lang.String message, double expected, double actual, double reldev)
Fails if the relative deviation betweenexpected
andactual
exceedsreldiv
in absolute value.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 ofexpected
withactual
.private static void
checkArraysSameClass(java.lang.Object expected, java.lang.Object actual)
Checks whetherexpected
is an array and whether its type coincides with the type ofactual
.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 arenull
and otherwise returns whether both arenull
.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.private static double
computeNorm1(java.lang.String norm, java.lang.Object expected)
Returns the norm ofexpected
defined by the method namednorm
.private static double
computeNorm2(java.lang.String norm, java.lang.Object expected, java.lang.Object actual)
Returns the distance of the two objectsexpected
andactual
defined by the metric defined by the method namednorm
; typically something like the norm of a kind of difference.private static java.lang.String
expectedActual(java.lang.Object expected, java.lang.Object actual)
private static java.lang.String
failInd(int[] indices)
private static java.lang.String
failLengthMessage(java.lang.Object expectedEntry, java.lang.Object actualEntry, int[] indices)
private static java.lang.String
failMessage(java.lang.Object expectedEntry, java.lang.Object actualEntry, int[] indices)
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 pathindices
deviate at leastdelta
.private static java.lang.String
failMessageLength(int expectedLen, int actualLen, int[] indices)
private static <E> int
invokeCompare(E obj1, E obj2, java.util.Comparator<E> cmp)
Returnscmp.compare(expected, actual)
if possible.static double
test()
static boolean
testAbsEquals(double expected, double actual, double absdev)
Returns whether the absolute deviation betweenexpected
andactual
exceedsabsdiv
in absolute value.static boolean
testRelEquals(double expected, double actual, double reldev)
Returns whether the relative deviation betweenexpected
andactual
exceedsreldiv
in absolute value.private static void
thrwAccessible(java.lang.reflect.Method method)
private static void
thrwWrongArgs(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 objectsexpected
andactual
defined 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
actual
cloase 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)
yields0
x.norm(y)
andy.norm(x)
yield the same result,x.norm(y)+y.norm(z)\(\ge\) x.norm(z)
.
actual
close toexpected
i.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.-
norm
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
-
- 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 ifactual
isnull
oractual
deviates fromexpected
by 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)
withCls
the 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 fromexpected
by at mostdelta
in 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)
yields0
x.norm(y)
andy.norm(x)
yield the same result,x.norm(y)+y.norm(z)\(\ge\) x.norm(z)
.
delta
- the allowed deviation as adouble
value.- Throws:
java.lang.IllegalArgumentException
- if the test cannot be performed, i.e.-
norm
isnull
or 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==null
or - 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 ofexpected
defined 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()
yields0
iffx
represents the zero vector. -
(sx).norm()=s(x.norm())
wheresx
ands(...)
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
expected
defined by the method namednorm
. - Throws:
java.lang.IllegalArgumentException
- if the test cannot be performed, i.e.-
norm
does 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 ifactual
isnull
oractual
deviates fromexpected
by 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. neithernorm
norexpected
isnull
, andactual
isnull
.- Parameters:
norm
- name of a member method in classCls
with signaturedouble norm(Cls actual)
.expected
- anObject
with typeCls
; in particular notnull
.actual
- anotherObject
; in particular notnull
.- Throws:
java.lang.IllegalArgumentException
- ifnorm==null
orexpected==null
.junit.framework.AssertionFailedError
- ifnorm,expected!=null
butactual==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
- anObject
ornull
.- 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 ifactualElement
is not an element ofexpectedContainer
.- Parameters:
expectedContainer
- aCollection
the objectactualElement
is expected to be contained in.actualElement
- an instance of anObject
.- Throws:
junit.framework.AssertionFailedError
- ifactualElement
is not inexpectedContainer
and in particular if it isnull
.
-
assertIsContainedAll
public static <E> void assertIsContainedAll(java.util.Collection<E> expected, java.util.Collection<E> actual)
Fails ifactual
is not a subcollection ofexpected
.- Parameters:
expected
- aCollection
actual
- anotherCollection
- Throws:
junit.framework.AssertionFailedError
- ifactual
is 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
- anObject
ornull
. Actually this should be aComparable
as well.- Throws:
java.lang.IllegalArgumentException
- if invokingexpected.compareTo(actual)
raises an exception. In particular forexpected == null
java.lang.IllegalStateException
- ifexpected.compare(actual)
is evaluated foractual == null
without 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
- anObject
ornull
. Actually this should be aComparable
as well.- Throws:
java.lang.IllegalArgumentException
- if invokingexpected.compareTo(actual)
raises an exception. In particular forexpected == null
java.lang.IllegalStateException
- ifexpected.compare(actual)
is evaluated foractual == null
without 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 comparingobj1
withobj2
.- Returns:
- the
int
value 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 arenull
and 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,expected
andactual
arenull
. - 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
- ifexpected
is 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 whetherexpected
is 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 ofexpected
and ofactual
do not coincide.- Parameters:
expected
- the expected array.actual
- the actual array.- Throws:
java.lang.IllegalArgumentException
- ifexpected
is 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 arraysexpected
andactual
within 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 pathindices
deviate 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 adouble
value.- Throws:
java.lang.IllegalArgumentException
- ifexpected
is 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 arraysexpected
andactual
within the arrays comprising them. The recursion starts withindices = new int[] {}
. This is for generating an appropriate message for anAssertionFailedError
.delta
- the allowed deviation as adouble
value.- Throws:
java.lang.IllegalArgumentException
- ifexpected
oractual
is 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
- ifexpected
is not 'finally' of primitive type.
-
testRelEquals
public static boolean testRelEquals(double expected, double actual, double reldev)
Returns whether the relative deviation betweenexpected
andactual
exceedsreldiv
in absolute value.- Parameters:
expected
- thedouble
value expected. This may be neither0.0
, nor an infinite value norNaN
.actual
- the actualdouble
value.reldev
- the maximum relative deviation betweenexpected
andactual
. This must be a non-negative value; in particular,NaN
is not allowed.- Returns:
- whether the relative deviation
between
expected
andactual
exceedsreldiv
in absolute value. - Throws:
java.lang.IllegalArgumentException
--
if
expected
is either0.0
, infinite orNaN
. -
if
reldev
is 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 betweenexpected
andactual
exceedsreldiv
in absolute value.- Parameters:
message
- the error message used in case the assertion fails.expected
- thedouble
value expected. This may be neither0.0
, nor an infinite value norNaN
.actual
- the actualdouble
value.reldev
- the maximum relative deviation betweenexpected
andactual
. This must be a non-negative value; in particular,NaN
is not allowed.- Throws:
java.lang.IllegalArgumentException
--
if
expected
is either0.0
, infinite orNaN
. -
if
reldev
is 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 betweenexpected
andactual
exceedsreldiv
in absolute value.- Parameters:
expected
- thedouble
value expected. This may be neither0.0
, nor an infinite value norNaN
.actual
- the actualdouble
value.reldev
- the maximum relative deviation betweenexpected
andactual
. This must be a non-negative value; in particular,NaN
is not allowed.- Throws:
java.lang.IllegalArgumentException
--
if
expected
is either0.0
, infinite orNaN
. -
if
reldev
is 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<= separateAbsRel
behaves 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
- thedouble
value expected.separateAbsRel
- a non-negativedouble
value separating the two parts of the domain of this method.actual
- the actualdouble
value.absdev
- the maximum absolute deviation betweenexpected
andactual
. This is relevant forexpected<= separateAbsRel
but ignored otherwise.reldev
- the maximum relative deviation betweenexpected
andactual
. This is relevant forexpected > separateAbsRel
but ignored otherwise.- Throws:
java.lang.IllegalArgumentException
- forseparateAbsRel < 0
.
-
assertAbsRelEquals
public static void assertAbsRelEquals(double expected, double separateAbsRel, double actual, double absdev, double reldev)
Forexpected<= separateAbsRel
behaves likeAssert.assertEquals(String,double,double,double)
ignoringreldev
, whereas otherwise behaves likeAssert.assertEquals(String, double, double, double)
ignoringabsdev
.- Parameters:
expected
- thedouble
value expected.separateAbsRel
- a non-negativedouble
value separating the two parts of the domain of this method.actual
- the actualdouble
value.absdev
- the maximum absolute deviation betweenexpected
andactual
. This is relevant forexpected<= separateAbsRel
but ignored otherwise.reldev
- the maximum relative deviation betweenexpected
andactual
. This is relevant forexpected > separateAbsRel
but ignored otherwise.- Throws:
java.lang.IllegalArgumentException
- forseparateAbsRel < 0
.
-
testAbsEquals
public static boolean testAbsEquals(double expected, double actual, double absdev)
Returns whether the absolute deviation betweenexpected
andactual
exceedsabsdiv
in absolute value.- Parameters:
expected
- thedouble
value expected. This may not beNaN
.actual
- the actualdouble
value.absdev
- the maximum absolute deviation betweenexpected
andactual
. This must be a non-negative value; in particular,NaN
is not allowed.- Returns:
- whether the absolute deviation
between
expected
andactual
exceedsabsdiv
in absolute value. - Throws:
java.lang.IllegalArgumentException
--
if
expected
isNaN
. -
if
absdev
is 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 betweenexpected
andactual
exceedsabsdiv
in absolute value.- Parameters:
message
- the error message used in case the assertion fails.expected
- thedouble
value expected. This may not be neitherNaN
.actual
- the actualdouble
value.absdev
- the maximum absolute deviation betweenexpected
andactual
. This must be a non-negative value; in particular,NaN
is not allowed.- Throws:
java.lang.IllegalArgumentException
--
if
expected
isNaN
. -
if
absdev
is 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 betweenexpected
andactual
exceedsabsdiv
in absolute value.- Parameters:
expected
- thedouble
value expected. This may not be neitherNaN
.actual
- the actualdouble
value.absdev
- the maximum absolute deviation betweenexpected
andactual
. This must be a non-negative value; in particular,NaN
is not allowed.- Throws:
java.lang.IllegalArgumentException
--
if
expected
isNaN
. -
if
absdev
is 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 ofexpected
withactual
. This is suitable for keeping long strings under control. If one of the arguments isnull
, this method behaves likeAssert.assertEquals(Object, Object)
.- Parameters:
expected
- theString
expected. This maactual
- aString
value
-
test
public static double test()
-
-