Identify HYPGEOM.DIST() as a separate Excel function, and additional unit tests (including unhappy path) (#1595)
This commit is contained in:
parent
f34cc6cf6e
commit
a9c8470b3b
|
@ -1250,6 +1250,11 @@ class Calculation
|
||||||
'functionCall' => [Statistical::class, 'HYPGEOMDIST'],
|
'functionCall' => [Statistical::class, 'HYPGEOMDIST'],
|
||||||
'argumentCount' => '4',
|
'argumentCount' => '4',
|
||||||
],
|
],
|
||||||
|
'HYPGEOM.DIST' => [
|
||||||
|
'category' => Category::CATEGORY_STATISTICAL,
|
||||||
|
'functionCall' => [Functions::class, 'DUMMY'],
|
||||||
|
'argumentCount' => '5',
|
||||||
|
],
|
||||||
'IF' => [
|
'IF' => [
|
||||||
'category' => Category::CATEGORY_LOGICAL,
|
'category' => Category::CATEGORY_LOGICAL,
|
||||||
'functionCall' => [Logical::class, 'statementIf'],
|
'functionCall' => [Logical::class, 'statementIf'],
|
||||||
|
|
|
@ -1901,12 +1901,17 @@ class Statistical
|
||||||
*/
|
*/
|
||||||
public static function HYPGEOMDIST($sampleSuccesses, $sampleNumber, $populationSuccesses, $populationNumber)
|
public static function HYPGEOMDIST($sampleSuccesses, $sampleNumber, $populationSuccesses, $populationNumber)
|
||||||
{
|
{
|
||||||
$sampleSuccesses = floor(Functions::flattenSingleValue($sampleSuccesses));
|
$sampleSuccesses = Functions::flattenSingleValue($sampleSuccesses);
|
||||||
$sampleNumber = floor(Functions::flattenSingleValue($sampleNumber));
|
$sampleNumber = Functions::flattenSingleValue($sampleNumber);
|
||||||
$populationSuccesses = floor(Functions::flattenSingleValue($populationSuccesses));
|
$populationSuccesses = Functions::flattenSingleValue($populationSuccesses);
|
||||||
$populationNumber = floor(Functions::flattenSingleValue($populationNumber));
|
$populationNumber = Functions::flattenSingleValue($populationNumber);
|
||||||
|
|
||||||
if ((is_numeric($sampleSuccesses)) && (is_numeric($sampleNumber)) && (is_numeric($populationSuccesses)) && (is_numeric($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)) {
|
if (($sampleSuccesses < 0) || ($sampleSuccesses > $sampleNumber) || ($sampleSuccesses > $populationSuccesses)) {
|
||||||
return Functions::NAN();
|
return Functions::NAN();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class HypGeomDistTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @dataProvider providerHYPGEOMDIST
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
*/
|
||||||
|
public function testHYPGEOMDIST($expectedResult, ...$args): void
|
||||||
|
{
|
||||||
|
$result = Statistical::HYPGEOMDIST(...$args);
|
||||||
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerHYPGEOMDIST()
|
||||||
|
{
|
||||||
|
return require 'tests/data/Calculation/Statistical/HYPGEOMDIST.php';
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,6 +37,10 @@ return [
|
||||||
'#VALUE!',
|
'#VALUE!',
|
||||||
'NAN', 3,
|
'NAN', 3,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#NUM!',
|
||||||
|
8, 0,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'#NUM!',
|
'#NUM!',
|
||||||
-8, 3,
|
-8, 3,
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
[
|
||||||
|
0.03263913041829,
|
||||||
|
10.00001131, 9, 2, false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
0.06809400387,
|
||||||
|
10.00001131, 9, 2, true,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
0.112020903828,
|
0.112020903828,
|
||||||
6, 3, 2, false,
|
6, 3, 2, false,
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
[
|
||||||
|
10.0000111914377,
|
||||||
|
0.068094, 9, 2,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
5.348120627447,
|
5.348120627447,
|
||||||
0.5, 3, 2,
|
0.5, 3, 2,
|
||||||
|
|
|
@ -5,6 +5,10 @@ return [
|
||||||
2.453736570842,
|
2.453736570842,
|
||||||
4.5,
|
4.5,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
1.791759469228,
|
||||||
|
4,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'#VALUE!',
|
'#VALUE!',
|
||||||
'NAN',
|
'NAN',
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
[
|
||||||
|
5.47698696965696,
|
||||||
|
4, 5, 8, 7, 11, 4, 3,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
1.6226711115996,
|
1.6226711115996,
|
||||||
2.5, 3, 0.5, 1, 3,
|
2.5, 3, 0.5, 1, 3,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#NUM!',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,8 +1,19 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
[
|
||||||
|
5.028375962062,
|
||||||
|
4, 5, 8, 7, 11, 4, 3,
|
||||||
|
],
|
||||||
[
|
[
|
||||||
1.2295081967213,
|
1.2295081967213,
|
||||||
2.5, 3, 0.5, 1, 3,
|
2.5, 3, 0.5, 1, 3,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#NUM!',
|
||||||
|
2.5, -3, 0.5, 1, 3,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#N/A',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
0.3632610939112,
|
||||||
|
1, 4, 8, 20,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
0.4525252525252,
|
||||||
|
1, 4, 4, 12,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
0.3393939393939,
|
||||||
|
2, 4, 4, 12,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
0.0646464646465,
|
||||||
|
3, 4, 4, 12,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
0.0020202020202,
|
||||||
|
4, 4, 4, 12,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
'NAN', 4, 4, 12,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#NUM!',
|
||||||
|
5, 4, 4, 12,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#NUM!',
|
||||||
|
4, 4, 4, 3,
|
||||||
|
],
|
||||||
|
];
|
Loading…
Reference in New Issue