PhpSpreadsheet/tests/PhpSpreadsheetTests/Custom/ComplexAssert.php

62 lines
2.0 KiB
PHP
Raw Normal View History

2015-05-17 16:10:35 +00:00
<?php
namespace PhpOffice\PhpSpreadsheetTests\Custom;
2015-05-17 16:10:35 +00:00
class ComplexAssert
2015-05-17 16:10:35 +00:00
{
2017-10-08 05:37:11 +00:00
private $errorMessage = '';
2015-05-17 16:10:35 +00:00
public function assertComplexEquals($expected, $actual, $delta = 0)
{
2016-12-22 14:43:37 +00:00
if ($expected[0] === '#') {
2015-05-17 16:10:35 +00:00
// Expecting an error, so we do a straight string comparison
if ($expected === $actual) {
return true;
}
2017-10-08 05:37:11 +00:00
$this->errorMessage = 'Expected Error: ' . $actual . ' !== ' . $expected;
2015-05-17 16:10:35 +00:00
return false;
}
$expectedComplex = new Complex($expected);
$actualComplex = new Complex($actual);
if (!is_numeric($actualComplex->getReal()) || !is_numeric($expectedComplex->getReal())) {
if ($actualComplex->getReal() !== $expectedComplex->getReal()) {
2017-10-08 05:37:11 +00:00
$this->errorMessage = 'Mismatched String: ' . $actualComplex->getReal() . ' !== ' . $expectedComplex->getReal();
2015-05-17 16:10:35 +00:00
return false;
}
2015-05-17 16:10:35 +00:00
return true;
}
if ($actualComplex->getReal() < ($expectedComplex->getReal() - $delta) ||
$actualComplex->getReal() > ($expectedComplex->getReal() + $delta)) {
2017-10-08 05:37:11 +00:00
$this->errorMessage = 'Mismatched Real part: ' . $actualComplex->getReal() . ' != ' . $expectedComplex->getReal();
2015-05-17 16:10:35 +00:00
return false;
}
if ($actualComplex->getImaginary() < ($expectedComplex->getImaginary() - $delta) ||
$actualComplex->getImaginary() > ($expectedComplex->getImaginary() + $delta)) {
2017-10-08 05:37:11 +00:00
$this->errorMessage = 'Mismatched Imaginary part: ' . $actualComplex->getImaginary() . ' != ' . $expectedComplex->getImaginary();
2015-05-17 16:10:35 +00:00
return false;
}
if ($actualComplex->getSuffix() !== $actualComplex->getSuffix()) {
2017-10-08 05:37:11 +00:00
$this->errorMessage = 'Mismatched Suffix: ' . $actualComplex->getSuffix() . ' != ' . $expectedComplex->getSuffix();
2015-05-17 16:10:35 +00:00
return false;
}
return true;
}
public function getErrorMessage()
{
2017-10-08 05:37:11 +00:00
return $this->errorMessage;
2015-05-17 16:10:35 +00:00
}
}