mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-03 05:57:46 +00:00
6fd24cad58
Test both the function implementation (directly), and when the function is called in a formula from a spreadsheet Replace error strings in expected result for providers with the value returned from the ExcelErrors class
80 lines
2.2 KiB
PHP
80 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Database\DStDev;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
|
|
|
class DStDevTest extends AllSetupTeardown
|
|
{
|
|
/**
|
|
* @dataProvider providerDStDev
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param mixed $database
|
|
* @param mixed $field
|
|
* @param mixed $criteria
|
|
*/
|
|
public function testDirectCallToDStDev($expectedResult, $database, $field, $criteria): void
|
|
{
|
|
$result = DStDev::evaluate($database, $field, $criteria);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerDStDev
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param mixed $database
|
|
* @param mixed $field
|
|
* @param mixed $criteria
|
|
*/
|
|
public function testDStDevAsWorksheetFormula($expectedResult, $database, $field, $criteria): void
|
|
{
|
|
$this->prepareWorksheetWithFormula('DSTDEV', $database, $field, $criteria);
|
|
|
|
$result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue();
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
|
|
}
|
|
|
|
public function providerDStDev(): array
|
|
{
|
|
return [
|
|
[
|
|
2.966479394838,
|
|
$this->database1(),
|
|
'Yield',
|
|
[
|
|
['Tree'],
|
|
['=Apple'],
|
|
['=Pear'],
|
|
],
|
|
],
|
|
[
|
|
0.104403065089,
|
|
$this->database3FilledIn(),
|
|
'Score',
|
|
[
|
|
['Subject', 'Gender'],
|
|
['English', 'Male'],
|
|
],
|
|
],
|
|
[
|
|
0.196723155729,
|
|
$this->database3FilledIn(),
|
|
'Score',
|
|
[
|
|
['Subject', 'Age'],
|
|
['Math', '>8'],
|
|
],
|
|
],
|
|
'omitted field name' => [
|
|
ExcelError::VALUE(),
|
|
$this->database1(),
|
|
null,
|
|
$this->database1(),
|
|
],
|
|
];
|
|
}
|
|
}
|