/** * Sets the tolerance for floating number comparison. If set to null, requires exact match of the values. * For example, if set to 0.01, ignores all differences lower than 0.01, so 1 and 0.9999 are considered equal. * * @param tolerance */ public ConfigurableJsonFluentAssert withTolerance(double tolerance) { return withTolerance(BigDecimal.valueOf(tolerance)); }
/** * Sets the tolerance for floating number comparison. If set to null, requires exact match of the values. * For example, if set to 0.01, ignores all differences lower than 0.01, so 1 and 0.9999 are considered equal. * * @param tolerance */ public ConfigurableJsonFluentAssert withTolerance(double tolerance) { return withTolerance(BigDecimal.valueOf(tolerance)); }
@Test void testAssertToleranceFailure() { assertThatThrownBy(() -> assertThatJson("{\"test\":1.1}").node("test").withTolerance(0.001).isEqualTo(1)) .hasMessage("JSON documents are different:\nDifferent value found in node \"test\", expected: <1> but was: <1.1>, difference is 0.1, tolerance is 0.001\n"); }
.withTolerance(0.000000001) .isEqualTo( '{' +
@Test void testAssertTolerance() { assertThatJson("{\"test\":1.00001}").node("test").withTolerance(0.001).isEqualTo(1); }
@Test void testAssertToleranceDirect() { assertThatJson("{\"test\":1.00001}").withTolerance(0.001).isEqualTo("{\"test\":1}"); }
@Test void testAssertToleranceDifferentOrder() { assertThatJson("{\"test\":1.00001}").withTolerance(0.001).node("test").isEqualTo(1); }