public final class FloatSubject extends ComparableSubject<FloatSubject,Float>
Float
subjects.Modifier and Type | Class and Description |
---|---|
static class |
FloatSubject.TolerantFloatComparison
A partially specified check about an approximate relationship to a
float subject using
a tolerance. |
Modifier and Type | Method and Description |
---|---|
void |
isEqualTo(Float other)
Asserts that the subject is exactly equal to the given value, with equality defined as by
Float#equals . |
void |
isEquivalentAccordingToCompareTo(Float other)
Deprecated.
Use
isWithin(float) or isEqualTo(java.lang.Float) instead (see documentation for advice). |
void |
isFinite()
Asserts that the subject is finite, i.e.
|
void |
isNaN()
Asserts that the subject is
Float.NaN . |
void |
isNegativeInfinity()
Asserts that the subject is
Float.NEGATIVE_INFINITY . |
void |
isNonZero()
Asserts that the subject is a non-null value other than zero (i.e.
|
void |
isNotEqualTo(Float other)
Asserts that the subject is not exactly equal to the given value, with equality defined as by
Float#equals . |
void |
isNotNaN()
Asserts that the subject is a non-null value other than
Float.NaN (but it may be Float.POSITIVE_INFINITY or Float.NEGATIVE_INFINITY ). |
FloatSubject.TolerantFloatComparison |
isNotWithin(float 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
Float.POSITIVE_INFINITY . |
FloatSubject.TolerantFloatComparison |
isWithin(float 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.
|
comparesEqualTo, isAtLeast, isAtMost, isGreaterThan, isIn, isLessThan, isNotIn
actual, actualAsString, actualCustomStringRepresentation, check, check, equals, fail, fail, fail, failComparing, failComparing, failWithActual, failWithActual, failWithBadResults, failWithCustomSubject, failWithoutActual, failWithoutActual, failWithoutSubject, failWithRawMessage, failWithRawMessageAndCause, getSubject, hashCode, ignoreCheck, internalCustomName, isAnyOf, isEqualTo, isIn, isInstanceOf, isNoneOf, isNotEqualTo, isNotIn, isNotInstanceOf, isNotNull, isNotSameAs, isNull, isSameAs, named, toString
public FloatSubject.TolerantFloatComparison isWithin(float tolerance)
The check will fail if either the subject or the object is Float.POSITIVE_INFINITY
,
Float.NEGATIVE_INFINITY
, or Float.NaN
. To check for those values, use isPositiveInfinity()
, isNegativeInfinity()
, isNaN()
, or (with more generality)
isEqualTo(java.lang.Float)
.
The check will pass if both values are zero, even if one is 0.0f
and the other is
-0.0f
. Use #isEqualTo
to assert that a value is exactly 0.0f
or that it
is exactly -0.0f
.
You can use a tolerance of 0.0f
to assert the exact equality of finite floats, but
often isEqualTo(java.lang.Float)
is preferable (note the different behaviours around non-finite values
and -0.0f
). See the documentation on isEqualTo(java.lang.Float)
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 non-negative finite value, i.e. not Float.NaN
, Float.POSITIVE_INFINITY
, or negative, including -0.0f
public FloatSubject.TolerantFloatComparison isNotWithin(float tolerance)
The check will fail if either the subject or the object is Float.POSITIVE_INFINITY
,
Float.NEGATIVE_INFINITY
, or Float.NaN
. See isFinite()
, isNotNaN()
, or isNotEqualTo(java.lang.Float)
for checks with other behaviours.
The check will fail if both values are zero, even if one is 0.0f
and the other is
-0.0f
. 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.0f
to assert the exact non-equality of finite floats,
but sometimes isNotEqualTo(java.lang.Float)
is preferable (note the different behaviours around
non-finite values and -0.0f
).
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 Float.NaN
, Float.POSITIVE_INFINITY
, or negative, including -0.0f
public final void isEqualTo(@NullableDecl Float other)
Float#equals
. This method is not recommended when the code under test is doing
any kind of arithmetic: use isWithin(float)
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.
Note: The assertion isEqualTo(0.0f)
fails for an input of -0.0f
, and
vice versa. For an assertion that passes for either 0.0f
or -0.0f
, use isZero()
.
public final void isNotEqualTo(@NullableDecl Float other)
Float#equals
. See isEqualTo(java.lang.Float)
for advice on when exact equality is recommended.
Use isNotWithin(float)
for an assertion with a tolerance.
Note: The assertion isNotEqualTo(0.0f)
passes for -0.0f
, and vice
versa. For an assertion that fails for either 0.0f
or -0.0f
, use isNonZero()
.
@Deprecated public final void isEquivalentAccordingToCompareTo(Float other)
isWithin(float)
or isEqualTo(java.lang.Float)
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<FloatSubject,Float>
public final void isZero()
0.0f
or -0.0f
).public final void isNonZero()
0.0f
,
-0.0f
or null
).public final void isPositiveInfinity()
Float.POSITIVE_INFINITY
.public final void isNegativeInfinity()
Float.NEGATIVE_INFINITY
.public final void isNaN()
Float.NaN
.public final void isFinite()
Float.POSITIVE_INFINITY
, Float.NEGATIVE_INFINITY
, or Float.NaN
.public final void isNotNaN()
Float.NaN
(but it may be Float.POSITIVE_INFINITY
or Float.NEGATIVE_INFINITY
).Copyright © 2018. All rights reserved.