#401 : PHPUnit Fixes (Calculation > Engineering)

This commit is contained in:
Progi1984 2016-05-19 12:31:40 +02:00
parent 14c9fac305
commit 248bdbf841
9 changed files with 51 additions and 13 deletions

View File

@ -772,10 +772,11 @@ class Engineering
$realNumber = substr($workString, 0, strlen($realNumber) + strlen($power) + $leadingSign);
if ($suffix != '') {
//if ($suffix != '') {
$imaginary = substr($workString, strlen($realNumber));
if (($imaginary == '') && (($realNumber == '') || ($realNumber == '+') || ($realNumber == '-'))) {
if ($imaginary == false) {
$imaginary = '';
} elseif (($imaginary == '') && (($realNumber == '') || ($realNumber == '+') || ($realNumber == '-'))) {
$imaginary = $realNumber . '1';
$realNumber = '0';
} elseif ($imaginary == '') {
@ -784,7 +785,7 @@ class Engineering
} elseif (($imaginary == '+') || ($imaginary == '-')) {
$imaginary .= '1';
}
}
//}
return array(
'real' => $realNumber,
@ -1876,12 +1877,10 @@ class Engineering
public static function IMARGUMENT($complexNumber)
{
$complexNumber = Functions::flattenSingleValue($complexNumber);
$parsedComplex = self::parseComplex($complexNumber);
if ($parsedComplex['real'] == 0.0) {
if ($parsedComplex['imaginary'] == 0.0) {
return 0.0;
return Functions::DIV0();
} elseif ($parsedComplex['imaginary'] < 0.0) {
return M_PI / -2;
} else {
@ -2193,9 +2192,12 @@ class Engineering
$parsedComplexDividend = self::parseComplex($complexDividend);
$parsedComplexDivisor = self::parseComplex($complexDivisor);
if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] != '') &&
($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])
) {
if (($parsedComplexDividend['suffix'] != '' && $parsedComplexDivisor['suffix'] != '') && ($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) {
return Functions::NAN();
}
if ((($parsedComplexDividend['suffix'] != '' && $parsedComplexDivisor['imaginary'] != '')
|| ($parsedComplexDivisor['suffix'] != '' && $parsedComplexDividend['imaginary'] != ''))
&& ($parsedComplexDividend['suffix'] != $parsedComplexDivisor['suffix'])) {
return Functions::NAN();
}
if (($parsedComplexDividend['suffix'] != '') && ($parsedComplexDivisor['suffix'] == '')) {
@ -2243,7 +2245,13 @@ class Engineering
($parsedComplex1['suffix'] != $parsedComplex2['suffix'])
) {
return Functions::NAN();
} elseif (($parsedComplex1['suffix'] == '') && ($parsedComplex2['suffix'] != '')) {
}
if ((($parsedComplex1['suffix'] != '' && $parsedComplex2['imaginary'] != '')
|| ($parsedComplex2['suffix'] != '' && $parsedComplex1['imaginary'] != ''))
&& ($parsedComplex1['suffix'] != $parsedComplex2['suffix'])) {
return Functions::NAN();
}
if (($parsedComplex1['suffix'] == '') && ($parsedComplex2['suffix'] != '')) {
$parsedComplex1['suffix'] = $parsedComplex2['suffix'];
}
@ -2279,7 +2287,7 @@ class Engineering
if ($activeSuffix == '') {
$activeSuffix = $parsedComplex['suffix'];
} elseif (($parsedComplex['suffix'] != '') && ($activeSuffix != $parsedComplex['suffix'])) {
return Functions::VALUE();
return Functions::NAN();
}
$returnValue['real'] += $parsedComplex['real'];

View File

@ -141,6 +141,7 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerWEEKNUM
* @group fail19
*/
public function testWEEKNUM()
{
@ -157,6 +158,7 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerWEEKDAY
* @group fail19
*/
public function testWEEKDAY()
{
@ -417,6 +419,7 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerDATEDIF
* @group fail19
*/
public function testDATEDIF()
{
@ -449,6 +452,7 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerYEARFRAC
* @group fail19
*/
public function testYEARFRAC()
{

View File

@ -30,6 +30,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerBESSELI
* @group fail19
*/
public function testBESSELI()
{
@ -46,6 +47,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerBESSELJ
* @group fail19
*/
public function testBESSELJ()
{
@ -62,6 +64,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerBESSELK
* @group fail19
*/
public function testBESSELK()
{
@ -78,6 +81,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerBESSELY
* @group fail19
*/
public function testBESSELY()
{
@ -158,6 +162,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerIMARGUMENT
* @group fail19
*/
public function testIMARGUMENT()
{
@ -206,6 +211,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerIMDIV
* @group fail19
*/
public function testIMDIV()
{
@ -222,6 +228,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerIMEXP
* @group fail19
*/
public function testIMEXP()
{
@ -286,6 +293,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerIMPOWER
* @group fail19
*/
public function testIMPOWER()
{
@ -350,6 +358,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerIMSUB
* @group fail19
*/
public function testIMSUB()
{
@ -366,6 +375,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerIMSUM
* @group fail19
*/
public function testIMSUM()
{
@ -462,6 +472,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerDEC2BIN
* @group fail19
*/
public function testDEC2BIN()
{
@ -510,6 +521,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerHEX2BIN
* @group fail19
*/
public function testHEX2BIN()
{
@ -526,6 +538,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerHEX2DEC
* @group fail19
*/
public function testHEX2DEC()
{
@ -542,6 +555,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerHEX2OCT
* @group fail19
*/
public function testHEX2OCT()
{
@ -558,6 +572,7 @@ class EngineeringTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerOCT2BIN
* @group fail19
*/
public function testOCT2BIN()
{

View File

@ -14,6 +14,7 @@ class FinancialTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerACCRINT
* @group fail19
*/
public function testACCRINT()
{
@ -462,6 +463,7 @@ class FinancialTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerPRICE
* @group fail19
*/
public function testPRICE()
{
@ -478,6 +480,7 @@ class FinancialTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerRATE
* @group fail19
*/
public function testRATE()
{
@ -494,6 +497,7 @@ class FinancialTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerXIRR
* @group fail19
*/
public function testXIRR()
{

View File

@ -14,6 +14,7 @@ class LookupRefTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerHLOOKUP
* @group fail19
*/
public function testHLOOKUP()
{
@ -30,6 +31,7 @@ class LookupRefTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerVLOOKUP
* @group fail19
*/
public function testVLOOKUP()
{

View File

@ -254,6 +254,7 @@ class MathTrigTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerMDETERM
* @group fail19
*/
public function testMDETERM()
{
@ -270,6 +271,7 @@ class MathTrigTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerMINVERSE
* @group fail19
*/
public function testMINVERSE()
{
@ -286,6 +288,7 @@ class MathTrigTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerMMULT
* @group fail19
*/
public function testMMULT()
{

View File

@ -155,6 +155,7 @@ class DateTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider providerDateTimeExcelToPHP1900Timezone
* @group fail19
*/
public function testDateTimeExcelToPHP1900Timezone()
{

View File

@ -8,6 +8,7 @@ class PasswordHasherTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerHashPassword
* @group fail19
*/
public function testHashPassword()
{

View File

@ -33,7 +33,7 @@ class Complex
// Neither real nor imaginary part, so test to see if we actually have a suffix
$validComplex = preg_match('/^([\-\+]?)([ij])$/ui', $complexNumber, $complexParts);
if (!$validComplex) {
throw new Exception('COMPLEX: Invalid complex number');
throw new \PHPExcel\Exception('COMPLEX: Invalid complex number');
}
// We have a suffix, so set the real to 0, the imaginary to either 1 or -1 (as defined by the sign)
$imaginary = 1;