public final class PrimitiveDoubleArraySubject extends AbstractArraySubject<PrimitiveDoubleArraySubject,double[]>
double[].
Note: this class deprecates some common methods because the operation of equality and comparison on floating point numbers requires additional specification. Alternative equality tests are provided.
| Modifier and Type | Class and Description |
|---|---|
static class |
PrimitiveDoubleArraySubject.TolerantPrimitiveDoubleArrayComparison
A partially specified proposition about an approximate relationship to a
double[]
subject using a tolerance. |
failureStrategy| Modifier and Type | Method and Description |
|---|---|
PrimitiveDoubleArraySubject.TolerantPrimitiveDoubleArrayComparison |
hasValuesNotWithin(double tolerance)
Deprecated.
Write a for loop over the values looking for mismatches (see this implementation
for an example)
|
PrimitiveDoubleArraySubject.TolerantPrimitiveDoubleArrayComparison |
hasValuesWithin(double tolerance)
Prepares for a check that the subject and object are arrays both (a) of the same length, and
(b) where the values at all corresponding positions in each array are finite values within
tolerance of each other, that is assertThat(actual[i]).isWithin(tolerance).of(expected[i]) passes for all i (see the
isWithin assertion for doubles). |
void |
isEqualTo(Object expected)
Deprecated.
use either
usingTolerance(someTolerance).containsExactly(someValues).inOrder() or usingExactEquality().containsExactly(someValues).inOrder() |
void |
isEqualTo(Object expected,
double tolerance)
Deprecated.
use
usingTolerance(someTolerance).containsExactly(someValues).inOrder(),
noting the different behaviour for non-finite values |
void |
isNotEqualTo(Object expected)
Deprecated.
If you really want this, convert the array to a list, possibly using
Doubles.asList(double...), and do the assertion on that, e.g. assertThat(asList(actualDoubleArray)).isNotEqualTo(asList(expectedDoubleArray));. |
void |
isNotEqualTo(Object expectedArray,
double tolerance)
Deprecated.
Write a for loop over the values looking for mismatches (see this implementation
for an example)
|
protected List<Double> |
listRepresentation()
Returns a List representation suitable for displaying in a string.
|
protected String |
underlyingType() |
IterableSubject.UsingCorrespondence<Double,Double> |
usingExactEquality()
Starts a method chain for a test proposition in which the actual values (i.e.
|
IterableSubject.UsingCorrespondence<Number,Number> |
usingTolerance(double tolerance)
Starts a method chain for a test proposition in which the actual values (i.e.
|
actualCustomStringRepresentation, hasLength, isEmpty, isNotEmptyactual, actualAsString, check, equals, fail, fail, fail, failWithBadResults, failWithCustomSubject, failWithoutActual, failWithoutSubject, failWithRawMessage, getDisplaySubject, getSubject, hashCode, internalCustomName, isAnyOf, isIn, isInstanceOf, isNoneOf, isNotIn, isNotInstanceOf, isNotNull, isNotSameAs, isNull, isSameAs, namedprotected String underlyingType()
protected List<Double> listRepresentation()
AbstractArraySubject@Deprecated public void isEqualTo(Object expected)
usingTolerance(someTolerance).containsExactly(someValues).inOrder() or usingExactEquality().containsExactly(someValues).inOrder()UnsupportedOperationException.isEqualTo in class Subject<PrimitiveDoubleArraySubject,double[]>@Deprecated public void isEqualTo(Object expected, double tolerance)
usingTolerance(someTolerance).containsExactly(someValues).inOrder(),
noting the different behaviour for non-finite valuesexpected is equal to each element in the subject,
and in the same position.
Behaviour for non-finite values (POSITIVE_INFINITY, NEGATIVE_INFINITY, and NaN) is as follows: If the
subject and the object of the assertion are the same array, the test will pass. If not
(including if one is a clone of the other) then non-finite values are considered not equal so
the any non-finite value in either argument will cause the test to fail.
@Deprecated public void isNotEqualTo(Object expected)
Doubles.asList(double...), and do the assertion on that, e.g. assertThat(asList(actualDoubleArray)).isNotEqualTo(asList(expectedDoubleArray));.UnsupportedOperationException.isNotEqualTo in class Subject<PrimitiveDoubleArraySubject,double[]>@Deprecated public void isNotEqualTo(Object expectedArray, double tolerance)
Behaviour for non-finite values (POSITIVE_INFINITY, NEGATIVE_INFINITY, and NaN) is as follows: If the
subject and the object of the assertion are the same array, the test will fail. If not
(including if one is a clone of the other) then non-finite values are considered not equal so
the any non-finite value in either argument will cause the test to pass.
public PrimitiveDoubleArraySubject.TolerantPrimitiveDoubleArrayComparison hasValuesWithin(double tolerance)
tolerance of each other, that is assertThat(actual[i]).isWithin(tolerance).of(expected[i]) passes for all i (see the
isWithin assertion for doubles).
The check will fail if any value in either the subject array or the object array is Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, or Double.NaN.
tolerance - an inclusive upper bound on the difference between the subject and object
allowed by the check, which must be a non-negative finite value, i.e. not Double.NaN, Double.POSITIVE_INFINITY, or negative, including -0.0@Deprecated public PrimitiveDoubleArraySubject.TolerantPrimitiveDoubleArrayComparison hasValuesNotWithin(double tolerance)
tolerance of each other, that is assertThat(actual[i]).isNotWithin(tolerance).of(expected[i]) passes for at least one i
(see the isNotWithin assertion for doubles).
In the case (b), a pair of subject and object values will not cause the test to pass if
either of them is Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, or Double.NaN.
tolerance - an exclusive lower bound on the difference between the subject and object
allowed by the check, which must be a non-negative finite value, i.e. not Double.NaN, Double.POSITIVE_INFINITY, or negative, including -0.0public IterableSubject.UsingCorrespondence<Number,Number> usingTolerance(double tolerance)
Correspondence which
considers values to correspond if they are finite values within tolerance of each
other. The proposition is actually executed by continuing the method chain. For example:
assertThat(actualDoubleArray).usingTolerance(1.0e-5).contains(3.14159);
-0.0 to be within any tolerance of 0.0.
Number instances which will
be converted to doubles, which may result in a loss of precision for some numeric types.
NullPointerException if any
expected Number instance is null.
tolerance - an inclusive upper bound on the difference between the double values of the
actual and expected numbers, which must be a non-negative finite value, i.e. not Double.NaN, Double.POSITIVE_INFINITY, or negative, including -0.0public IterableSubject.UsingCorrespondence<Double,Double> usingExactEquality()
Correspondence which
considers values to correspond if they are exactly equal, with equality defined by Double.equals(java.lang.Object). This method is not recommended when the code under test is doing any
kind of arithmetic: use usingTolerance(double) with a suitable tolerance in that case.
(Remember that the exact result of floating point arithmetic is sensitive to apparently trivial
changes such as replacing (a + b) + c with a + (b + c), and that unless strictfp is in force even the result of (a + b) + c is sensitive to the JVM's choice
of precision for the intermediate result.) This method is recommended when the code under test
is specified as either copying a value without modification from its input or returning a
well-defined literal or constant value. The proposition is actually executed by continuing the
method chain. For example:
assertThat(actualDoubleArray).usingExactEquality().contains(3.14159);
Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, and
Double.NaN to be equal to themselves.
-0.0 to be equal to 0.0.
NullPointerException if any
expected Double instance is null.
Copyright © 2016. All rights reserved.