diff --git a/unitTests/custom/Complex.php b/unitTests/custom/Complex.php index f5a67c01..c827baeb 100644 --- a/unitTests/custom/Complex.php +++ b/unitTests/custom/Complex.php @@ -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'); } diff --git a/unitTests/custom/complexAssert.php b/unitTests/custom/complexAssert.php index 680aa2ea..486e0929 100644 --- a/unitTests/custom/complexAssert.php +++ b/unitTests/custom/complexAssert.php @@ -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);