From a367f35438cef83f18d14f97061606b8cf37e850 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 16 Jul 2019 23:51:48 +0200 Subject: [PATCH] Trend function unit tests (#1089) * Merge branch 'master' of C:\Projects\PHPOffice\PHPSpreadsheet\develop with conflicts. * More trend function unit tests * Yet more trend function unit tests --- .../Calculation/StatisticalTest.php | 64 +++++++++++++++++ .../data/Calculation/Statistical/FORECAST.php | 6 ++ .../Calculation/Statistical/INTERCEPT.php | 29 ++++++++ tests/data/Calculation/Statistical/RSQ.php | 14 ++++ tests/data/Calculation/Statistical/SLOPE.php | 68 +++++++++++++++++++ tests/data/Calculation/Statistical/STEYX.php | 14 ++++ 6 files changed, 195 insertions(+) create mode 100644 tests/data/Calculation/Statistical/INTERCEPT.php create mode 100644 tests/data/Calculation/Statistical/RSQ.php create mode 100644 tests/data/Calculation/Statistical/SLOPE.php create mode 100644 tests/data/Calculation/Statistical/STEYX.php diff --git a/tests/PhpSpreadsheetTests/Calculation/StatisticalTest.php b/tests/PhpSpreadsheetTests/Calculation/StatisticalTest.php index 97238913..92b52116 100644 --- a/tests/PhpSpreadsheetTests/Calculation/StatisticalTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/StatisticalTest.php @@ -253,6 +253,22 @@ class StatisticalTest extends TestCase 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 * @@ -284,4 +300,52 @@ class StatisticalTest extends TestCase { 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'; + } } diff --git a/tests/data/Calculation/Statistical/FORECAST.php b/tests/data/Calculation/Statistical/FORECAST.php index c6abbb65..77d2ab8f 100644 --- a/tests/data/Calculation/Statistical/FORECAST.php +++ b/tests/data/Calculation/Statistical/FORECAST.php @@ -37,4 +37,10 @@ return [ [-1, -2, -3, -4], [10, 20, 30, 40], ], + [ + 32.666666666667, + 7, + [3, 7, 15, 20, 22, 27], + [1, 2, 3, 4, 5, 6], + ], ]; diff --git a/tests/data/Calculation/Statistical/INTERCEPT.php b/tests/data/Calculation/Statistical/INTERCEPT.php new file mode 100644 index 00000000..f68fdd98 --- /dev/null +++ b/tests/data/Calculation/Statistical/INTERCEPT.php @@ -0,0 +1,29 @@ +