public final class PrimitiveDoubleArraySubject extends Subject
double[]
.Modifier and Type  Class and Description 

static class 
PrimitiveDoubleArraySubject.DoubleArrayAsIterable
A partially specified check for doing assertions on the array similar to the assertions
supported for
Iterable subjects, in which the elements of the array under test are
compared to expected elements using either exact or tolerant double equality: see usingExactEquality() and usingTolerance(double) . 
Modifier and Type  Method and Description 

void 
hasLength(int length)
Fails if the array does not have the given length.

void 
isEmpty()
Fails if the array is not empty (i.e.

void 
isEqualTo(Object expected)
A check that the actual array and
expected are arrays of the same length and type,
containing elements such that each element in expected is equal to each element in the
actual array, and in the same position, with element equality defined the same way that Arrays.equals(double[], double[]) and Double.equals(Object) define it (which is
different to the way that the == operator on primitive double defines it). 
void 
isNotEmpty()
Fails if the array is empty (i.e.

void 
isNotEqualTo(Object expected)
A check that the actual array and
expected are not arrays of the same length and type,
containing elements such that each element in expected is equal to each element in the
actual array, and in the same position, with element equality defined the same way that Arrays.equals(double[], double[]) and Double.equals(Object) define it (which is
different to the way that the == operator on primitive double defines it). 
PrimitiveDoubleArraySubject.DoubleArrayAsIterable 
usingExactEquality()
Starts a method chain for a check in which the actual values (i.e.

PrimitiveDoubleArraySubject.DoubleArrayAsIterable 
usingTolerance(double tolerance)
Starts a method chain for a check in which the actual values (i.e.

actualCustomStringRepresentation, check, equals, failWithActual, failWithActual, failWithoutActual, hashCode, ignoreCheck, isAnyOf, isIn, isInstanceOf, isNoneOf, isNotIn, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toString
public void isEqualTo(Object expected)
expected
are arrays of the same length and type,
containing elements such that each element in expected
is equal to each element in the
actual array, and in the same position, with element equality defined the same way that Arrays.equals(double[], double[])
and Double.equals(Object)
define it (which is
different to the way that the ==
operator on primitive double
defines it). 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, e.g. assertThat(actualArray).usingTolerance(1.0e10).containsExactly(expectedArray).inOrder()
.
(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 values without modification from its input or returning
welldefined literal or constant values.
Double.POSITIVE_INFINITY
, Double.NEGATIVE_INFINITY
, and
Double.NaN
to be equal to themselves (contrast with usingTolerance(0.0)
which does not).
0.0
to be equal to 0.0
(contrast with usingTolerance(0.0)
which does).
public void isNotEqualTo(Object expected)
expected
are not arrays of the same length and type,
containing elements such that each element in expected
is equal to each element in the
actual array, and in the same position, with element equality defined the same way that Arrays.equals(double[], double[])
and Double.equals(Object)
define it (which is
different to the way that the ==
operator on primitive double
defines it). See
isEqualTo(Object)
for advice on when exact equality is recommended.
Double.POSITIVE_INFINITY
, Double.NEGATIVE_INFINITY
, and
Double.NaN
to be equal to themselves.
0.0
to be equal to 0.0
.
isNotEqualTo
in class Subject
public PrimitiveDoubleArraySubject.DoubleArrayAsIterable usingTolerance(double tolerance)
Correspondence
which considers
values to correspond if they are finite values within tolerance
of each other. The
check is actually executed by continuing the method chain. For example:
assertThat(actualDoubleArray).usingTolerance(1.0e5).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 nonnegative finite value, i.e. not Double.NaN
, Double.POSITIVE_INFINITY
, or negative, including 0.0
public PrimitiveDoubleArraySubject.DoubleArrayAsIterable 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 welldefined literal
or constant value. The check is actually executed by continuing the method chain. For example:
assertThat(actualDoubleArray).usingExactEquality().contains(3.14159);
For convenience, some subsequent methods accept expected values as Number
instances.
These numbers must be either of type Double
, Float
, Integer
, or Long
, and if they are Long
then their absolute values must not exceed 2^53 which is
just over 9e15. (This restriction ensures that the expected values have exact Double
representations: using exact equality makes no sense if they do not.)
Double.POSITIVE_INFINITY
, Double.NEGATIVE_INFINITY
, and
Double.NaN
to be equal to themselves (contrast with usingTolerance(0.0)
which does not).
0.0
to be equal to 0.0
(contrast with usingTolerance(0.0)
which does not).
NullPointerException
if any
expected Double
instance is null.
public final void isEmpty()
array.length > 0
).public final void isNotEmpty()
array.length == 0
).public final void hasLength(int length)
IllegalArgumentException
 if length < 0
Copyright © 2019. All rights reserved.