mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-26 07:16:03 +03:00
Minor rework of Complex Assertions for unit tests
git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@88321 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
parent
c98eaf18f7
commit
c9787e1224
@ -15,15 +15,17 @@ class Complex {
|
||||
// Fix silly human errors
|
||||
if (strpos($complexNumber,'+-') !== FALSE)
|
||||
$complexNumber = str_replace('+-','-',$complexNumber);
|
||||
if (strpos($complexNumber,'++') !== FALSE)
|
||||
$complexNumber = str_replace('++','+',$complexNumber);
|
||||
if (strpos($complexNumber,'--') !== FALSE)
|
||||
$complexNumber = str_replace('--','-',$complexNumber);
|
||||
|
||||
// Basic validation of string, to parse out real and imaginary parts, and any suffix
|
||||
$validComplex = preg_match('/^([-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?)([-+]?(\d+\.?\d*|\d*\.?\d+)([Ee][-+]?[0-2]?\d{1,2})?)?(([-+]?)([ij]?))$/ui',$complexNumber,$complexParts);
|
||||
$validComplex = preg_match('/^([\-\+]?(\d+\.?\d*|\d*\.?\d+)([Ee][\-\+]?[0-2]?\d{1,3})?)([\-\+]?(\d+\.?\d*|\d*\.?\d+)([Ee][\-\+]?[0-2]?\d{1,3})?)?(([\-\+]?)([ij]?))$/ui',$complexNumber,$complexParts);
|
||||
|
||||
if (!$validComplex) {
|
||||
// Neither real nor imaginary part, so test to see if we actually have a suffix
|
||||
$validComplex = preg_match('/^([-+]?)([ij])$/ui',$complexNumber,$complexParts);
|
||||
$validComplex = preg_match('/^([\-\+]?)([ij])$/ui',$complexNumber,$complexParts);
|
||||
if (!$validComplex) {
|
||||
throw new Exception('COMPLEX: Invalid complex number');
|
||||
}
|
||||
|
@ -9,6 +9,16 @@ class complexAssert {
|
||||
|
||||
public function assertComplexEquals($expected, $actual, $delta = 0)
|
||||
{
|
||||
if ($expected{0} === '#') {
|
||||
// Expecting an error, so we do a straight string comparison
|
||||
if ($expected === $actual) {
|
||||
return TRUE;
|
||||
}
|
||||
$this->_errorMessage = 'Expected Error: ' .
|
||||
$actual . ' !== ' . $expected;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$expectedComplex = new Complex($expected);
|
||||
$actualComplex = new Complex($actual);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user