I'm using assertSame() in PHPUnit to compare a database result with expected values. The results are floating point numbers.
PHPUnit returns this message (but I can't spot any differences):
Failed asserting that Array (
'1_1' => 11.111111111111
'1_2' => 33.333333333333
'1_3' => 55.555555555556
'1_4' => 0.0
'1_5' => null
'1_total' => 100.0
) is identical to Array (
'1_1' => 11.111111111111
'1_2' => 33.333333333333
'1_3' => 55.555555555556
'1_4' => 0.0
'1_5' => null
'1_total' => 100.0
)
Why is this failing and what is the correct way to compare an arrays of floating point values?
assertEquals has a $floating_delta argument for this type of cases:
$this->assertEquals($expected_array, $actual_array, '', 0.00001);
PHPUnit docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With