org.assertj.core.api
Interface FloatingPointNumberAssert<S extends FloatingPointNumberAssert<S,A>,A extends Number>

Type Parameters:
S - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation" for more details.
A - the type of the "actual" value.
All Superinterfaces:
NumberAssert<S,A>
All Known Implementing Classes:
AbstractDoubleAssert, AbstractFloatAssert, DoubleAssert, FloatAssert

public interface FloatingPointNumberAssert<S extends FloatingPointNumberAssert<S,A>,A extends Number>
extends NumberAssert<S,A>

Assertion methods applicable to floating-point Numbers.

Author:
Alex Ruiz, Yvonne Wang, Mikhail Mazursky

Method Summary
 S isCloseTo(A expected, Offset<A> offset)
          Verifies that the actual number is close to the given one within the given offset.
If difference is equal to offset value, assertion is considered valid.
 S isEqualTo(A expected, Offset<A> offset)
          Verifies that the actual value is close to the given one by less than the given offset.
If difference is equal to offset value, assertion is considered valid.
 S isNaN()
          Verifies that the actual value is equal to NaN.
 S isNotNaN()
          Verifies that the actual value is not equal to NaN.
 
Methods inherited from interface org.assertj.core.api.NumberAssert
isBetween, isNegative, isNotNegative, isNotPositive, isNotZero, isPositive, isStrictlyBetween, isZero
 

Method Detail

isEqualTo

S isEqualTo(A expected,
            Offset<A> offset)
Verifies that the actual value is close to the given one by less than the given offset.
If difference is equal to offset value, assertion is considered valid.

Example with double:

 // assertion will pass:
 assertThat(8.1).isEqualTo(new Double(8.0), offset(0.2));

 // if difference is exactly equals to the offset (0.1), it's ok
 assertThat(8.1).isEqualTo(new Double(8.0), offset(0.1));

 // within is an alias of offset
 assertThat(8.1).isEqualTo(new Double(8.0), within(0.1));

 // assertion will fail
 assertThat(8.1).isEqualTo(new Double(8.0), offset(0.01));
 

Parameters:
expected - the given value to compare the actual value to.
offset - the given positive offset.
Returns:
this assertion object.
Throws:
NullPointerException - if the given offset is null.
NullPointerException - if the expected number is null.
AssertionError - if the actual value is not equal to the given one.

isCloseTo

S isCloseTo(A expected,
            Offset<A> offset)
Verifies that the actual number is close to the given one within the given offset.
If difference is equal to offset value, assertion is considered valid.

Example with double:

 // assertions will pass:
 assertThat(8.1).isCloseTo(new Double(8.0), within(0.2));

 // you can use offset if you prefer
 assertThat(8.1).isCloseTo(new Double(8.0), offset(0.2));

 // if difference is exactly equals to the offset (0.1), it's ok
 assertThat(8.1).isCloseTo(new Double(8.0), within(0.1));

 // assertion will fail
 assertThat(8.1).isCloseTo(new Double(8.0), within(0.01));
 

Parameters:
expected - the given number to compare the actual value to.
offset - the given positive offset.
Returns:
this assertion object.
Throws:
NullPointerException - if the given offset is null.
NullPointerException - if the expected number is null.
AssertionError - if the actual value is not equal to the given one.

isNaN

S isNaN()
Verifies that the actual value is equal to NaN.

Returns:
this assertion object.
Throws:
AssertionError - if the actual value is not equal to NaN.

isNotNaN

S isNotNaN()
Verifies that the actual value is not equal to NaN.

Returns:
this assertion object.
Throws:
AssertionError - if the actual value is equal to NaN.


Copyright © 2013–2015 AssertJ. All rights reserved.