diff --git a/src/PhpSpreadsheet/Calculation/Statistical.php b/src/PhpSpreadsheet/Calculation/Statistical.php index 3727cc12..eeee84fe 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical.php +++ b/src/PhpSpreadsheet/Calculation/Statistical.php @@ -596,11 +596,7 @@ class Statistical } // Is it a numeric value? if ((is_numeric($arg)) && (!is_string($arg))) { - if ($returnValue === null) { - $returnValue = $arg; - } else { - $returnValue += $arg; - } + $returnValue += $arg; ++$aCount; } } @@ -643,11 +639,7 @@ class Statistical } elseif (is_string($arg)) { $arg = 0; } - if ($returnValue === null) { - $returnValue = $arg; - } else { - $returnValue += $arg; - } + $returnValue += $arg; ++$aCount; } } @@ -821,7 +813,7 @@ class Statistical * @param float $probability Probability of success on each trial * @param bool $cumulative * - * @return float + * @return float|string * * @todo Cumulative distribution function */ @@ -863,7 +855,7 @@ class Statistical * @param float $value Value for the function * @param float $degrees degrees of freedom * - * @return float + * @return float|string */ public static function CHIDIST($value, $degrees) { @@ -896,7 +888,7 @@ class Statistical * @param float $probability Probability for the function * @param float $degrees degrees of freedom * - * @return float + * @return float|string */ public static function CHIINV($probability, $degrees) { @@ -955,7 +947,7 @@ class Statistical * @param float $stdDev Standard Deviation * @param float $size * - * @return float + * @return float|string */ public static function CONFIDENCE($alpha, $stdDev, $size) { @@ -985,7 +977,7 @@ class Statistical * @param mixed $yValues array of mixed Data Series Y * @param null|mixed $xValues array of mixed Data Series X * - * @return float + * @return float|string */ public static function CORREL($yValues, $xValues = null) { @@ -1513,7 +1505,7 @@ class Statistical * @param mixed $yValues array of mixed Data Series Y * @param mixed $xValues of mixed Data Series X * - * @return float + * @return bool|float|string */ public static function FORECAST($xValue, $yValues, $xValues) { @@ -1692,7 +1684,7 @@ class Statistical /** * GROWTH. * - * Returns values along a predicted emponential Trend + * Returns values along a predicted exponential Trend * * @param mixed[] $yValues Data Series Y * @param mixed[] $xValues Data Series X diff --git a/tests/PhpSpreadsheetTests/Calculation/StatisticalTest.php b/tests/PhpSpreadsheetTests/Calculation/StatisticalTest.php index 92fa9b78..97238913 100644 --- a/tests/PhpSpreadsheetTests/Calculation/StatisticalTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/StatisticalTest.php @@ -109,6 +109,86 @@ class StatisticalTest extends TestCase 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 * @@ -141,6 +221,38 @@ class StatisticalTest extends TestCase 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 providerMAXIFS * diff --git a/tests/data/Calculation/Statistical/AVERAGEIF.php b/tests/data/Calculation/Statistical/AVERAGEIF.php index 94b860ff..bd976471 100644 --- a/tests/data/Calculation/Statistical/AVERAGEIF.php +++ b/tests/data/Calculation/Statistical/AVERAGEIF.php @@ -45,4 +45,9 @@ return [ [2012, 2012, 2013, 2011, 2011, 2010], "<2013", ], + [ + 14000, + [7000, 14000, 'Hello World', 21000, 28000], + "<23000", + ], ]; diff --git a/tests/data/Calculation/Statistical/BETADIST.php b/tests/data/Calculation/Statistical/BETADIST.php index 7e32ba57..5e965736 100644 --- a/tests/data/Calculation/Statistical/BETADIST.php +++ b/tests/data/Calculation/Statistical/BETADIST.php @@ -9,4 +9,8 @@ return [ 0.598190307617, 7.5, 8, 9, 5, 10, ], + [ + 0.685470581054, + 2, 8, 10, 1, 3, + ], ]; diff --git a/tests/data/Calculation/Statistical/BETAINV.php b/tests/data/Calculation/Statistical/BETAINV.php index ffd5f31e..7d0657be 100644 --- a/tests/data/Calculation/Statistical/BETAINV.php +++ b/tests/data/Calculation/Statistical/BETAINV.php @@ -9,4 +9,8 @@ return [ 7.761240188783, 0.75, 8, 9, 5, 10, ], + [ + 2.0, + 0.685470581055, 8, 10, 1, 3, + ], ]; diff --git a/tests/data/Calculation/Statistical/BINOMDIST.php b/tests/data/Calculation/Statistical/BINOMDIST.php new file mode 100644 index 00000000..40770781 --- /dev/null +++ b/tests/data/Calculation/Statistical/BINOMDIST.php @@ -0,0 +1,20 @@ +