Verifies that the actual number is close to the given one within the given offset value.
When abs(actual - expected) == offset value, the assertion:
- succeeds when using
Assertions#within(Integer)
- fails when using
Assertions#byLessThan(Integer) or
Offset#strictOffset(Number)
Breaking change since 2.9.0/3.9.0: using
Assertions#byLessThan(Integer) implies a strict comparison,
use
Assertions#within(Integer) to get the old behavior.
Examples:
// assertions will pass:
assertThat(5).isCloseTo(7, within(3));
assertThat(5).isCloseTo(7, byLessThan(3));
// if difference is exactly equals to the offset, it's ok ...
assertThat(5).isCloseTo(7, within(2));
// ... but not with byLessThan which implies a strict comparison
assertThat(5).isCloseTo(7, byLessThan(2)); // FAIL
// assertions will fail
assertThat(5).isCloseTo(7, within(1));
assertThat(5).isCloseTo(7, byLessThan(1));
assertThat(5).isCloseTo(7, byLessThan(2));