From a9c8470b3b15a45e7f393dfcbf8e2f5c2fc68d97 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Sun, 26 Jul 2020 22:10:53 +0200 Subject: [PATCH] Identify HYPGEOM.DIST() as a separate Excel function, and additional unit tests (including unhappy path) (#1595) --- .../Calculation/Calculation.php | 5 +++ .../Calculation/Statistical.php | 13 ++++--- .../Functions/Statistical/HypGeomDistTest.php | 25 +++++++++++++ .../data/Calculation/Statistical/CHIDIST.php | 4 +++ .../Calculation/Statistical/GAMMADIST.php | 8 +++++ .../data/Calculation/Statistical/GAMMAINV.php | 4 +++ .../data/Calculation/Statistical/GAMMALN.php | 4 +++ .../data/Calculation/Statistical/GEOMEAN.php | 7 ++++ .../data/Calculation/Statistical/HARMEAN.php | 11 ++++++ .../Calculation/Statistical/HYPGEOMDIST.php | 36 +++++++++++++++++++ 10 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HypGeomDistTest.php create mode 100644 tests/data/Calculation/Statistical/HYPGEOMDIST.php diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index 8cb1c297..99260e3b 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -1250,6 +1250,11 @@ class Calculation 'functionCall' => [Statistical::class, 'HYPGEOMDIST'], 'argumentCount' => '4', ], + 'HYPGEOM.DIST' => [ + 'category' => Category::CATEGORY_STATISTICAL, + 'functionCall' => [Functions::class, 'DUMMY'], + 'argumentCount' => '5', + ], 'IF' => [ 'category' => Category::CATEGORY_LOGICAL, 'functionCall' => [Logical::class, 'statementIf'], diff --git a/src/PhpSpreadsheet/Calculation/Statistical.php b/src/PhpSpreadsheet/Calculation/Statistical.php index 524438ea..4b113726 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical.php +++ b/src/PhpSpreadsheet/Calculation/Statistical.php @@ -1901,12 +1901,17 @@ class Statistical */ public static function HYPGEOMDIST($sampleSuccesses, $sampleNumber, $populationSuccesses, $populationNumber) { - $sampleSuccesses = floor(Functions::flattenSingleValue($sampleSuccesses)); - $sampleNumber = floor(Functions::flattenSingleValue($sampleNumber)); - $populationSuccesses = floor(Functions::flattenSingleValue($populationSuccesses)); - $populationNumber = floor(Functions::flattenSingleValue($populationNumber)); + $sampleSuccesses = Functions::flattenSingleValue($sampleSuccesses); + $sampleNumber = Functions::flattenSingleValue($sampleNumber); + $populationSuccesses = Functions::flattenSingleValue($populationSuccesses); + $populationNumber = Functions::flattenSingleValue($populationNumber); if ((is_numeric($sampleSuccesses)) && (is_numeric($sampleNumber)) && (is_numeric($populationSuccesses)) && (is_numeric($populationNumber))) { + $sampleSuccesses = floor($sampleSuccesses); + $sampleNumber = floor($sampleNumber); + $populationSuccesses = floor($populationSuccesses); + $populationNumber = floor($populationNumber); + if (($sampleSuccesses < 0) || ($sampleSuccesses > $sampleNumber) || ($sampleSuccesses > $populationSuccesses)) { return Functions::NAN(); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HypGeomDistTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HypGeomDistTest.php new file mode 100644 index 00000000..d05b60b5 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HypGeomDistTest.php @@ -0,0 +1,25 @@ +