parent
2eaf9b53aa
commit
42e8680fc0
|
|
@ -2753,13 +2753,16 @@ class Statistical
|
||||||
$mean = Averages::AVERAGE($aArgs);
|
$mean = Averages::AVERAGE($aArgs);
|
||||||
$stdDev = StandardDeviations::STDEV($aArgs);
|
$stdDev = StandardDeviations::STDEV($aArgs);
|
||||||
|
|
||||||
|
if ($stdDev === 0.0 || is_string($stdDev)) {
|
||||||
|
return Functions::DIV0();
|
||||||
|
}
|
||||||
|
|
||||||
$count = $summer = 0;
|
$count = $summer = 0;
|
||||||
// Loop through arguments
|
// Loop through arguments
|
||||||
foreach ($aArgs as $k => $arg) {
|
foreach ($aArgs as $k => $arg) {
|
||||||
if (
|
if ((is_bool($arg)) && (!Functions::isMatrixValue($k))) {
|
||||||
(is_bool($arg)) &&
|
} elseif (!is_numeric($arg)) {
|
||||||
(!Functions::isMatrixValue($k))
|
return Functions::VALUE();
|
||||||
) {
|
|
||||||
} else {
|
} else {
|
||||||
// Is it a numeric value?
|
// Is it a numeric value?
|
||||||
if ((is_numeric($arg)) && (!is_string($arg))) {
|
if ((is_numeric($arg)) && (!is_string($arg))) {
|
||||||
|
|
@ -3173,6 +3176,7 @@ class Statistical
|
||||||
if (($percent < 0) || ($percent > 1)) {
|
if (($percent < 0) || ($percent > 1)) {
|
||||||
return Functions::NAN();
|
return Functions::NAN();
|
||||||
}
|
}
|
||||||
|
|
||||||
$mArgs = [];
|
$mArgs = [];
|
||||||
foreach ($aArgs as $arg) {
|
foreach ($aArgs as $arg) {
|
||||||
// Is it a numeric value?
|
// Is it a numeric value?
|
||||||
|
|
@ -3180,8 +3184,10 @@ class Statistical
|
||||||
$mArgs[] = $arg;
|
$mArgs[] = $arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$discard = floor(Counts::COUNT($mArgs) * $percent / 2);
|
$discard = floor(Counts::COUNT($mArgs) * $percent / 2);
|
||||||
sort($mArgs);
|
sort($mArgs);
|
||||||
|
|
||||||
for ($i = 0; $i < $discard; ++$i) {
|
for ($i = 0; $i < $discard; ++$i) {
|
||||||
array_pop($mArgs);
|
array_pop($mArgs);
|
||||||
array_shift($mArgs);
|
array_shift($mArgs);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class ColumnTest extends TestCase
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerCOLUMN
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
*/
|
||||||
|
public function testCOLUMN($expectedResult, string $cellReference): void
|
||||||
|
{
|
||||||
|
$result = LookupRef::COLUMN($cellReference);
|
||||||
|
self::assertSame($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerCOLUMN()
|
||||||
|
{
|
||||||
|
return require 'tests/data/Calculation/LookupRef/COLUMN.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class RowTest extends TestCase
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerROW
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
*/
|
||||||
|
public function testROW($expectedResult, string $cellReference): void
|
||||||
|
{
|
||||||
|
$result = LookupRef::ROW($cellReference);
|
||||||
|
self::assertSame($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerROW()
|
||||||
|
{
|
||||||
|
return require 'tests/data/Calculation/LookupRef/ROW.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 SkewTest extends TestCase
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerSKEW
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
*/
|
||||||
|
public function testSKEW($expectedResult, array $args): void
|
||||||
|
{
|
||||||
|
$result = Statistical::SKEW($args);
|
||||||
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerSKEW()
|
||||||
|
{
|
||||||
|
return require 'tests/data/Calculation/Statistical/SKEW.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class TrimMeanTest extends TestCase
|
||||||
|
{
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerTRIMMEAN
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
* @param mixed $percentage
|
||||||
|
*/
|
||||||
|
public function testTRIMMEAN($expectedResult, array $args, $percentage): void
|
||||||
|
{
|
||||||
|
$result = Statistical::TRIMMEAN($args, $percentage);
|
||||||
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerTRIMMEAN()
|
||||||
|
{
|
||||||
|
return require 'tests/data/Calculation/Statistical/TRIMMEAN.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
2,
|
||||||
|
'B13',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[2, 3, 4],
|
||||||
|
'B2:D2',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
10,
|
||||||
|
'C10',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
[[10], [11], [12]],
|
||||||
|
'C10:C12',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
@ -16,4 +16,14 @@ return [
|
||||||
[2, 7, 8, 3, 4, 1, 6, 5],
|
[2, 7, 8, 3, 4, 1, 6, 5],
|
||||||
[22.9, 33.49, 34.5, 27.61, 19.5, 10.11, 37.9, 31.08],
|
[22.9, 33.49, 34.5, 27.61, 19.5, 10.11, 37.9, 31.08],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#N/A',
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, 5],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#DIV/0!',
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, null, null],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -43,4 +43,22 @@ return [
|
||||||
[3, 7, 15, 20, 22, 27],
|
[3, 7, 15, 20, 22, 27],
|
||||||
[1, 2, 3, 4, 5, 6],
|
[1, 2, 3, 4, 5, 6],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
'NaN',
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, 5],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#N/A',
|
||||||
|
2,
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, 5],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#DIV/0!',
|
||||||
|
2,
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, null, null],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,14 @@ return [
|
||||||
[6, 9, 17, 20, 20, 27],
|
[6, 9, 17, 20, 20, 27],
|
||||||
[1, 2, 3, 4, 5, 6],
|
[1, 2, 3, 4, 5, 6],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#N/A',
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, 5],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#DIV/0!',
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, null, null],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,14 @@ return [
|
||||||
[2, 7, 8, 3, 4, 1, 6, 5],
|
[2, 7, 8, 3, 4, 1, 6, 5],
|
||||||
[22.9, 33.49, 34.5, 27.61, 19.5, 10.11, 37.90, 31.08],
|
[22.9, 33.49, 34.5, 27.61, 19.5, 10.11, 37.90, 31.08],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#N/A',
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, 5],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#DIV/0!',
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, null, null],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
0.359543071407,
|
||||||
|
[3, 4, 5, 2, 3, 4, 5, 6, 4, 7],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
0.863378312234,
|
||||||
|
[1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 7, 8],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
[1, 1, 2, 2, 2, 2, 3, 'NaN', 3, 4, 4, 5, 6, 7, 8],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#DIV/0!',
|
||||||
|
[1, 1],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
@ -65,4 +65,14 @@ return [
|
||||||
4,
|
4,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'#N/A',
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, 5],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#DIV/0!',
|
||||||
|
[1, 2, 3],
|
||||||
|
[4, null, null],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
3.777777777778,
|
||||||
|
[4, 5, 6, 7, 2, 3, 4, 5, 1, 2, 3],
|
||||||
|
0.2,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
9.45,
|
||||||
|
[0.5, 6, 7, 7, 8, 8, 9, 9, 16, 24],
|
||||||
|
0.15,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
8.75,
|
||||||
|
[0.5, 6, 7, 7, 8, 8, 9, 9, 16, 24],
|
||||||
|
0.2,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
8.0,
|
||||||
|
[0.5, 6, 7, 7, 8, 8, 9, 9, 16, 24],
|
||||||
|
0.4,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#NUM!',
|
||||||
|
[0.5, 6, 7, 7, 8, 8, 9, 9, 16, 24],
|
||||||
|
15,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'#VALUE!',
|
||||||
|
[0.5, 6, 7, 7, 8, 8, 9, 9, 16, 24],
|
||||||
|
'NaN',
|
||||||
|
],
|
||||||
|
];
|
||||||
Loading…
Reference in New Issue