Failed asserting that “double:0.999″ matches expected value “double:0.999″.
If you execute the following piece of code in a test using phpUnit….
$dRes = 400-399.001;
$this->assertEquals( 0.999, $dRes);
you will get…
“Failed asserting that <double:0.999> matches expected value <double:0.999>.”
That’s PHP…
The correct way would be “$this->assertEquals(0.999, round($dRes, 3));” as float handling in PHP is a bit strange. But I really love this Message - I start to think about what is reality and what not…
August 15, 2007 | Filed Under PHP related, _trunk
Comments
5 Responses to “Failed asserting that “double:0.999″ matches expected value “double:0.999″.”
Leave a Reply
http://bugs.php.net/bug.php?id=2835
this bug has same specific behavior and rasmus replied correct to this type of “php magic”.
Well you are right but this is not the point.
If we start to think about that 1 !== 1 … something weird is going on ….
Have a look at the signature of assertEquals():
void assertEquals(float $expected, float $actual, ”, float $delta = 0)
Just pass the $delta that defines the tolerance interval (equality within +/- $delta) of your choice and you’re done.
Hoi Sebastian,
you are right as always
But what delta should we have here ?
I know it is not a phpUnit problem - simply strange.
Ever did a php -r “var_dump(serialize(3.13));”?