Skip to content

Commit

Permalink
Additional statistical unit tests (#1818)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Baker authored Jan 31, 2021
1 parent 5d309e9 commit 18abae7
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 NegBinomDistTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}

/**
* @dataProvider providerNEGBINOMDIST
*
* @param mixed $expectedResult
*/
public function testNEGBINOMDIST($expectedResult, ...$args): void
{
$result = Statistical::NEGBINOMDIST(...$args);
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}

public function providerNEGBINOMDIST()
{
return require 'tests/data/Calculation/Statistical/NEGBINOMDIST.php';
}
}
Original file line number Diff line number Diff line change
@@ -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 PoissonTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}

/**
* @dataProvider providerPOISSON
*
* @param mixed $expectedResult
*/
public function testPOISSON($expectedResult, ...$args): void
{
$result = Statistical::POISSON(...$args);
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}

public function providerPOISSON()
{
return require 'tests/data/Calculation/Statistical/POISSON.php';
}
}
5 changes: 5 additions & 0 deletions tests/data/Calculation/MathTrig/FLOOR.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
-2.5,
2,
],
[
0.0,
0.0,
1,
],
[
'#NUM!',
2.5,
Expand Down
5 changes: 5 additions & 0 deletions tests/data/Calculation/MathTrig/FLOORMATH.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
2.5,
-2,
],
[
0.0,
0.0,
1,
],
[
'#DIV/0!',
123.456,
Expand Down
5 changes: 5 additions & 0 deletions tests/data/Calculation/MathTrig/FLOORPRECISE.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
2.5,
-2,
],
[
0.0,
0.0,
1,
],
[
'#DIV/0!',
123.456,
Expand Down
36 changes: 36 additions & 0 deletions tests/data/Calculation/Statistical/NEGBINOMDIST.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

return [
[
0.05504866037517786,
10, 5, 0.25,
],
[
0.047210693359375,
6, 12, 0.5,
],
[
0.0805901288986206,
12, 12, 0.5,
],
[
0.057564377784729004,
15, 12, 0.5,
],
[
'#VALUE!',
15, 12, 'NaN',
],
[
'#NUM!',
15, 12, -0.25,
],
[
'#NUM!',
-1, 1, 0.25,
],
[
'#NUM!',
1, 0.5, 0.25,
],
];
8 changes: 8 additions & 0 deletions tests/data/Calculation/Statistical/PERMUT.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@
10068347520,
49, 6,
],
[
'#NUM!',
1, 2,
],
[
'#VALUE!',
49, 'NaN',
],
];
28 changes: 28 additions & 0 deletions tests/data/Calculation/Statistical/POISSON.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

return [
[
0.12465201948308113,
2, 5, true,
],
[
0.08422433748856833,
2, 5, false,
],
[
0.05191746860849132,
20, 25, false,
],
[
0.24241419769010333,
35, 40, true,
],
[
'#NUM!',
35, -40, true,
],
[
'#VALUE!',
35, 'Nan', true,
],
];

0 comments on commit 18abae7

Please sign in to comment.