/** * Asserts that the actual value is close to the an offset expressed as an percentage value. * * @param info contains information about the assertion. * @param actual the actual value. * @param other the expected value. * @param percentage the given positive percentage. */ public void assertIsCloseToPercentage(final AssertionInfo info, final NUMBER actual, final NUMBER other, final Percentage percentage) { assertNotNull(info, actual); checkPercentageIsNotNull(percentage); checkNumberIsNotNull(other); if (areEqual(actual, other)) return; double acceptableDiff = abs(percentage.value * other.doubleValue() / 100d); double actualDiff = absDiff(actual, other).doubleValue(); if (actualDiff > acceptableDiff || Double.isNaN(actualDiff) || Double.isInfinite(actualDiff)) throw failures.failure(info, shouldBeEqualWithinPercentage(actual, other, percentage, absDiff(actual, other))); }
/** * Asserts that the actual value is not close to the an offset expressed as an percentage value. * * @param info contains information about the assertion. * @param actual the actual value. * @param other the expected value. * @param percentage the given positive percentage. */ public void assertIsNotCloseToPercentage(final AssertionInfo info, final NUMBER actual, final NUMBER other, final Percentage percentage) { assertNotNull(info, actual); checkPercentageIsNotNull(percentage); checkNumberIsNotNull(other); double diff = abs(percentage.value * other.doubleValue() / 100d); boolean areEqual = areEqual(actual, other); if (!areEqual && Double.isInfinite(diff)) return; if (absDiff(actual, other).doubleValue() <= diff || areEqual) throw failures.failure(info, shouldNotBeEqualWithinPercentage(actual, other, percentage, absDiff(actual, other))); }
/** * Asserts that the actual value is close to the an offset expressed as an percentage value. * * @param info contains information about the assertion. * @param actual the actual value. * @param other the expected value. * @param percentage the given positive percentage. */ public void assertIsCloseToPercentage(final AssertionInfo info, final NUMBER actual, final NUMBER other, final Percentage percentage) { assertNotNull(info, actual); checkPercentageIsNotNull(percentage); checkNumberIsNotNull(other); if (areEqual(actual, other)) return; double acceptableDiff = abs(percentage.value * other.doubleValue() / 100d); double actualDiff = absDiff(actual, other).doubleValue(); if (actualDiff > acceptableDiff || Double.isNaN(actualDiff) || Double.isInfinite(actualDiff)) throw failures.failure(info, shouldBeEqualWithinPercentage(actual, other, percentage, absDiff(actual, other))); }
/** * Asserts that the actual value is not close to the an offset expressed as an percentage value. * * @param info contains information about the assertion. * @param actual the actual value. * @param other the expected value. * @param percentage the given positive percentage. */ public void assertIsNotCloseToPercentage(final AssertionInfo info, final NUMBER actual, final NUMBER other, final Percentage percentage) { assertNotNull(info, actual); checkPercentageIsNotNull(percentage); checkNumberIsNotNull(other); double diff = abs(percentage.value * other.doubleValue() / 100d); boolean areEqual = areEqual(actual, other); if (!areEqual && Double.isInfinite(diff)) return; if (absDiff(actual, other).doubleValue() <= diff || areEqual) throw failures.failure(info, shouldNotBeEqualWithinPercentage(actual, other, percentage, absDiff(actual, other))); }