Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfPreciseTest.php
T
oleibman 6c1651e995 Floating-point Equality in Two Tests (#3064)
* 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.
2022-09-14 09:05:01 -07:00

54 lines
1.5 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PHPUnit\Framework\TestCase;
class ErfPreciseTest extends TestCase
{
const ERF_PRECISION = 1E-12;
/**
* @dataProvider providerERFPRECISE
*
* @param mixed $limit
* @param mixed $expectedResult
*/
public function testERFPRECISE($expectedResult, $limit): void
{
$result = Engineering::ERFPRECISE($limit);
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
}
public function providerERFPRECISE(): array
{
return require 'tests/data/Calculation/Engineering/ERFPRECISE.php';
}
/**
* @dataProvider providerErfPreciseArray
*/
public function testErfPreciseArray(array $expectedResult, string $limit): void
{
$calculation = Calculation::getInstance();
$formula = "=ERF.PRECISE({$limit})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
}
public function providerErfPreciseArray(): array
{
return [
'row vector' => [
[
[-0.9103139782296353, -0.5204998778130465, 0.0, 0.2763263901682369, 0.999593047982555],
],
'{-1.2, -0.5, 0.0, 0.25, 2.5}',
],
];
}
}