ErfTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
  5. use PHPUnit\Framework\TestCase;
  6. class ErfTest extends TestCase
  7. {
  8. const ERF_PRECISION = 1E-12;
  9. /**
  10. * @dataProvider providerERF
  11. *
  12. * @param mixed $lower
  13. * @param null|mixed $upper
  14. * @param mixed $expectedResult
  15. */
  16. public function testERF($expectedResult, $lower, $upper = null): void
  17. {
  18. $result = Engineering::ERF($lower, $upper);
  19. self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
  20. }
  21. public function providerERF(): array
  22. {
  23. return require 'tests/data/Calculation/Engineering/ERF.php';
  24. }
  25. /**
  26. * @dataProvider providerErfArray
  27. */
  28. public function testErfArray(array $expectedResult, string $lower, string $upper = 'NULL'): void
  29. {
  30. $calculation = Calculation::getInstance();
  31. $formula = "=ERF({$lower}, {$upper})";
  32. $result = $calculation->_calculateFormulaValue($formula);
  33. self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
  34. }
  35. public function providerErfArray(): array
  36. {
  37. return [
  38. 'row vector' => [
  39. [
  40. [-0.9103139782296353, -0.5204998778130465, 0.0, 0.2763263901682369, 0.999593047982555],
  41. ],
  42. '{-1.2, -0.5, 0.0, 0.25, 2.5}',
  43. ],
  44. ];
  45. }
  46. }