GammaTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
  5. use PHPUnit\Framework\TestCase;
  6. class GammaTest extends TestCase
  7. {
  8. /**
  9. * @dataProvider providerGAMMA
  10. *
  11. * @param mixed $expectedResult
  12. * @param mixed $testValue
  13. */
  14. public function testGAMMA($expectedResult, $testValue): void
  15. {
  16. $result = Statistical::GAMMAFunction($testValue);
  17. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  18. }
  19. public function providerGAMMA(): array
  20. {
  21. return require 'tests/data/Calculation/Statistical/GAMMA.php';
  22. }
  23. /**
  24. * @dataProvider providerGammaArray
  25. */
  26. public function testGammaArray(array $expectedResult, string $values): void
  27. {
  28. $calculation = Calculation::getInstance();
  29. $formula = "=GAMMA({$values})";
  30. $result = $calculation->_calculateFormulaValue($formula);
  31. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  32. }
  33. public function providerGammaArray(): array
  34. {
  35. return [
  36. 'matrix' => [
  37. [[2.363271800901467, 4.590843711999102], [1.2254167024651963, 17.837861981813575]],
  38. '{-1.5, 0.2; 0.75, 4.8}',
  39. ],
  40. ];
  41. }
  42. }