No Description

complexAssert.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. include_once dirname(__FILE__).'/Complex.php';
  3. class complexAssert {
  4. private $_errorMessage = '';
  5. public function assertComplexEquals($expected, $actual, $delta = 0)
  6. {
  7. if ($expected{0} === '#') {
  8. // Expecting an error, so we do a straight string comparison
  9. if ($expected === $actual) {
  10. return TRUE;
  11. }
  12. $this->_errorMessage = 'Expected Error: ' .
  13. $actual . ' !== ' . $expected;
  14. return FALSE;
  15. }
  16. $expectedComplex = new Complex($expected);
  17. $actualComplex = new Complex($actual);
  18. if (!is_numeric($actualComplex->getReal()) || !is_numeric($expectedComplex->getReal())) {
  19. if ($actualComplex->getReal() !== $expectedComplex->getReal()) {
  20. $this->_errorMessage = 'Mismatched String: ' .
  21. $actualComplex->getReal() . ' !== ' . $expectedComplex->getReal();
  22. return FALSE;
  23. }
  24. return TRUE;
  25. }
  26. if ($actualComplex->getReal() < ($expectedComplex->getReal() - $delta) ||
  27. $actualComplex->getReal() > ($expectedComplex->getReal() + $delta)) {
  28. $this->_errorMessage = 'Mismatched Real part: ' .
  29. $actualComplex->getReal() . ' != ' . $expectedComplex->getReal();
  30. return FALSE;
  31. }
  32. if ($actualComplex->getImaginary() < ($expectedComplex->getImaginary() - $delta) ||
  33. $actualComplex->getImaginary() > ($expectedComplex->getImaginary() + $delta)) {
  34. $this->_errorMessage = 'Mismatched Imaginary part: ' .
  35. $actualComplex->getImaginary() . ' != ' . $expectedComplex->getImaginary();
  36. return FALSE;
  37. }
  38. if ($actualComplex->getSuffix() !== $actualComplex->getSuffix()) {
  39. $this->_errorMessage = 'Mismatched Suffix: ' .
  40. $actualComplex->getSuffix() . ' != ' . $expectedComplex->getSuffix();
  41. return FALSE;
  42. }
  43. return TRUE;
  44. }
  45. public function getErrorMessage() {
  46. return $this->_errorMessage;
  47. }
  48. }