sebastianbergmann/phpunit — Issue #448: Double comparison default delta makes tests fail
Author: isfs
Created: 2011-12-24 00:59:06+00:00
State: open

Defaulting the delta for numerical comparisons to 0.0000000001 (Framework/Comparator/Double.php:65, 96-98) causes problems. Numbers may differ by amounts much smaller than this but the difference still be very significant, because the magnitudes of the numbers may be small. For instance, this test fails, but it really should pass.

assertNotEquals(1e-20,2e-20);
}
}

It is also, as far as I can tell, impossible to specify a delta of zero, because zero is defaulted to 0.0000000001. This makes it impossible to even override the default and make the test pass without modifying the PHPUnit source. I.e. this doesn't work:

assertNotEquals(1e-20,2e-20,"",0);
}
}

PHPUnit does not use the specified delta of zero, but uses 0.0000000001.

IMHO, it would be best not to default the delta at all, as that makes a pretty big assumption about the kinds of numbers the user is comparing, and it's unhelpful; it is better just to use zero and let the user provide an appropriate delta if they find their tests are failing. More importantly, though, if a non-zero default delta is used, overriding it by providing a delta of zero as a parameter must work.