mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-10-02 09:57:25 +00:00
70b4ecd4d3
They aren't quite interchangeable. Both are used in the test suite, with no indication of why one or the other. I think we'd be best off being consistent. Based on the names, I think `_calculateFormulaValue` was intended as a private, or at least internal, method, so favor `calculateFormula`. I do not intend to rename or re-categorize `_calculateFormulaValue`, just remove its usage when it isn't clearly warranted.
61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
|
|
|
class ChiInvLeftTailTest extends AllSetupTeardown
|
|
{
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerCHIINV')]
|
|
public function testCHIINV(mixed $expectedResult, mixed ...$args): void
|
|
{
|
|
$this->runTestCaseReference('CHISQ.INV', $expectedResult, ...$args);
|
|
}
|
|
|
|
public static function providerCHIINV(): array
|
|
{
|
|
return require 'tests/data/Calculation/Statistical/CHIINVLeftTail.php';
|
|
}
|
|
|
|
public function invVersusDistTest(): void
|
|
{
|
|
$expectedResult = 4.671330448981;
|
|
$probability = 0.3;
|
|
$degrees = 7;
|
|
$calculation = Calculation::getInstance();
|
|
$formula = "=CHISQ.INV($probability, $degrees)";
|
|
/** @var float|int|string */
|
|
$result = $calculation->calculateFormula($formula);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8);
|
|
$formula = "=CHISQ.DIST($result, $degrees)";
|
|
$result = $calculation->calculateFormula($formula);
|
|
self::assertEqualsWithDelta($probability, $result, 1.0e-8);
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerChiInvLeftTailArray')]
|
|
public function testChiInvLeftTailArray(array $expectedResult, string $probabilities, string $degrees): void
|
|
{
|
|
$calculation = Calculation::getInstance();
|
|
|
|
$formula = "=CHISQ.INV({$probabilities}, {$degrees})";
|
|
$result = $calculation->calculateFormula($formula);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
|
|
}
|
|
|
|
public static function providerChiInvLeftTailArray(): array
|
|
{
|
|
return [
|
|
'row/column vectors' => [
|
|
[
|
|
[5.0816470296362795, 6.345811195521517, 1.508898337422818],
|
|
[9.61151737996991, 11.34032237742413, 4.0773397083341045],
|
|
],
|
|
'{0.35, 0.5, 0.018}',
|
|
'{7; 12}',
|
|
],
|
|
];
|
|
}
|
|
}
|