Statistical issues (#1098)

* Merge branch 'master' of C:\Projects\PHPOffice\PHPSpreadsheet\develop with conflicts.

* Adjusted logic for COUNT() function to handle differences in EXCEL, GNUMERIC and OPENOFFICE modes for cells and for literal values

* Fix case-sensitivity in filenames

* Appeasing Codesniffer

* Resolve COUNTA() differences between cell values and literals

* Style fixes

* Start refactoring statistical function tests into individual tests rather than having a single, giant test for all statistical functions.... first step toward doing this for all tests

* More refactoring into separate tests
If all functions have their own individual test files, it should be a lot easier to identify which functions aren't covered by tests yet

* Missing last lines in files
This commit is contained in:
Mark Baker 2019-07-20 18:40:05 +02:00 committed by GitHub
parent a367f35438
commit 554684720d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 1125 additions and 368 deletions

View File

@ -1022,12 +1022,20 @@ class Statistical
// Loop through arguments // Loop through arguments
$aArgs = Functions::flattenArrayIndexed($args); $aArgs = Functions::flattenArrayIndexed($args);
foreach ($aArgs as $k => $arg) { foreach ($aArgs as $k => $arg) {
// MS Excel does not count Booleans if passed as cell values, but they are counted if passed as literals
// OpenOffice Calc always counts Booleans
// Gnumeric never counts Booleans
if ((is_bool($arg)) && if ((is_bool($arg)) &&
((!Functions::isCellValue($k)) || (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE))) { ((!Functions::isCellValue($k) && (Functions::getCompatibilityMode() === Functions::COMPATIBILITY_EXCEL)) ||
(Functions::getCompatibilityMode() === Functions::COMPATIBILITY_OPENOFFICE))) {
$arg = (int) $arg; $arg = (int) $arg;
} }
// Is it a numeric value? // Is it a numeric value?
if ((is_numeric($arg)) && (!is_string($arg))) { // Strings containing numeric values are only counted if they are string literals (not cell values)
// and then only in MS Excel and in Open Office, not in Gnumeric
if (((is_numeric($arg)) && (!is_string($arg))) ||
((is_numeric($arg)) && (!Functions::isCellValue($k)) &&
(Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_GNUMERIC))) {
++$returnValue; ++$returnValue;
} }
} }
@ -1054,10 +1062,10 @@ class Statistical
$returnValue = 0; $returnValue = 0;
// Loop through arguments // Loop through arguments
$aArgs = Functions::flattenArray($args); $aArgs = Functions::flattenArrayIndexed($args);
foreach ($aArgs as $arg) { foreach ($aArgs as $k => $arg) {
// Is it a numeric, boolean or string value? // Nulls are counted if literals, but not if cell values
if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) && ($arg != '')))) { if ($arg !== null || (!Functions::isCellValue($k))) {
++$returnValue; ++$returnValue;
} }
} }
@ -1264,19 +1272,24 @@ class Statistical
$alpha = Functions::flattenSingleValue($alpha); $alpha = Functions::flattenSingleValue($alpha);
if ((is_numeric($trials)) && (is_numeric($probability)) && (is_numeric($alpha))) { if ((is_numeric($trials)) && (is_numeric($probability)) && (is_numeric($alpha))) {
$trials = (int) $trials;
$trialsApprox = $trials;
if ($trials < 0) { if ($trials < 0) {
return Functions::NAN(); return Functions::NAN();
} elseif (($probability < 0) || ($probability > 1)) { } elseif (($probability < 0.0) || ($probability > 1.0)) {
return Functions::NAN(); return Functions::NAN();
} elseif (($alpha < 0) || ($alpha > 1)) { } elseif (($alpha < 0.0) || ($alpha > 1.0)) {
return Functions::NAN(); return Functions::NAN();
} elseif ($alpha <= 0.5) { }
if ($alpha <= 0.5) {
$t = sqrt(log(1 / ($alpha * $alpha))); $t = sqrt(log(1 / ($alpha * $alpha)));
$trialsApprox = 0 - ($t + (2.515517 + 0.802853 * $t + 0.010328 * $t * $t) / (1 + 1.432788 * $t + 0.189269 * $t * $t + 0.001308 * $t * $t * $t)); $trialsApprox = 0 - ($t + (2.515517 + 0.802853 * $t + 0.010328 * $t * $t) / (1 + 1.432788 * $t + 0.189269 * $t * $t + 0.001308 * $t * $t * $t));
} else { } else {
$t = sqrt(log(1 / pow(1 - $alpha, 2))); $t = sqrt(log(1 / pow(1 - $alpha, 2)));
$trialsApprox = $t - (2.515517 + 0.802853 * $t + 0.010328 * $t * $t) / (1 + 1.432788 * $t + 0.189269 * $t * $t + 0.001308 * $t * $t * $t); $trialsApprox = $t - (2.515517 + 0.802853 * $t + 0.010328 * $t * $t) / (1 + 1.432788 * $t + 0.189269 * $t * $t + 0.001308 * $t * $t * $t);
} }
$Guess = floor($trials * $probability + $trialsApprox * sqrt($trials * $probability * (1 - $probability))); $Guess = floor($trials * $probability + $trialsApprox * sqrt($trials * $probability * (1 - $probability)));
if ($Guess < 0) { if ($Guess < 0) {
$Guess = 0; $Guess = 0;

View File

@ -209,11 +209,8 @@ class Color extends Supervisor
private static function getColourComponent($RGB, $offset, $hex = true) private static function getColourComponent($RGB, $offset, $hex = true)
{ {
$colour = substr($RGB, $offset, 2); $colour = substr($RGB, $offset, 2);
if (!$hex) {
$colour = hexdec($colour);
}
return $colour; return ($hex) ? $colour : hexdec($colour);
} }
/** /**
@ -268,7 +265,7 @@ class Color extends Supervisor
*/ */
public static function changeBrightness($hex, $adjustPercentage) public static function changeBrightness($hex, $adjustPercentage)
{ {
$rgba = (strlen($hex) == 8); $rgba = (strlen($hex) === 8);
$red = self::getRed($hex, false); $red = self::getRed($hex, false);
$green = self::getGreen($hex, false); $green = self::getGreen($hex, false);
@ -300,9 +297,9 @@ class Color extends Supervisor
} }
$rgb = strtoupper( $rgb = strtoupper(
str_pad(dechex($red), 2, '0', 0) . str_pad(dechex((int) $red), 2, '0', 0) .
str_pad(dechex($green), 2, '0', 0) . str_pad(dechex((int) $green), 2, '0', 0) .
str_pad(dechex($blue), 2, '0', 0) str_pad(dechex((int) $blue), 2, '0', 0)
); );
return (($rgba) ? 'FF' : '') . $rgb; return (($rgba) ? 'FF' : '') . $rgb;

View File

@ -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 AveDevTest extends TestCase
{
public function setUp()
{
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';
}
}

View File

@ -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 AverageATest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @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';
}
}

View File

@ -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 AverageIfTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @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';
}
}

View File

@ -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 AverageTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @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';
}
}

View File

@ -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 BetaDistTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @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';
}
}

View File

@ -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 BetaInvTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @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';
}
}

View File

@ -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 BinomDistTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerBINOMDIST
*
* @param mixed $expectedResult
*/
public function testBINOMDIST($expectedResult, ...$args)
{
$result = Statistical::BINOMDIST(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerBINOMDIST()
{
return require 'data/Calculation/Statistical/BINOMDIST.php';
}
}

View File

@ -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 ChiDistTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCHIDIST
*
* @param mixed $expectedResult
*/
public function testCHIDIST($expectedResult, ...$args)
{
$result = Statistical::CHIDIST(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCHIDIST()
{
return require 'data/Calculation/Statistical/CHIDIST.php';
}
}

View File

@ -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 ChiInvTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCHIINV
*
* @param mixed $expectedResult
*/
public function testCHIINV($expectedResult, ...$args)
{
$result = Statistical::CHIINV(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCHIINV()
{
return require 'data/Calculation/Statistical/CHIINV.php';
}
}

View File

@ -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 ConfidenceTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCONFIDENCE
*
* @param mixed $expectedResult
*/
public function testCONFIDENCE($expectedResult, ...$args)
{
$result = Statistical::CONFIDENCE(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCONFIDENCE()
{
return require 'data/Calculation/Statistical/CONFIDENCE.php';
}
}

View File

@ -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 CorrelTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCORREL
*
* @param mixed $expectedResult
*/
public function testCORREL($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::CORREL($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCORREL()
{
return require 'data/Calculation/Statistical/CORREL.php';
}
}

View File

@ -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 CountATest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCOUNTA
*
* @param mixed $expectedResult
*/
public function testCOUNTA($expectedResult, ...$args)
{
$result = Statistical::COUNTA(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOUNTA()
{
return require 'data/Calculation/Statistical/COUNTA.php';
}
}

View File

@ -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 CountBlankTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCOUNTBLANK
*
* @param mixed $expectedResult
*/
public function testCOUNTBLANK($expectedResult, ...$args)
{
$result = Statistical::COUNTBLANK(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOUNTBLANK()
{
return require 'data/Calculation/Statistical/COUNTBLANK.php';
}
}

View File

@ -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 CountIfTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCOUNTIF
*
* @param mixed $expectedResult
*/
public function testCOUNTIF($expectedResult, ...$args)
{
$result = Statistical::COUNTIF(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOUNTIF()
{
return require 'data/Calculation/Statistical/COUNTIF.php';
}
}

View File

@ -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 CountIfsTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCOUNTIFS
*
* @param mixed $expectedResult
*/
public function testCOUNTIFS($expectedResult, ...$args)
{
$result = Statistical::COUNTIFS(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOUNTIFS()
{
return require 'data/Calculation/Statistical/COUNTIFS.php';
}
}

View File

@ -0,0 +1,83 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class CountTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerBasicCOUNT
*
* @param mixed $expectedResult
*/
public function testBasicCOUNT($expectedResult, ...$args)
{
$result = Statistical::COUNT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerBasicCOUNT()
{
return require 'data/Calculation/Statistical/BasicCOUNT.php';
}
/**
* @dataProvider providerExcelCOUNT
*
* @param mixed $expectedResult
*/
public function testExcelCOUNT($expectedResult, ...$args)
{
$result = Statistical::COUNT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerExcelCOUNT()
{
return require 'data/Calculation/Statistical/ExcelCOUNT.php';
}
/**
* @dataProvider providerOpenOfficeCOUNT
*
* @param mixed $expectedResult
*/
public function testOpenOfficeCOUNT($expectedResult, ...$args)
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$result = Statistical::COUNT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerOpenOfficeCOUNT()
{
return require 'data/Calculation/Statistical/OpenOfficeCOUNT.php';
}
/**
* @dataProvider providerGnumericCOUNT
*
* @param mixed $expectedResult
*/
public function testGnumericCOUNT($expectedResult, ...$args)
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$result = Statistical::COUNT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerGnumericCOUNT()
{
return require 'data/Calculation/Statistical/GnumericCOUNT.php';
}
}

View File

@ -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 CovarTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCOVAR
*
* @param mixed $expectedResult
*/
public function testCOVAR($expectedResult, ...$args)
{
$result = Statistical::COVAR(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOVAR()
{
return require 'data/Calculation/Statistical/COVAR.php';
}
}

View File

@ -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 ForecastTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerFORECAST
*
* @param mixed $expectedResult
*/
public function testFORECAST($expectedResult, ...$args)
{
$result = Statistical::FORECAST(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerFORECAST()
{
return require 'data/Calculation/Statistical/FORECAST.php';
}
}

View File

@ -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 InterceptTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerINTERCEPT
*
* @param mixed $expectedResult
*/
public function testINTERCEPT($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::INTERCEPT($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerINTERCEPT()
{
return require 'data/Calculation/Statistical/INTERCEPT.php';
}
}

View File

@ -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 MaxIfsTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerMAXIFS
*
* @param mixed $expectedResult
*/
public function testMAXIFS($expectedResult, ...$args)
{
$result = Statistical::MAXIFS(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerMAXIFS()
{
return require 'data/Calculation/Statistical/MAXIFS.php';
}
}

View File

@ -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 MinIfsTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerMINIFS
*
* @param mixed $expectedResult
*/
public function testMINIFS($expectedResult, ...$args)
{
$result = Statistical::MINIFS(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerMINIFS()
{
return require 'data/Calculation/Statistical/MINIFS.php';
}
}

View File

@ -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 PermutTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerPERMUT
*
* @param mixed $expectedResult
*/
public function testPERMUT($expectedResult, ...$args)
{
$result = Statistical::PERMUT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerPERMUT()
{
return require 'data/Calculation/Statistical/PERMUT.php';
}
}

View File

@ -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 RsqTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerRSQ
*
* @param mixed $expectedResult
*/
public function testRSQ($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::RSQ($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerRSQ()
{
return require 'data/Calculation/Statistical/RSQ.php';
}
}

View File

@ -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 SlopeTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerSLOPE
*
* @param mixed $expectedResult
*/
public function testSLOPE($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::SLOPE($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerSLOPE()
{
return require 'data/Calculation/Statistical/SLOPE.php';
}
}

View File

@ -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 SteyxTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerSTEYX
*
* @param mixed $expectedResult
*/
public function testSTEYX($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::STEYX($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerSTEYX()
{
return require 'data/Calculation/Statistical/STEYX.php';
}
}

View File

@ -1,351 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class StatisticalTest extends TestCase
{
public function setUp()
{
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 providerBINOMDIST
*
* @param mixed $expectedResult
*/
public function testBINOMDIST($expectedResult, ...$args)
{
$result = Statistical::BINOMDIST(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerBINOMDIST()
{
return require 'data/Calculation/Statistical/BINOMDIST.php';
}
/**
* @dataProvider providerCHIDIST
*
* @param mixed $expectedResult
*/
public function testCHIDIST($expectedResult, ...$args)
{
$result = Statistical::CHIDIST(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCHIDIST()
{
return require 'data/Calculation/Statistical/CHIDIST.php';
}
/**
* @dataProvider providerCHIINV
*
* @param mixed $expectedResult
*/
public function testCHIINV($expectedResult, ...$args)
{
$result = Statistical::CHIINV(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCHIINV()
{
return require 'data/Calculation/Statistical/CHIINV.php';
}
/**
* @dataProvider providerCONFIDENCE
*
* @param mixed $expectedResult
*/
public function testCONFIDENCE($expectedResult, ...$args)
{
$result = Statistical::CONFIDENCE(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCONFIDENCE()
{
return require 'data/Calculation/Statistical/CONFIDENCE.php';
}
/**
* @dataProvider providerCORREL
*
* @param mixed $expectedResult
*/
public function testCORREL($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::CORREL($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCORREL()
{
return require 'data/Calculation/Statistical/CORREL.php';
}
/**
* @dataProvider providerCOUNTIF
*
* @param mixed $expectedResult
*/
public function testCOUNTIF($expectedResult, ...$args)
{
$result = Statistical::COUNTIF(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOUNTIF()
{
return require 'data/Calculation/Statistical/COUNTIF.php';
}
/**
* @dataProvider providerCOUNTIFS
*
* @param mixed $expectedResult
*/
public function testCOUNTIFS($expectedResult, ...$args)
{
$result = Statistical::COUNTIFS(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOUNTIFS()
{
return require 'data/Calculation/Statistical/COUNTIFS.php';
}
/**
* @dataProvider providerCOVAR
*
* @param mixed $expectedResult
*/
public function testCOVAR($expectedResult, ...$args)
{
$result = Statistical::COVAR(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerCOVAR()
{
return require 'data/Calculation/Statistical/COVAR.php';
}
/**
* @dataProvider providerFORECAST
*
* @param mixed $expectedResult
*/
public function testFORECAST($expectedResult, ...$args)
{
$result = Statistical::FORECAST(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerFORECAST()
{
return require 'data/Calculation/Statistical/FORECAST.php';
}
/**
* @dataProvider providerINTERCEPT
*
* @param mixed $expectedResult
*/
public function testINTERCEPT($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::INTERCEPT($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerINTERCEPT()
{
return require 'data/Calculation/Statistical/INTERCEPT.php';
}
/**
* @dataProvider providerMAXIFS
*
* @param mixed $expectedResult
*/
public function testMAXIFS($expectedResult, ...$args)
{
$result = Statistical::MAXIFS(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerMAXIFS()
{
return require 'data/Calculation/Statistical/MAXIFS.php';
}
/**
* @dataProvider providerMINIFS
*
* @param mixed $expectedResult
*/
public function testMINIFS($expectedResult, ...$args)
{
$result = Statistical::MINIFS(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerMINIFS()
{
return require 'data/Calculation/Statistical/MINIFS.php';
}
/**
* @dataProvider providerRSQ
*
* @param mixed $expectedResult
*/
public function testRSQ($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::RSQ($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerRSQ()
{
return require 'data/Calculation/Statistical/RSQ.php';
}
/**
* @dataProvider providerSLOPE
*
* @param mixed $expectedResult
*/
public function testSLOPE($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::SLOPE($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerSLOPE()
{
return require 'data/Calculation/Statistical/SLOPE.php';
}
/**
* @dataProvider providerSTEYX
*
* @param mixed $expectedResult
*/
public function testSTEYX($expectedResult, array $xargs, array $yargs)
{
$result = Statistical::STEYX($xargs, $yargs);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerSTEYX()
{
return require 'data/Calculation/Statistical/STEYX.php';
}
}

View File

@ -0,0 +1,27 @@
<?php
use PhpOffice\PhpSpreadsheet\Shared\Date;
return [
[
5,
[-1, 0, 1, 2, 3],
],
[
7,
[
Date::stringToExcel('1900-02-01'),
0,
null,
1.2,
'',
2.4,
'',
3.6,
'',
4.8,
'Not a numeric',
6
],
],
];

View File

@ -5,4 +5,12 @@ return [
0.692951912734, 0.692951912734,
0.05, 2.5, 50, 0.05, 2.5, 50,
], ],
[
0.48999099653,
0.05, 2.5, 100,
],
[
0.013719747903,
0.05, 0.07, 100,
],
]; ];

View File

@ -0,0 +1,51 @@
<?php
use PhpOffice\PhpSpreadsheet\Shared\Date;
return [
[
5,
[-1, 0, 1, 2, 3],
],
[
11,
[
// The index simulates a cell value
'0.1.A' => Date::stringToExcel('1900-02-01'),
'0.2.A' => 0,
'0.3.A' => null,
'0.4.A' => 1.2,
'0.5.A' => '',
'0.6.A' => 2.4,
'0.7.A' => null,
'0.8.A' => '',
'0.9.A' => 3.6,
'0.10.A' => null,
'0.11.A' => '',
'0.12.A' => 4.8,
'0.13.A' => 'Not a numeric',
'0.14.A' => 6
],
],
[
14,
[
// No index indicates arguments passed as literals rather than cell values
// In this case, nuls are counted as well as numbers
Date::stringToExcel('1900-02-01'),
0,
null,
1.2,
'',
2.4,
null,
'',
3.6,
null,
'',
4.8,
'Not a numeric',
6
],
],
];

View File

@ -0,0 +1,8 @@
<?php
return [
[
4,
[-1, null, 0, '', 1, null, 2, '', 3],
],
];

View File

@ -0,0 +1,24 @@
<?php
return [
[
4,
6, 0.5, 0.75,
],
[
7,
12, 0.5, 0.75,
],
[
46,
100, 0.5, 0.2,
],
[
50,
100, 0.5, 0.5,
],
[
56,
100, 0.5, 0.9,
],
];

View File

@ -0,0 +1,35 @@
<?php
return [
[
3,
[
// The index simulates a cell value
'0.1.A' => 'A',
'0.2.A' => 1,
'0.3.A' => true,
'0.4.A' => 2.9,
'0.5.A' => false,
'0.6.A' => '3',
'0.7.A' => '',
'0.8.A' => null,
'0.9.A' => 9,
],
],
[
6,
[
// No index indicates arguments passed as literals rather than cell values
// In this case, booleans are counted as well as numbers, as are numeric-value string literals
'A',
1,
true,
2.9,
false,
'3',
'',
null,
9,
],
],
];

View File

@ -0,0 +1,34 @@
<?php
return [
[
3,
[
// The index simulates a cell value
'0.1.A' => 'A',
'0.2.A' => 1,
'0.3.A' => true,
'0.4.A' => 2.9,
'0.5.A' => false,
'0.6.A' => '3',
'0.7.A' => '',
'0.8.A' => null,
'0.9.A' => 9,
],
],
[
3,
[
// No index indicates arguments passed as literals rather than cell values
'A',
1,
true,
2.9,
false,
'3',
'',
null,
9,
],
],
];

View File

@ -0,0 +1,36 @@
<?php
return [
[
5,
[
// The index simulates a cell value
// Numbers and Booleans are both counted
'0.1.A' => 'A',
'0.2.A' => 1,
'0.3.A' => true,
'0.4.A' => 2.9,
'0.5.A' => false,
'0.6.A' => '3',
'0.7.A' => '',
'0.8.A' => null,
'0.9.A' => 9,
],
],
[
6,
[
// No index indicates arguments passed as literals rather than cell values
// In this case, booleans are counted as well as numbers, as are numeric-value string literals
'A',
1,
true,
2.9,
false,
'3',
'',
null,
9,
],
],
];

View File

@ -0,0 +1,48 @@
<?php
return [
[
5,
5, 1,
],
[
20,
5, 2,
],
[
60,
5, 3,
],
[
120,
5, 4,
],
[
120,
5, 5,
],
[
970200,
100, 3,
],
[
6,
3, 2,
],
[
720,
6, 6,
],
[
5040,
7, 6,
],
[
151200,
10, 6,
],
[
10068347520,
49,6,
],
];