SELF
- the "self" type of this assertion class. Please read "Emulating
'self types' using Java Generics to simplify fluent API implementation" for more details.ACTUAL
- the type of the "actual" value.public interface FloatingPointNumberAssert<SELF extends FloatingPointNumberAssert<SELF,ACTUAL>,ACTUAL extends Number> extends NumberAssert<SELF,ACTUAL>
Number
s.Modifier and Type | Method and Description |
---|---|
SELF |
isCloseTo(ACTUAL expected,
Offset<ACTUAL> 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. |
SELF |
isEqualTo(ACTUAL expected,
Offset<ACTUAL> offset)
Verifies that the actual number is close to the given one within the given offset value.
|
SELF |
isNaN()
Verifies that the actual value is equal to
NaN . |
SELF |
isNotCloseTo(ACTUAL expected,
Offset<ACTUAL> offset)
Verifies that the actual number is not close to the given one by less than the given offset.
If the difference is equal to the offset value, the assertion fails. |
SELF |
isNotNaN()
Verifies that the actual value is not equal to
NaN . |
isBetween, isCloseTo, isNegative, isNotCloseTo, isNotNegative, isNotPositive, isNotZero, isOne, isPositive, isStrictlyBetween, isZero
SELF isEqualTo(ACTUAL expected, Offset<ACTUAL> offset)
This assertion is the same as isCloseTo(Number, Offset)
.
When abs(actual - expected) == offset value, the assertion:
Assertions.within(Double)
or Assertions.offset(Double)
Assertions.byLessThan(Double)
or Offset.strictOffset(Number)
Examples:
// assertions will pass
assertThat(8.1).isEqualTo(8.0, within(0.2));
assertThat(8.1).isEqualTo(8.0, offset(0.2)); // alias of within
assertThat(8.1).isEqualTo(8.0, byLessThan(0.2)); // strict
// assertions succeed when the difference == offset value ...
assertThat(8.1).isEqualTo(8.0, within(0.1));
assertThat(8.1).isEqualTo(8.0, offset(0.1));
// ... except when using byLessThan which is strict
assertThat(8.1).isEqualTo(8.0, byLessThan(0.1)); // strict => fail
// this assertions also fails
assertThat(8.1).isEqualTo(8.0, within(0.001));
expected
- the given value to compare the actual value to.offset
- the given positive offset.this
assertion object.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.SELF isCloseTo(ACTUAL expected, Offset<ACTUAL> offset)
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));
isCloseTo
in interface NumberAssert<SELF extends FloatingPointNumberAssert<SELF,ACTUAL>,ACTUAL extends Number>
expected
- the given number to compare the actual value to.offset
- the given positive offset.this
assertion object.NullPointerException
- if the given offset is null
.NullPointerException
- if the expected number is null
.AssertionError
- if the actual value is not close to the given one.SELF isNotCloseTo(ACTUAL expected, Offset<ACTUAL> offset)
Example with double:
// assertions will pass:
assertThat(8.3).isNotCloseTo(new Double(8.0), byLessThan(0.2));
// you can use offset if you prefer
assertThat(8.3).isNotCloseTo(new Double(8.0), offset(0.2));
// assertions will fail
assertThat(8.1).isNotCloseTo(new Double(8.0), byLessThan(0.1));
assertThat(8.1).isNotCloseTo(new Double(8.0), byLessThan(0.2));
isNotCloseTo
in interface NumberAssert<SELF extends FloatingPointNumberAssert<SELF,ACTUAL>,ACTUAL extends Number>
expected
- the given number to compare the actual value to.offset
- the given positive offset.this
assertion object.NullPointerException
- if the given offset is null
.NullPointerException
- if the expected number is null
.AssertionError
- if the actual value is equal to the given one.Assertions.byLessThan(Double)
SELF isNaN()
NaN
.
Example:
// assertions will pass
assertThat(Double.NaN).isNaN();
assertThat(0.0 / 0.0).isNaN();
assertThat(0.0F * Float.POSITIVE_INFINITY).isNaN();
// assertions will fail
assertThat(1.0).isNaN();
assertThat(-1.0F).isNaN();
AssertionError
- if the actual value is not equal to NaN
.SELF isNotNaN()
NaN
.
Example:
// assertions will pass
assertThat(1.0).isNotNaN();
assertThat(-1.0F).isNotNaN();
// assertions will fail
assertThat(Double.NaN).isNotNaN();
assertThat(0.0 / 0.0).isNotNaN();
assertThat(0.0F * Float.POSITIVE_INFINITY).isNotNaN();
AssertionError
- if the actual value is equal to NaN
.Copyright © 2014–2018 AssertJ. All rights reserved.