Implementation of the CHITEST() statistical function (#1960)

* Implementation of the CHITEST() statistical function

* A couple of additional edge case tests (rows = 1, columns = 1)
This commit is contained in:
Mark Baker
2021-03-27 22:04:05 +01:00
committed by GitHub
parent a34dd71cce
commit 67fec4e3fc
5 changed files with 110 additions and 2 deletions
@@ -0,0 +1,27 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class ChiTestTest extends TestCase
{
/**
* @dataProvider providerCHITEST
*
* @param mixed $expectedResult
* @param mixed $actual
* @param mixed $expected
*/
public function testCHITEST($expectedResult, $actual, $expected): void
{
$result = Statistical\Distributions\ChiSquared::test($actual, $expected);
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public function providerCHITEST()
{
return require 'tests/data/Calculation/Statistical/CHITEST.php';
}
}
@@ -0,0 +1,39 @@
<?php
return [
[
0.0152703571482,
[[112, 76], [85, 95]],
[[100, 85], [70, 90]],
],
[
0.000308192027,
[[58, 35], [11, 25], [10, 23]],
[[45.35, 47.65], [17.56, 18.44], [16.09, 16.91]],
],
[
0.015888560447,
[[58], [11], [10]],
[[45.35], [17.56], [16.09]],
],
[
0.008682970191,
[[58, 35]],
[[45.35, 47.65]],
],
[
'#NUM!',
[[58, 11], [10, 35], [25]],
[[45.35, 17.56], [16.09, 47.65], [18.44, 16.91]],
],
[
'#DIV/0!',
[[112, 76], [85, 95]],
[[100, 0], [70, 90]],
],
[
'#NUM!',
[[112, 76], [85, 95]],
[[100, 85], [-70, 90]],
],
];