public final class DoubleSubject extends ComparableSubject<Double>
Double
subjects.Modifier and Type  Class and Description 

static class 
DoubleSubject.TolerantDoubleComparison
A partially specified check about an approximate relationship to a
double subject using
a tolerance. 
Modifier and Type  Method and Description 

void 
isAtLeast(int other)
Checks that the subject is greater than or equal to
other . 
void 
isAtMost(int other)
Checks that the subject is less than or equal to
other . 
void 
isEqualTo(Object other)
Asserts that the subject is exactly equal to the given value, with equality defined as by
Double#equals . 
void 
isEquivalentAccordingToCompareTo(Double other)
Deprecated.
Use
isWithin(double) or isEqualTo(java.lang.Object) instead (see documentation for advice). 
void 
isFinite()
Asserts that the subject is finite, i.e.

void 
isGreaterThan(int other)
Checks that the subject is greater than
other . 
void 
isLessThan(int other)
Checks that the subject is less than
other . 
void 
isNaN()
Asserts that the subject is
Double.NaN . 
void 
isNegativeInfinity()
Asserts that the subject is
Double.NEGATIVE_INFINITY . 
void 
isNonZero()
Asserts that the subject is a nonnull value other than zero (i.e.

void 
isNotEqualTo(Object other)
Asserts that the subject is not exactly equal to the given value, with equality defined as by
Double#equals . 
void 
isNotNaN()
Asserts that the subject is a nonnull value other than
Double.NaN (but it may be
Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY ). 
DoubleSubject.TolerantDoubleComparison 
isNotWithin(double tolerance)
Prepares for a check that the subject is a finite number not within the given tolerance of an
expected value that will be provided in the next call in the fluent chain.

void 
isPositiveInfinity()
Asserts that the subject is
Double.POSITIVE_INFINITY . 
DoubleSubject.TolerantDoubleComparison 
isWithin(double tolerance)
Prepares for a check that the subject is a finite number within the given tolerance of an
expected value that will be provided in the next call in the fluent chain.

void 
isZero()
Asserts that the subject is zero (i.e.

isAtLeast, isAtMost, isGreaterThan, isIn, isLessThan, isNotIn
actualCustomStringRepresentation, check, equals, failWithActual, failWithActual, failWithoutActual, hashCode, ignoreCheck, isAnyOf, isIn, isInstanceOf, isNoneOf, isNotIn, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toString
public DoubleSubject.TolerantDoubleComparison isWithin(double tolerance)
The check will fail if either the subject or the object is Double.POSITIVE_INFINITY
,
Double.NEGATIVE_INFINITY
, or Double.NaN
. To check for those values, use isPositiveInfinity()
, isNegativeInfinity()
, isNaN()
, or (with more generality)
isEqualTo(java.lang.Object)
.
The check will pass if both values are zero, even if one is 0.0
and the other is
0.0
. Use #isEqualTo
to assert that a value is exactly 0.0
or that it
is exactly 0.0
.
You can use a tolerance of 0.0
to assert the exact equality of finite doubles, but
often isEqualTo(java.lang.Object)
is preferable (note the different behaviours around nonfinite values
and 0.0
). See the documentation on isEqualTo(java.lang.Object)
for advice on when exact
equality assertions are appropriate.
tolerance
 an inclusive upper bound on the difference between the subject and object
allowed by the check, which must be a nonnegative finite value, i.e. not Double.NaN
, Double.POSITIVE_INFINITY
, or negative, including 0.0
public DoubleSubject.TolerantDoubleComparison isNotWithin(double tolerance)
The check will fail if either the subject or the object is Double.POSITIVE_INFINITY
,
Double.NEGATIVE_INFINITY
, or Double.NaN
. See isFinite()
, isNotNaN()
, or isNotEqualTo(java.lang.Object)
for checks with other behaviours.
The check will fail if both values are zero, even if one is 0.0
and the other is
0.0
. Use #isNotEqualTo
for a test which fails for a value of exactly zero with
one sign but passes for zero with the opposite sign.
You can use a tolerance of 0.0
to assert the exact nonequality of finite doubles,
but sometimes isNotEqualTo(java.lang.Object)
is preferable (note the different behaviours around
nonfinite values and 0.0
).
tolerance
 an exclusive lower bound on the difference between the subject and object
allowed by the check, which must be a nonnegative finite value, i.e. not Double.NaN
, Double.POSITIVE_INFINITY
, or negative, including 0.0
public final void isEqualTo(@NullableDecl Object other)
Double#equals
. This method is not recommended when the code under test is doing
any kind of arithmetic: use isWithin(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.
Note: The assertion isEqualTo(0.0)
fails for an input of 0.0
, and
vice versa. For an assertion that passes for either 0.0
or 0.0
, use isZero()
.
public final void isNotEqualTo(@NullableDecl Object other)
Double#equals
. See isEqualTo(java.lang.Object)
for advice on when exact equality is recommended.
Use isNotWithin(double)
for an assertion with a tolerance.
Note: The assertion isNotEqualTo(0.0)
passes for 0.0
, and vice
versa. For an assertion that fails for either 0.0
or 0.0
, use isNonZero()
.
isNotEqualTo
in class Subject
@Deprecated public final void isEquivalentAccordingToCompareTo(Double other)
isWithin(double)
or isEqualTo(java.lang.Object)
instead (see documentation for advice).ComparableSubject
other
according to Comparable.compareTo(T)
, (i.e., checks that a.comparesTo(b) == 0
).
Note: Do not use this method for checking object equality. Instead, use Subject.isEqualTo(Object)
.
isEquivalentAccordingToCompareTo
in class ComparableSubject<Double>
public final void isZero()
0.0
or 0.0
).public final void isNonZero()
0.0
,
0.0
or null
).public final void isPositiveInfinity()
Double.POSITIVE_INFINITY
.public final void isNegativeInfinity()
Double.NEGATIVE_INFINITY
.public final void isNaN()
Double.NaN
.public final void isFinite()
Double.POSITIVE_INFINITY
, Double.NEGATIVE_INFINITY
, or Double.NaN
.public final void isNotNaN()
Double.NaN
(but it may be
Double.POSITIVE_INFINITY
or Double.NEGATIVE_INFINITY
).public final void isGreaterThan(int other)
other
.
To check that the subject is greater than or equal to other
, use isAtLeast(int)
.
public final void isLessThan(int other)
other
.
To check that the subject is less than or equal to other
, use isAtMost(int)
.
public final void isAtMost(int other)
other
.
To check that the subject is strictly less than other
, use isLessThan(int)
.
public final void isAtLeast(int other)
other
.
To check that the subject is strictly greater than other
, use isGreaterThan(int)
.
Copyright © 2019. All rights reserved.