diff --git a/unitTests/custom/Complex.php b/unitTests/custom/Complex.php new file mode 100644 index 00000000..72938aa3 --- /dev/null +++ b/unitTests/custom/Complex.php @@ -0,0 +1,70 @@ +realPart = $realPart; + $this->imaginaryPart = $imaginaryPart; + $this->suffix = strtolower($suffix); + } + + public function getReal() + { + return $this->realPart; + } + + public function getImaginary() + { + return $this->imaginaryPart; + } + + public function getSuffix() + { + return $this->suffix; + } + + public function __toString() { + $str = ""; + if ($this->imaginaryPart != 0.0) $str .= $this->imaginaryPart . $this->suffix; + if ($this->realPart != 0.0) { + if ($str) $str = "+" . $str; + $str = $this->realPart . $str; + } + if (!$str) $str = "0"; + return $str; + } + +} diff --git a/unitTests/custom/complexAssert.php b/unitTests/custom/complexAssert.php new file mode 100644 index 00000000..680aa2ea --- /dev/null +++ b/unitTests/custom/complexAssert.php @@ -0,0 +1,52 @@ +getReal()) || !is_numeric($expectedComplex->getReal())) { + if ($actualComplex->getReal() !== $expectedComplex->getReal()) { + $this->_errorMessage = 'Mismatched String: ' . + $actualComplex->getReal() . ' !== ' . $expectedComplex->getReal(); + return FALSE; + } + return TRUE; + } + + if ($actualComplex->getReal() < ($expectedComplex->getReal() - $delta) || + $actualComplex->getReal() > ($expectedComplex->getReal() + $delta)) { + $this->_errorMessage = 'Mismatched Real part: ' . + $actualComplex->getReal() . ' != ' . $expectedComplex->getReal(); + return FALSE; + } + + if ($actualComplex->getImaginary() < ($expectedComplex->getImaginary() - $delta) || + $actualComplex->getImaginary() > ($expectedComplex->getImaginary() + $delta)) { + $this->_errorMessage = 'Mismatched Imaginary part: ' . + $actualComplex->getImaginary() . ' != ' . $expectedComplex->getImaginary(); + return FALSE; + } + + if ($actualComplex->getSuffix() !== $actualComplex->getSuffix()) { + $this->_errorMessage = 'Mismatched Suffix: ' . + $actualComplex->getSuffix() . ' != ' . $expectedComplex->getSuffix(); + return FALSE; + } + + return TRUE; + } + + + public function getErrorMessage() { + return $this->_errorMessage; + } + +}