public final class PrimitiveFloatArraySubject extends Subject<S,T>
float[]
.Modifier and Type  Class and Description 

static class 
PrimitiveFloatArraySubject.FloatArrayAsIterable
A partially specified proposition 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 float equality: see usingExactEquality() and usingTolerance(double) . 
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 

protected String 
actualCustomStringRepresentation()
Supplies the direct string representation of the actual value to other methods which may prefix
or otherwise position it in an error message.

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

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)
Deprecated.
Use
usingTolerance(double) , e.g. assertThat(floatArray).usingTolerance(1e5).containsExactly(1.2f, 3.4f, 5.6f).inOrder(); 
void 
isEmpty()
Fails if the array is not empty (i.e.

void 
isEqualTo(Object expected)
A proposition 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(float[], float[]) and Float.equals(Object) define it (which is
different to the way that the == operator on primitive float defines it). 
void 
isEqualTo(Object expected,
float tolerance)
Deprecated.
use
usingTolerance(someTolerance).containsExactly(someValues).inOrder() ,
noting the different behaviour for nonfinite values 
void 
isNotEmpty()
Fails if the array is empty (i.e.

void 
isNotEqualTo(Object expected)
A proposition 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(float[], float[]) and Float.equals(Object) define it (which is
different to the way that the == operator on primitive float defines it). 
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() 
PrimitiveFloatArraySubject.FloatArrayAsIterable 
usingExactEquality()
Starts a method chain for a test proposition in which the actual values (i.e.

PrimitiveFloatArraySubject.FloatArrayAsIterable 
usingTolerance(double tolerance)
Starts a method chain for a test proposition in which the actual values (i.e.

actual, actualAsString, check, equals, fail, fail, fail, failComparing, failComparing, failWithBadResults, failWithCustomSubject, failWithoutActual, failWithoutSubject, failWithRawMessage, failWithRawMessageAndCause, getDisplaySubject, getSubject, hashCode, ignoreCheck, internalCustomName, isAnyOf, isIn, isInstanceOf, isNoneOf, isNotIn, isNotInstanceOf, isNotNull, isNotSameAs, isNull, isSameAs, named
protected String underlyingType()
protected List<Float> listRepresentation()
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(float[], float[])
and Float.equals(Object)
define it (which is
different to the way that the ==
operator on primitive float
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.0e5).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.
Float.POSITIVE_INFINITY
, Float.NEGATIVE_INFINITY
, and
Float.NaN
to be equal to themselves (contrast with #usingTolerance(0.0)
which does not).
isEqualTo
in class Subject<PrimitiveFloatArraySubject,float[]>
@Deprecated public void isEqualTo(Object expected, float tolerance)
usingTolerance(someTolerance).containsExactly(someValues).inOrder()
,
noting the different behaviour for nonfinite valuesexpected
are arrays of the same length and
type, containing elements such that each element in expected
is within tolerance
of each element in the subject, and in the same position.
Behaviour for nonfinite 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 nonfinite values are considered not equal so
the any nonfinite value in either argument will cause the test to fail.
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(float[], float[])
and Float.equals(Object)
define it (which is
different to the way that the ==
operator on primitive float
defines it). See
isEqualTo(Object)
for advice on when exact equality is recommended.
Float.POSITIVE_INFINITY
, Float.NEGATIVE_INFINITY
, and Float.NaN
to be equal to themselves.
0.0
to be equal to 0.0
.
isNotEqualTo
in class Subject<PrimitiveFloatArraySubject,float[]>
@Deprecated public void isNotEqualTo(Object expectedArray, float tolerance)
expected
are not arrays of the same length and
type, containing elements such that each element in expected
is within tolerance
of each element in the subject, and in the same position.
Behaviour for nonfinite 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 nonfinite values are considered not equal so
the any nonfinite value in either argument will cause the test to pass.
@Deprecated public PrimitiveFloatArraySubject.TolerantPrimitiveFloatArrayComparison hasValuesWithin(float tolerance)
usingTolerance(double)
, e.g. assertThat(floatArray).usingTolerance(1e5).containsExactly(1.2f, 3.4f, 5.6f).inOrder();
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 nonnegative 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 nonnegative finite value, i.e. not Float.NaN
, Float.POSITIVE_INFINITY
, or negative, including 0.0f
public PrimitiveFloatArraySubject.FloatArrayAsIterable 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(actualFloatArray).usingTolerance(1.0e5f).contains(3.14159f);
0.0f
to be within any tolerance of 0.0f
.
Number
instances which
will be converted to floats, 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 float values of the
actual and expected numbers, which must be a nonnegative finite value, i.e. not Float.NaN
, Float.POSITIVE_INFINITY
, or negative, including 0.0f
public PrimitiveFloatArraySubject.FloatArrayAsIterable 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(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 proposition is actually executed by continuing the
method chain. For example:
assertThat(actualFloatArray).usingExactEquality().contains(3.14159f);
For convenience, some subsequent methods accept expected values as Number
instances.
These numbers must be either of type Float
, Integer
, or Long
, and if
they are Integer
or Long
then their absolute values must not exceed 2^24 which
is 16,777,216. (This restriction ensures that the expected values have exact Float
representations: using exact equality makes no sense if they do not.)
Float.POSITIVE_INFINITY
, Float.NEGATIVE_INFINITY
, and Float.NaN
to be equal to themselves (contrast with #usingTolerance(0.0)
which does not).
public void isEmpty()
array.length != 0
).public void isNotEmpty()
array.length == 0
).public void hasLength(int length)
IllegalArgumentException
 if length < 0
protected String actualCustomStringRepresentation()
Subject
Subjects should override this with care.
By default, this returns String.ValueOf(getActualValue())
.
actualCustomStringRepresentation
in class Subject<S extends com.google.common.truth.AbstractArraySubject<S,T>,T>
Copyright © 2017. All Rights Reserved.