Extract Permutation functions from the Statistical class into a dedicated Permutations class (#1851)

* Extract Permutation functions from the Statistical class into a dedicated Permutations class

Retain the original methods in the Statistical class as stubs for BC, but deprecate them. They will be removed for PHPSpreadsheet v2

Note that unit tests still point to the Statistical class stubs; these should be modified to use the Permutations class directly when the stubs are removed

Also provided a basic implementationof the PERMUTATIONA() Function
This commit is contained in:
Mark Baker
2021-02-13 15:35:07 +01:00
committed by GitHub
parent e824caf857
commit 42ecc270ec
7 changed files with 138 additions and 15 deletions
@@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Permutations;
use PHPUnit\Framework\TestCase;
class PermutationATest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerPERMUT
*
* @param mixed $expectedResult
*/
public function testPERMUT($expectedResult, ...$args): void
{
$result = Permutations::PERMUTATIONA(...$args);
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public function providerPERMUT()
{
return require 'tests/data/Calculation/Statistical/PERMUTATIONA.php';
}
}
@@ -45,6 +45,10 @@ return [
10068347520,
49, 6,
],
[
'#NUM!',
2, 3,
],
[
'#NUM!',
1, 2,
@@ -0,0 +1,28 @@
<?php
return [
[
5,
5, 1,
],
[
2,
2.2, 1.1,
],
[
5,
5.1, 1.9,
],
[
1,
1, 2,
],
[
'#NUM!',
-1, 2,
],
[
'#VALUE!',
49, 'NaN',
],
];