mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-03 14:10:27 +00:00
6c1651e995
* Floating-point Equality in Two Tests Merging a change today, Git reported failures that did not occur during "normal" unit testing. The merge still succeeded, but ... The problem was an error comparing float values for equal, and the inequality occurred beyond the 14th decimal digit. Change the tests in question, which incidentally were not part of the merged changed, to use assertEqualsWithDelta. * Egad - 112 More Precision-related Problems Spread across 9 test members.
52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Shared\Trend;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\Trend\LinearBestFit;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class LinearBestFitTest extends TestCase
|
|
{
|
|
const LBF_PRECISION = 1.0E-8;
|
|
|
|
/**
|
|
* @dataProvider providerLinearBestFit
|
|
*
|
|
* @param mixed $expectedSlope
|
|
* @param mixed $expectedIntersect
|
|
* @param mixed $expectedGoodnessOfFit
|
|
* @param mixed $yValues
|
|
* @param mixed $xValues
|
|
* @param mixed $expectedEquation
|
|
*/
|
|
public function testLinearBestFit(
|
|
$expectedSlope,
|
|
$expectedIntersect,
|
|
$expectedGoodnessOfFit,
|
|
$expectedEquation,
|
|
$yValues,
|
|
$xValues
|
|
): void {
|
|
$bestFit = new LinearBestFit($yValues, $xValues);
|
|
$slope = $bestFit->getSlope(1);
|
|
self::assertEqualsWithDelta($expectedSlope[0], $slope, self::LBF_PRECISION);
|
|
$slope = $bestFit->getSlope();
|
|
self::assertEqualsWithDelta($expectedSlope[1], $slope, self::LBF_PRECISION);
|
|
$intersect = $bestFit->getIntersect(1);
|
|
self::assertEqualsWithDelta($expectedIntersect[0], $intersect, self::LBF_PRECISION);
|
|
$intersect = $bestFit->getIntersect();
|
|
self::assertEqualsWithDelta($expectedIntersect[1], $intersect, self::LBF_PRECISION);
|
|
|
|
$equation = $bestFit->getEquation(2);
|
|
self::assertEquals($expectedEquation, $equation);
|
|
|
|
self::assertSame($expectedGoodnessOfFit[0], $bestFit->getGoodnessOfFit(6));
|
|
self::assertSame($expectedGoodnessOfFit[1], $bestFit->getGoodnessOfFit());
|
|
}
|
|
|
|
public function providerLinearBestFit(): array
|
|
{
|
|
return require 'tests/data/Shared/Trend/LinearBestFit.php';
|
|
}
|
|
}
|