Merge remote-tracking branch 'origin/master'

This commit is contained in:
MarkBaker 2019-07-26 22:22:20 +02:00
commit dbb83ab184
36 changed files with 726 additions and 146 deletions

View File

@ -210,6 +210,7 @@ AND | \PhpOffice\PhpSpreadsheet\Calculation\Logical::logicalAnd
FALSE | \PhpOffice\PhpSpreadsheet\Calculation\Logical::FALSE
IF | \PhpOffice\PhpSpreadsheet\Calculation\Logical::STATEMENT_IF
IFERROR | \PhpOffice\PhpSpreadsheet\Calculation\Logical::IFERROR
IFNA | \PhpOffice\PhpSpreadsheet\Calculation\Logical::IFNA
NOT | \PhpOffice\PhpSpreadsheet\Calculation\Logical::NOT
OR | \PhpOffice\PhpSpreadsheet\Calculation\Logical::logicalOr
TRUE | \PhpOffice\PhpSpreadsheet\Calculation\Logical::TRUE

View File

@ -207,6 +207,7 @@ Excel Function | Category | PhpSpreadsheet Function
--------------------|--------------------------------|-------------------------------------------
IF | CATEGORY_LOGICAL | \PhpOffice\PhpSpreadsheet\Calculation\Logical::STATEMENT_IF
IFERROR | CATEGORY_LOGICAL | \PhpOffice\PhpSpreadsheet\Calculation\Logical::IFERROR
IFNA | CATEGORY_LOGICAL | \PhpOffice\PhpSpreadsheet\Calculation\Logical::IFNA
IFS | CATEGORY_LOGICAL | **Not yet Implemented**
IMABS | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::IMABS
IMAGINARY | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::IMAGINARY

View File

@ -1018,6 +1018,11 @@ class Calculation
'functionCall' => [Logical::class, 'IFERROR'],
'argumentCount' => '2',
],
'IFNA' => [
'category' => Category::CATEGORY_LOGICAL,
'functionCall' => [Logical::class, 'IFNA'],
'argumentCount' => '2',
],
'IMABS' => [
'category' => Category::CATEGORY_ENGINEERING,
'functionCall' => [Engineering::class, 'IMABS'],

View File

@ -347,4 +347,25 @@ class Logical
return self::statementIf(Functions::isError($testValue), $errorpart, $testValue);
}
/**
* IFNA.
*
* Excel Function:
* =IFNA(testValue,napart)
*
* @category Logical Functions
*
* @param mixed $testValue Value to check, is also the value returned when not an NA
* @param mixed $napart Value to return when testValue is an NA condition
*
* @return mixed The value of errorpart or testValue determined by error condition
*/
public static function IFNA($testValue = '', $napart = '')
{
$testValue = ($testValue === null) ? '' : Functions::flattenSingleValue($testValue);
$napart = ($napart === null) ? '' : Functions::flattenSingleValue($napart);
return self::statementIf(Functions::isNa($testValue), $napart, $testValue);
}
}

View File

@ -1778,7 +1778,7 @@ class Statistical
public static function HARMEAN(...$args)
{
// Return value
$returnValue = Functions::NA();
$returnValue = 0;
// Loop through arguments
$aArgs = Functions::flattenArray($args);
@ -1792,11 +1792,7 @@ class Statistical
if ($arg <= 0) {
return Functions::NAN();
}
if ($returnValue === null) {
$returnValue = (1 / $arg);
} else {
$returnValue += (1 / $arg);
}
$returnValue += (1 / $arg);
++$aCount;
}
}
@ -1806,7 +1802,7 @@ class Statistical
return 1 / ($returnValue / $aCount);
}
return $returnValue;
return Functions::NA();
}
/**

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class AndTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerAND
*
* @param mixed $expectedResult
*/
public function testAND($expectedResult, ...$args)
{
$result = Logical::logicalAnd(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerAND()
{
return require 'data/Calculation/Logical/AND.php';
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class FalseTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
public function testFALSE()
{
$result = Logical::FALSE();
$this->assertFalse($result);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class IfErrorTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerIFERROR
*
* @param mixed $expectedResult
* @param $value
* @param $return
*/
public function testIFERROR($expectedResult, $value, $return)
{
$result = Logical::IFERROR($value, $return);
$this->assertEquals($expectedResult, $result);
}
public function providerIFERROR()
{
return require 'data/Calculation/Logical/IFERROR.php';
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class IfNaTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerIFNA
*
* @param mixed $expectedResult
* @param $value
* @param $return
*/
public function testIFNA($expectedResult, $value, $return)
{
$result = Logical::IFNA($value, $return);
$this->assertEquals($expectedResult, $result);
}
public function providerIFNA()
{
return require 'data/Calculation/Logical/IFNA.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class IfTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerIF
*
* @param mixed $expectedResult
*/
public function testIF($expectedResult, ...$args)
{
$result = Logical::statementIf(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerIF()
{
return require 'data/Calculation/Logical/IF.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class NotTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerNOT
*
* @param mixed $expectedResult
*/
public function testNOT($expectedResult, ...$args)
{
$result = Logical::NOT(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerNOT()
{
return require 'data/Calculation/Logical/NOT.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class OrTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerOR
*
* @param mixed $expectedResult
*/
public function testOR($expectedResult, ...$args)
{
$result = Logical::logicalOr(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerOR()
{
return require 'data/Calculation/Logical/OR.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class SwitchTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerSwitch
*
* @param mixed $expectedResult
*/
public function testSWITCH($expectedResult, ...$args)
{
$result = Logical::statementSwitch(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerSwitch()
{
return require 'data/Calculation/Logical/SWITCH.php';
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class TrueTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
public function testTRUE()
{
$result = Logical::TRUE();
$this->assertTrue($result);
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class XorTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerXOR
*
* @param mixed $expectedResult
*/
public function testXOR($expectedResult, ...$args)
{
$result = Logical::logicalXor(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerXOR()
{
return require 'data/Calculation/Logical/XOR.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class ExponDistTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerEXPONDIST
*
* @param mixed $expectedResult
*/
public function testEXPONDIST($expectedResult, ...$args)
{
$result = Statistical::EXPONDIST(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerEXPONDIST()
{
return require 'data/Calculation/Statistical/EXPONDIST.php';
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class FisherInvTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerFISHERINV
*
* @param mixed $expectedResult
* @param $value
*/
public function testFISHERINV($expectedResult, $value)
{
$result = Statistical::FISHERINV($value);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerFISHERINV()
{
return require 'data/Calculation/Statistical/FISHERINV.php';
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class FisherTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerFISHER
*
* @param mixed $expectedResult
* @param $value
*/
public function testFISHER($expectedResult, $value)
{
$result = Statistical::FISHER($value);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerFISHER()
{
return require 'data/Calculation/Statistical/FISHER.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class GammaDistTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerGAMMADIST
*
* @param mixed $expectedResult
*/
public function testGAMMADIST($expectedResult, ...$args)
{
$result = Statistical::GAMMADIST(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerGAMMADIST()
{
return require 'data/Calculation/Statistical/GAMMADIST.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class GammaInvTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerGAMMAINV
*
* @param mixed $expectedResult
*/
public function testGAMMAINV($expectedResult, ...$args)
{
$result = Statistical::GAMMAINV(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerGAMMAINV()
{
return require 'data/Calculation/Statistical/GAMMAINV.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class GammaLnTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerGAMMALN
*
* @param mixed $expectedResult
*/
public function testGAMMALN($expectedResult, ...$args)
{
$result = Statistical::GAMMALN(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerGAMMALN()
{
return require 'data/Calculation/Statistical/GAMMALN.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class GeoMeanTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerGEOMEAN
*
* @param mixed $expectedResult
*/
public function testGEOMEAN($expectedResult, ...$args)
{
$result = Statistical::GEOMEAN(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerGEOMEAN()
{
return require 'data/Calculation/Statistical/GEOMEAN.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class HarMeanTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerHARMEAN
*
* @param mixed $expectedResult
*/
public function testHARMEAN($expectedResult, ...$args)
{
$result = Statistical::HARMEAN(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerHARMEAN()
{
return require 'data/Calculation/Statistical/HARMEAN.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class MedianTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerMEDIAN
*
* @param mixed $expectedResult
*/
public function testMEDIAN($expectedResult, ...$args)
{
$result = Statistical::MEDIAN(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerMEDIAN()
{
return require 'data/Calculation/Statistical/MEDIAN.php';
}
}

View File

@ -1,139 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical;
use PHPUnit\Framework\TestCase;
class LogicalTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
public function testTRUE()
{
$result = Logical::TRUE();
self::assertTrue($result);
}
public function testFALSE()
{
$result = Logical::FALSE();
self::assertFalse($result);
}
/**
* @dataProvider providerAND
*
* @param mixed $expectedResult
*/
public function testAND($expectedResult, ...$args)
{
$result = Logical::logicalAnd(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerAND()
{
return require 'data/Calculation/Logical/AND.php';
}
/**
* @dataProvider providerOR
*
* @param mixed $expectedResult
*/
public function testOR($expectedResult, ...$args)
{
$result = Logical::logicalOr(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerOR()
{
return require 'data/Calculation/Logical/OR.php';
}
/**
* @dataProvider providerXOR
*
* @param mixed $expectedResult
*/
public function testXOR($expectedResult, ...$args)
{
$result = Logical::logicalXor(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerXOR()
{
return require 'data/Calculation/Logical/XOR.php';
}
/**
* @dataProvider providerNOT
*
* @param mixed $expectedResult
*/
public function testNOT($expectedResult, ...$args)
{
$result = Logical::NOT(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerNOT()
{
return require 'data/Calculation/Logical/NOT.php';
}
/**
* @dataProvider providerIF
*
* @param mixed $expectedResult
*/
public function testIF($expectedResult, ...$args)
{
$result = Logical::statementIf(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerIF()
{
return require 'data/Calculation/Logical/IF.php';
}
/**
* @dataProvider providerIFERROR
*
* @param mixed $expectedResult
*/
public function testIFERROR($expectedResult, ...$args)
{
$result = Logical::IFERROR(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerIFERROR()
{
return require 'data/Calculation/Logical/IFERROR.php';
}
/**
* @dataProvider providerSwitch
*
* @param mixed $expectedResult
*/
public function testSWITCH($expectedResult, ...$args)
{
$result = Logical::statementSwitch(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerSwitch()
{
return require 'data/Calculation/Logical/SWITCH.php';
}
}

View File

@ -0,0 +1,12 @@
<?php
return [
[
55,
55, 'not found',
],
[
'not found',
'#N/A', 'not found',
],
];

View File

@ -0,0 +1,12 @@
<?php
return [
[
0.606530659713,
0.5, 1, false,
],
[
0.393469340287,
0.5, 1, true,
],
];

View File

@ -0,0 +1,16 @@
<?php
return [
[
-1.472219489583,
-0.9,
],
[
-0.255412811883,
-0.25,
],
[
1.098612288668,
0.8,
]
];

View File

@ -0,0 +1,20 @@
<?php
return [
[
-0.197375320225,
-0.2,
],
[
0.0,
0.0,
],
[
0.761594155956,
1.0,
],
[
0.992631520201,
2.8,
],
];

View File

@ -0,0 +1,12 @@
<?php
return [
[
0.112020903828,
6, 3, 2, false,
],
[
0.576809918873,
6, 3, 2, true,
],
];

View File

@ -0,0 +1,8 @@
<?php
return [
[
5.348120627447,
0.5, 3, 2,
],
];

View File

@ -0,0 +1,8 @@
<?php
return [
[
2.453736570842,
4.5,
],
];

View File

@ -0,0 +1,8 @@
<?php
return [
[
1.6226711115996,
2.5, 3, 0.5, 1, 3,
],
];

View File

@ -0,0 +1,8 @@
<?php
return [
[
1.2295081967213,
2.5, 3, 0.5, 1, 3,
],
];

View File

@ -0,0 +1,16 @@
<?php
return [
[
8.0,
1, 4.5, 7, 8, 9, 13, 14,
],
[
8.5,
1, 4.5, 7, 8, 9, 13, 14, 12,
],
[
8.0,
1, 4.5, 7, 8, 9, 13, 14, '',
],
];