Extended unit tests (#1087)
* Merge branch 'master' of C:\Projects\PHPOffice\PHPSpreadsheet\develop with conflicts. * Additional unit tests for average functions, and fix to AVERAGEIF() function if third argument is passed * Update change log * Stricter typed comparisons in AVERAGEIF() conditions * Unit tests for BETADIST() and BETAINV()
This commit is contained in:
parent
5f7ed98aa6
commit
f1e82a212f
|
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
|||
|
||||
### Fixed
|
||||
|
||||
- Fix to AVERAGEIF() function when called with a third argument
|
||||
- Eliminate duplicate fill none style entries [Issue #1066](https://github.com/PHPOffice/PhpSpreadsheet/issues/1066)
|
||||
- Fix number format masks containing literal (non-decimal point) dots [Issue #1079](https://github.com/PHPOffice/PhpSpreadsheet/issues/1079)
|
||||
- Fix number format masks containing named colours that were being misinterpreted as date formats; and add support for masks that fully replace the value with a full text string [Issue #1009](https://github.com/PHPOffice/PhpSpreadsheet/issues/1009)
|
||||
|
|
|
@ -147,7 +147,7 @@ class Database
|
|||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function DAVERAGE($database, $field, $criteria)
|
||||
{
|
||||
|
@ -452,7 +452,7 @@ class Database
|
|||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function DSTDEV($database, $field, $criteria)
|
||||
{
|
||||
|
@ -493,7 +493,7 @@ class Database
|
|||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function DSTDEVP($database, $field, $criteria)
|
||||
{
|
||||
|
|
|
@ -1116,7 +1116,7 @@ class MathTrig
|
|||
* in hidden rows or columns
|
||||
* @param array of mixed Data Series
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function SUBTOTAL(...$args)
|
||||
{
|
||||
|
|
|
@ -531,7 +531,7 @@ class Statistical
|
|||
*
|
||||
* @param mixed ...$args Data values
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function AVEDEV(...$args)
|
||||
{
|
||||
|
@ -582,7 +582,7 @@ class Statistical
|
|||
*
|
||||
* @param mixed ...$args Data values
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function AVERAGE(...$args)
|
||||
{
|
||||
|
@ -625,7 +625,7 @@ class Statistical
|
|||
*
|
||||
* @param mixed ...$args Data values
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function AVERAGEA(...$args)
|
||||
{
|
||||
|
@ -674,7 +674,7 @@ class Statistical
|
|||
* @param string $condition the criteria that defines which cells will be checked
|
||||
* @param mixed[] $averageArgs Data values
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function AVERAGEIF($aArgs, $condition, $averageArgs = [])
|
||||
{
|
||||
|
@ -686,20 +686,25 @@ class Statistical
|
|||
$averageArgs = $aArgs;
|
||||
}
|
||||
$condition = Functions::ifCondition($condition);
|
||||
$conditionIsNumeric = strpos($condition, '"') === false;
|
||||
|
||||
// Loop through arguments
|
||||
$aCount = 0;
|
||||
foreach ($aArgs as $key => $arg) {
|
||||
if (!is_numeric($arg)) {
|
||||
if ($conditionIsNumeric) {
|
||||
continue;
|
||||
}
|
||||
$arg = Calculation::wrapResult(strtoupper($arg));
|
||||
} elseif (!$conditionIsNumeric) {
|
||||
continue;
|
||||
}
|
||||
$testCondition = '=' . $arg . $condition;
|
||||
if (Calculation::getInstance()->_calculateFormulaValue($testCondition)) {
|
||||
if (($returnValue === null) || ($arg > $returnValue)) {
|
||||
$returnValue += $arg;
|
||||
$returnValue += $averageArgs[$key];
|
||||
++$aCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($aCount > 0) {
|
||||
return $returnValue / $aCount;
|
||||
|
@ -719,7 +724,7 @@ class Statistical
|
|||
* @param mixed $rMin
|
||||
* @param mixed $rMax
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function BETADIST($value, $alpha, $beta, $rMin = 0, $rMax = 1)
|
||||
{
|
||||
|
@ -758,7 +763,7 @@ class Statistical
|
|||
* @param float $rMin Minimum value
|
||||
* @param float $rMax Maximum value
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function BETAINV($probability, $alpha, $beta, $rMin = 0, $rMax = 1)
|
||||
{
|
||||
|
@ -1376,7 +1381,7 @@ class Statistical
|
|||
*
|
||||
* @param mixed ...$args Data values
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function DEVSQ(...$args)
|
||||
{
|
||||
|
@ -1843,7 +1848,7 @@ class Statistical
|
|||
*
|
||||
* @param array ...$args Data Series
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function KURT(...$args)
|
||||
{
|
||||
|
@ -2912,7 +2917,7 @@ class Statistical
|
|||
*
|
||||
* @param array ...$args Data Series
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function SKEW(...$args)
|
||||
{
|
||||
|
@ -3055,7 +3060,7 @@ class Statistical
|
|||
*
|
||||
* @param mixed ...$args Data values
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function STDEV(...$args)
|
||||
{
|
||||
|
@ -3104,7 +3109,7 @@ class Statistical
|
|||
*
|
||||
* @param mixed ...$args Data values
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function STDEVA(...$args)
|
||||
{
|
||||
|
@ -3156,7 +3161,7 @@ class Statistical
|
|||
*
|
||||
* @param mixed ...$args Data values
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function STDEVP(...$args)
|
||||
{
|
||||
|
@ -3203,7 +3208,7 @@ class Statistical
|
|||
*
|
||||
* @param mixed ...$args Data values
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function STDEVPA(...$args)
|
||||
{
|
||||
|
@ -3442,7 +3447,7 @@ class Statistical
|
|||
* @param mixed $args Data values
|
||||
* @param float $discard Percentage to discard
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function TRIMMEAN(...$args)
|
||||
{
|
||||
|
@ -3715,7 +3720,7 @@ class Statistical
|
|||
* @param float $m0 Alpha Parameter
|
||||
* @param float $sigma Beta Parameter
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function ZTEST($dataSet, $m0, $sigma = null)
|
||||
{
|
||||
|
|
|
@ -13,6 +13,102 @@ class StatisticalTest extends TestCase
|
|||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAVEDEV
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testAVEDEV($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::AVEDEV(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerAVEDEV()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/AVEDEV.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAVERAGE
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testAVERAGE($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::AVERAGE(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerAVERAGE()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/AVERAGE.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAVERAGEA
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testAVERAGEA($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::AVERAGEA(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerAVERAGEA()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/AVERAGEA.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerAVERAGEIF
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testAVERAGEIF($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::AVERAGEIF(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerAVERAGEIF()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/AVERAGEIF.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerBETADIST
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testBETADIST($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::BETADIST(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerBETADIST()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/BETADIST.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerBETAINV
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testBETAINV($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::BETAINV(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerBETAINV()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/BETAINV.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerCOUNTIF
|
||||
*
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
1.020408163265,
|
||||
[4, 5, 6, 7, 5, 4, 3],
|
||||
],
|
||||
[
|
||||
1.65,
|
||||
[10.5, 7.2],
|
||||
],
|
||||
[
|
||||
17.2,
|
||||
[7.2, 5.4, 45],
|
||||
],
|
||||
[
|
||||
61.504,
|
||||
[10.5, 7.2, 200, 5.4, 8.1],
|
||||
],
|
||||
];
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
11,
|
||||
[10, 7, 9, 27, 2],
|
||||
],
|
||||
[
|
||||
10,
|
||||
[10, 7, 9, 27, 2, 5],
|
||||
],
|
||||
[
|
||||
19,
|
||||
[10, 15, 32],
|
||||
],
|
||||
[
|
||||
8.85,
|
||||
[10.5, 7.2],
|
||||
],
|
||||
[
|
||||
19.2,
|
||||
[7.2, 5.4, 45],
|
||||
],
|
||||
[
|
||||
46.24,
|
||||
[10.5, 7.2, 200, 5.4, 8.1],
|
||||
],
|
||||
];
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
7.0,
|
||||
[10, 7, 9, 2],
|
||||
],
|
||||
[
|
||||
5.6,
|
||||
[10, 7, 9, 2, 'STRING VALUE'],
|
||||
],
|
||||
[
|
||||
8.85,
|
||||
[10.5, 7.2],
|
||||
],
|
||||
[
|
||||
43.74,
|
||||
[10.5, 7.2, 200, true, false],
|
||||
],
|
||||
[
|
||||
0.5,
|
||||
[true, false],
|
||||
],
|
||||
];
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
14000,
|
||||
[7000, 14000, 21000, 28000],
|
||||
"<23000",
|
||||
],
|
||||
[
|
||||
150000,
|
||||
[100000, 200000, 300000, 400000],
|
||||
"<250000",
|
||||
],
|
||||
[
|
||||
'#DIV/0!',
|
||||
[100000, 200000, 300000, 400000],
|
||||
"<95000",
|
||||
],
|
||||
[
|
||||
24500,
|
||||
[100000, 200000, 300000, 400000],
|
||||
">250000",
|
||||
[7000, 14000, 21000, 28000],
|
||||
],
|
||||
[
|
||||
8.2,
|
||||
[2012, 2012, 2013, 2011, 2011, 2010],
|
||||
2012,
|
||||
[6, 10.4, 7, 12, 8, 15],
|
||||
],
|
||||
[
|
||||
10,
|
||||
[2012, 2012, 2013, 2011, 2011, 2010],
|
||||
2011,
|
||||
[6, 10.4, 7, 12, 8, 15],
|
||||
],
|
||||
[
|
||||
7.8,
|
||||
[2012, 2012, 2013, 2011, 2011, 2010],
|
||||
">=2012",
|
||||
[6, 10.4, 7, 12, 8, 15],
|
||||
],
|
||||
[
|
||||
2011.2,
|
||||
[2012, 2012, 2013, 2011, 2011, 2010],
|
||||
"<2013",
|
||||
],
|
||||
];
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
0.960370937542,
|
||||
3, 7.5, 9, 1, 4,
|
||||
],
|
||||
[
|
||||
0.598190307617,
|
||||
7.5, 8, 9, 5, 10,
|
||||
],
|
||||
];
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
2.164759759129,
|
||||
0.3, 7.5, 9, 1, 4,
|
||||
],
|
||||
[
|
||||
7.761240188783,
|
||||
0.75, 8, 9, 5, 10,
|
||||
],
|
||||
];
|
Loading…
Reference in New Issue