 1b96c95a44
			
		
	
	
		1b96c95a44
		
			
		
	
	
	
	
		
			
			* - Refactored Complex Engineering Functions to use external complex number library
- Added calculation engine support for the new complex number functions that were added in MS Excel 2013
    - IMCOSH()  Returns the hyperbolic cosine of a complex number
    - IMCOT()   Returns the cotangent of a complex number
    - IMCSC()   Returns the cosecant of a complex number
    - IMCSCH()  Returns the hyperbolic cosecant of a complex number
    - IMSEC()   Returns the secant of a complex number
    - IMSECH()  Returns the hyperbolic secant of a complex number
    - IMSINH()  Returns the hyperbolic sine of a complex number
    - IMTAN()   Returns the tangent of a complex number
* Simplified the parseComplex() method in the PhpOffice\PhpSpreadsheet\Calculation\Engineering class, using Complex\Complex; and docblock flagged as deprecated
		
	
			
		
			
				
	
	
		
			83 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			83 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace PhpOffice\PhpSpreadsheetTests\Custom;
 | |
| 
 | |
| use Complex\Complex;
 | |
| 
 | |
| class ComplexAssert
 | |
| {
 | |
|     private $errorMessage = '';
 | |
| 
 | |
|     private function testExpectedExceptions($expected, $actual)
 | |
|     {
 | |
|         //    Expecting an error, so we do a straight string comparison
 | |
|         if ($expected === $actual) {
 | |
|             return true;
 | |
|         } elseif ($expected === INF && $actual === 'INF') {
 | |
|             return true;
 | |
|         }
 | |
|         $this->errorMessage = 'Expected Error: ' . $actual . ' !== ' . $expected;
 | |
| 
 | |
|         return false;
 | |
|     }
 | |
| 
 | |
|     private function adjustDelta($expected, $actual, $delta)
 | |
|     {
 | |
|         $adjustedDelta = $delta;
 | |
| 
 | |
|         if (abs($actual) > 10 && abs($expected) > 10) {
 | |
|             $variance = floor(log10(abs($expected)));
 | |
|             $adjustedDelta *= pow(10, $variance);
 | |
|         }
 | |
| 
 | |
|         return $adjustedDelta > 1.0 ? 1.0 : $adjustedDelta;
 | |
|     }
 | |
| 
 | |
|     public function assertComplexEquals($expected, $actual, $delta = 0)
 | |
|     {
 | |
|         if ($expected === INF || $expected[0] === '#') {
 | |
|             return $this->testExpectedExceptions($expected, $actual);
 | |
|         }
 | |
| 
 | |
|         $expectedComplex = new Complex($expected);
 | |
|         $actualComplex = new Complex($actual);
 | |
| 
 | |
|         if (!is_numeric($actualComplex->getReal()) || !is_numeric($expectedComplex->getReal())) {
 | |
|             if ($actualComplex->getReal() !== $expectedComplex->getReal()) {
 | |
|                 $this->errorMessage = 'Mismatched String: ' . $actualComplex->getReal() . ' !== ' . $expectedComplex->getReal();
 | |
| 
 | |
|                 return false;
 | |
|             }
 | |
| 
 | |
|             return true;
 | |
|         }
 | |
| 
 | |
|         $adjustedDelta = $this->adjustDelta($expectedComplex->getReal(), $actualComplex->getReal(), $delta);
 | |
|         if (abs($actualComplex->getReal() - $expectedComplex->getReal()) > $adjustedDelta) {
 | |
|             $this->errorMessage = 'Mismatched Real part: ' . $actualComplex->getReal() . ' != ' . $expectedComplex->getReal();
 | |
| 
 | |
|             return false;
 | |
|         }
 | |
| 
 | |
|         $adjustedDelta = $this->adjustDelta($expectedComplex->getImaginary(), $actualComplex->getImaginary(), $delta);
 | |
|         if (abs($actualComplex->getImaginary() - $expectedComplex->getImaginary()) > $adjustedDelta) {
 | |
|             $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;
 | |
|     }
 | |
| }
 |