/** * Asserts that the subject is finite, i.e. not {@link Double#POSITIVE_INFINITY}, {@link * Double#NEGATIVE_INFINITY}, or {@link Double#NaN}. */ public final void isFinite() { if (actual() == null || actual().isNaN() || actual().isInfinite()) { failWithActual(simpleFact("expected to be finite")); } }
/** * Asserts that the subject is a non-null value other than zero (i.e. it is not {@code 0.0}, * {@code -0.0} or {@code null}). */ public final void isNonZero() { if (actual() == null) { failWithActual(simpleFact("expected a double other than zero")); } else if (actual().doubleValue() == 0.0) { failWithActual(simpleFact("expected not to be zero")); } }
/** * Asserts that the subject is a non-null value other than {@link Double#NaN} (but it may be * {@link Double#POSITIVE_INFINITY} or {@link Double#NEGATIVE_INFINITY}). */ public final void isNotNaN() { if (actual() == null) { failWithActual(simpleFact("expected a double other than NaN")); } else { isNotEqualTo(NaN); } } }
@Override public void of(double expected) { Double actual = actual(); checkNotNull( actual, "actual value cannot be null. tolerance=%s expected=%s", tolerance, expected); checkTolerance(tolerance); if (!equalWithinTolerance(actual, expected, tolerance)) { failWithoutActual( fact("expected", doubleToString(expected)), butWas(), fact("outside tolerance", doubleToString(tolerance))); } } };
@Override public void of(double expected) { Double actual = actual(); checkNotNull( actual, "actual value cannot be null. tolerance=%s expected=%s", tolerance, expected); checkTolerance(tolerance); if (!notEqualWithinTolerance(actual, expected, tolerance)) { failWithoutActual( fact("expected not to be", doubleToString(expected)), butWas(), fact("within tolerance", doubleToString(tolerance))); } } };