ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
complexAssert.php
Go to the documentation of this file.
1<?php
2
3include_once dirname(__FILE__).'/Complex.php';
4
5
7
8 private $_errorMessage = '';
9
10 public function assertComplexEquals($expected, $actual, $delta = 0)
11 {
12 if ($expected{0} === '#') {
13 // Expecting an error, so we do a straight string comparison
14 if ($expected === $actual) {
15 return TRUE;
16 }
17 $this->_errorMessage = 'Expected Error: ' .
18 $actual . ' !== ' . $expected;
19 return FALSE;
20 }
21
22 $expectedComplex = new Complex($expected);
23 $actualComplex = new Complex($actual);
24
25 if (!is_numeric($actualComplex->getReal()) || !is_numeric($expectedComplex->getReal())) {
26 if ($actualComplex->getReal() !== $expectedComplex->getReal()) {
27 $this->_errorMessage = 'Mismatched String: ' .
28 $actualComplex->getReal() . ' !== ' . $expectedComplex->getReal();
29 return FALSE;
30 }
31 return TRUE;
32 }
33
34 if ($actualComplex->getReal() < ($expectedComplex->getReal() - $delta) ||
35 $actualComplex->getReal() > ($expectedComplex->getReal() + $delta)) {
36 $this->_errorMessage = 'Mismatched Real part: ' .
37 $actualComplex->getReal() . ' != ' . $expectedComplex->getReal();
38 return FALSE;
39 }
40
41 if ($actualComplex->getImaginary() < ($expectedComplex->getImaginary() - $delta) ||
42 $actualComplex->getImaginary() > ($expectedComplex->getImaginary() + $delta)) {
43 $this->_errorMessage = 'Mismatched Imaginary part: ' .
44 $actualComplex->getImaginary() . ' != ' . $expectedComplex->getImaginary();
45 return FALSE;
46 }
47
48 if ($actualComplex->getSuffix() !== $actualComplex->getSuffix()) {
49 $this->_errorMessage = 'Mismatched Suffix: ' .
50 $actualComplex->getSuffix() . ' != ' . $expectedComplex->getSuffix();
51 return FALSE;
52 }
53
54 return TRUE;
55 }
56
57
58 public function getErrorMessage() {
60 }
61
62}
An exception for terminatinating execution or to throw for unit testing.
assertComplexEquals($expected, $actual, $delta=0)