double expected,
double actual) {
bool bothNaN = std::isnan(expected) && std::isnan(actual);
- bool bothInf = std::isinf(expected) && std::isinf(actual);
- if (expected != actual && !bothNaN && !bothInf) {
+ if (expected != actual && !bothNaN) {
errln((UnicodeString)"FAIL: " + message + "; got " +
actual +
"; expected " + expected);
double expected,
double actual,
double delta) {
+ if (std::isnan(delta) || std::isinf(delta)) {
+ errln((UnicodeString)("FAIL: ") + message + "; nonsensical delta " + delta +
+ " - delta may not be NaN or Inf");
+ return FALSE;
+ }
bool bothNaN = std::isnan(expected) && std::isnan(actual);
- bool bothInf = std::isinf(expected) && std::isinf(actual);
- if (abs(expected - actual) > delta && !bothNaN && !bothInf) {
+ double difference = abs(expected - actual);
+ if (expected != actual && (difference > delta || std::isnan(difference)) && !bothNaN) {
errln((UnicodeString)("FAIL: ") + message + "; got " + actual + "; expected " + expected +
"; acceptable delta " + delta);
return FALSE;
* Asserts that two doubles are equal to within a positive delta. Returns
* false if they are not.
*
- * If the expected value is infinity then the delta value is ignored. NaNs
- * are considered equal: assertEquals(msg, NaN, NaN, *) passes.
+ * NaNs are considered equal: assertEquals(msg, NaN, NaN, *) passes.
+ * Infs are considered equal: assertEquals(msg, inf, inf, *) passes.
*
* @param message - the identifying message for the AssertionError.
* @param expected - expected value.
* Asserts that two doubles are equal to within a positive delta. Returns
* false if they are not.
*
- * If the expected value is infinity then the delta value is ignored. NaNs
- * are considered equal: assertEquals(msg, NaN, NaN, *) passes.
+ * NaNs are considered equal: assertEquals(msg, NaN, NaN, *) passes.
+ * Infs are considered equal: assertEquals(msg, inf, inf, *) passes.
*
* @param message - the identifying message for the AssertionError.
* @param expected - expected value.