public final class PrimitiveFloatArraySubject extends AbstractArraySubject<PrimitiveFloatArraySubject,float[]>
float[]
.
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 |
PrimitiveFloatArraySubject.TolerantPrimitiveFloatArrayComparison
A partially specified proposition about an approximate relationship to a
float[]
subject using a tolerance. |
failureStrategy
Modifier and Type | Method and Description |
---|---|
PrimitiveFloatArraySubject.TolerantPrimitiveFloatArrayComparison |
hasValuesNotWithin(float tolerance)
Deprecated.
Write a for loop over the values looking for mismatches (see this implementation
for an example)
|
PrimitiveFloatArraySubject.TolerantPrimitiveFloatArrayComparison |
hasValuesWithin(float 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 floats). |
void |
isEqualTo(Object expected)
Deprecated.
use either
usingTolerance(someTolerance).containsExactly(someValues).inOrder() or usingExactEquality().containsExactly(someValues).inOrder() |
void |
isEqualTo(Object expected,
float 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
Floats.asList(float...) , and do the assertion on that, e.g. assertThat(asList(actualFloatArray)).isNotEqualTo(asList(expectedFloatArray)); . |
void |
isNotEqualTo(Object expectedArray,
float tolerance)
Deprecated.
Write a for loop over the values looking for mismatches (see this implementation
for an example)
|
protected List<Float> |
listRepresentation()
Returns a List representation suitable for displaying in a string.
|
protected String |
underlyingType() |
IterableSubject.UsingCorrespondence<Float,Float> |
usingExactEquality()
Starts a method chain for a test proposition in which the actual values (i.e.
|
IterableSubject.UsingCorrespondence<Number,Number> |
usingTolerance(float tolerance)
Starts a method chain for a test proposition in which the actual values (i.e.
|
actualCustomStringRepresentation, hasLength, isEmpty, isNotEmpty
actual, 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, named
protected String underlyingType()
protected List<Float> listRepresentation()
AbstractArraySubject
@Deprecated public void isEqualTo(Object expected)
usingTolerance(someTolerance).containsExactly(someValues).inOrder()
or usingExactEquality().containsExactly(someValues).inOrder()
UnsupportedOperationException
.isEqualTo
in class Subject<PrimitiveFloatArraySubject,float[]>
@Deprecated public void isEqualTo(Object expected, float 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)
Floats.asList(float...)
, and do the assertion on that, e.g. assertThat(asList(actualFloatArray)).isNotEqualTo(asList(expectedFloatArray));
.UnsupportedOperationException
.isNotEqualTo
in class Subject<PrimitiveFloatArraySubject,float[]>
@Deprecated public void isNotEqualTo(Object expectedArray, float 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 PrimitiveFloatArraySubject.TolerantPrimitiveFloatArrayComparison hasValuesWithin(float tolerance)
tolerance
of each other, that is assertThat(actual[i]).isWithin(tolerance).of(expected[i])
passes for all i
(see the
isWithin
assertion for floats).
The check will fail if any value in either the subject array or the object array is Float.POSITIVE_INFINITY
, Float.NEGATIVE_INFINITY
, or Float.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 Float.NaN
, Float.POSITIVE_INFINITY
, or negative, including -0.0f
@Deprecated public PrimitiveFloatArraySubject.TolerantPrimitiveFloatArrayComparison hasValuesNotWithin(float 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 floats).
In the case (b), a pair of subject and object values will not cause the test to pass if
either of them is Float.POSITIVE_INFINITY
, Float.NEGATIVE_INFINITY
, or Float.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 Float.NaN
, Float.POSITIVE_INFINITY
, or negative, including -0.0f
public IterableSubject.UsingCorrespondence<Number,Number> usingTolerance(float 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(actualFloatArray).usingTolerance(1.0e-5f).contains(3.14159f);
-0.0f
to be within any tolerance of 0.0f
.
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 Float.NaN
, Float.POSITIVE_INFINITY
, or negative, including -0.0f
public IterableSubject.UsingCorrespondence<Float,Float> usingExactEquality()
Correspondence
which
considers values to correspond if they are exactly equal, with equality defined by Float.equals(java.lang.Object)
. This method is not recommended when the code under test is doing any
kind of arithmetic: use usingTolerance(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. The proposition is actually executed by continuing the
method chain. For example:
assertThat(actualFloatArray).usingExactEquality().contains(3.14159f);
Float.POSITIVE_INFINITY
, Float.NEGATIVE_INFINITY
, and
Float.NaN
to be equal to themselves.
-0.0f
to be equal to 0.0f
.
NullPointerException
if any
expected Float
instance is null.
Copyright © 2016. All Rights Reserved.