diff --git a/docs/references/function-list-by-category.md b/docs/references/function-list-by-category.md index 418311bc..effe9e97 100644 --- a/docs/references/function-list-by-category.md +++ b/docs/references/function-list-by-category.md @@ -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 diff --git a/docs/references/function-list-by-name.md b/docs/references/function-list-by-name.md index 7f22ef24..e974c316 100644 --- a/docs/references/function-list-by-name.md +++ b/docs/references/function-list-by-name.md @@ -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 diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index 325d132b..63cd69cc 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -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'], diff --git a/src/PhpSpreadsheet/Calculation/Logical.php b/src/PhpSpreadsheet/Calculation/Logical.php index 3e6c5e74..c95417c8 100644 --- a/src/PhpSpreadsheet/Calculation/Logical.php +++ b/src/PhpSpreadsheet/Calculation/Logical.php @@ -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); + } } diff --git a/src/PhpSpreadsheet/Calculation/Statistical.php b/src/PhpSpreadsheet/Calculation/Statistical.php index 850ae25e..1f9c7665 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical.php +++ b/src/PhpSpreadsheet/Calculation/Statistical.php @@ -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(); } /** diff --git a/tests/PhpSpreadsheetTests/Calculation/EngineeringTest.php b/tests/PhpSpreadsheetTests/Calculation/EngineeringTest.php deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/AndTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/AndTest.php new file mode 100644 index 00000000..69ae43af --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/AndTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result); + } + + public function providerAND() + { + return require 'data/Calculation/Logical/AND.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/FalseTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/FalseTest.php new file mode 100644 index 00000000..cbd2a8f4 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/FalseTest.php @@ -0,0 +1,21 @@ +assertFalse($result); + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfErrorTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfErrorTest.php new file mode 100644 index 00000000..678dcc6e --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfErrorTest.php @@ -0,0 +1,33 @@ +assertEquals($expectedResult, $result); + } + + public function providerIFERROR() + { + return require 'data/Calculation/Logical/IFERROR.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfNaTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfNaTest.php new file mode 100644 index 00000000..16f0314f --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfNaTest.php @@ -0,0 +1,33 @@ +assertEquals($expectedResult, $result); + } + + public function providerIFNA() + { + return require 'data/Calculation/Logical/IFNA.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfTest.php new file mode 100644 index 00000000..d3a7623f --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result); + } + + public function providerIF() + { + return require 'data/Calculation/Logical/IF.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/NotTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/NotTest.php new file mode 100644 index 00000000..1aab0cd1 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/NotTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result); + } + + public function providerNOT() + { + return require 'data/Calculation/Logical/NOT.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/OrTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/OrTest.php new file mode 100644 index 00000000..a47b83bc --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/OrTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result); + } + + public function providerOR() + { + return require 'data/Calculation/Logical/OR.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/SwitchTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/SwitchTest.php new file mode 100644 index 00000000..aa3b7525 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/SwitchTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result); + } + + public function providerSwitch() + { + return require 'data/Calculation/Logical/SWITCH.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/TrueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/TrueTest.php new file mode 100644 index 00000000..075820a9 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/TrueTest.php @@ -0,0 +1,21 @@ +assertTrue($result); + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/XorTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/XorTest.php new file mode 100644 index 00000000..8a41f0d0 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/XorTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result); + } + + public function providerXOR() + { + return require 'data/Calculation/Logical/XOR.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ExponDistTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ExponDistTest.php new file mode 100644 index 00000000..9d61356f --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ExponDistTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result, '', 1E-12); + } + + public function providerEXPONDIST() + { + return require 'data/Calculation/Statistical/EXPONDIST.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FisherInvTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FisherInvTest.php new file mode 100644 index 00000000..a6c2f695 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FisherInvTest.php @@ -0,0 +1,32 @@ +assertEquals($expectedResult, $result, '', 1E-12); + } + + public function providerFISHERINV() + { + return require 'data/Calculation/Statistical/FISHERINV.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FisherTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FisherTest.php new file mode 100644 index 00000000..ec5d928c --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FisherTest.php @@ -0,0 +1,32 @@ +assertEquals($expectedResult, $result, '', 1E-12); + } + + public function providerFISHER() + { + return require 'data/Calculation/Statistical/FISHER.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaDistTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaDistTest.php new file mode 100644 index 00000000..51235f90 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaDistTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result, '', 1E-12); + } + + public function providerGAMMADIST() + { + return require 'data/Calculation/Statistical/GAMMADIST.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaInvTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaInvTest.php new file mode 100644 index 00000000..2cb243fc --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaInvTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result, '', 1E-12); + } + + public function providerGAMMAINV() + { + return require 'data/Calculation/Statistical/GAMMAINV.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaLnTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaLnTest.php new file mode 100644 index 00000000..02b11af3 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaLnTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result, '', 1E-12); + } + + public function providerGAMMALN() + { + return require 'data/Calculation/Statistical/GAMMALN.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GeoMeanTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GeoMeanTest.php new file mode 100644 index 00000000..b927bdac --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GeoMeanTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result, '', 1E-12); + } + + public function providerGEOMEAN() + { + return require 'data/Calculation/Statistical/GEOMEAN.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HarMeanTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HarMeanTest.php new file mode 100644 index 00000000..5b57ee38 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HarMeanTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result, '', 1E-12); + } + + public function providerHARMEAN() + { + return require 'data/Calculation/Statistical/HARMEAN.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MedianTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MedianTest.php new file mode 100644 index 00000000..bc6139ce --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MedianTest.php @@ -0,0 +1,31 @@ +assertEquals($expectedResult, $result, '', 1E-12); + } + + public function providerMEDIAN() + { + return require 'data/Calculation/Statistical/MEDIAN.php'; + } +} diff --git a/tests/PhpSpreadsheetTests/Calculation/LogicalTest.php b/tests/PhpSpreadsheetTests/Calculation/LogicalTest.php deleted file mode 100644 index 37f9434e..00000000 --- a/tests/PhpSpreadsheetTests/Calculation/LogicalTest.php +++ /dev/null @@ -1,139 +0,0 @@ -