GammaInvTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  5. use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
  6. use PHPUnit\Framework\TestCase;
  7. class GammaInvTest extends TestCase
  8. {
  9. protected function setUp(): void
  10. {
  11. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  12. }
  13. /**
  14. * @dataProvider providerGAMMAINV
  15. *
  16. * @param mixed $expectedResult
  17. */
  18. public function testGAMMAINV($expectedResult, ...$args): void
  19. {
  20. $result = Statistical::GAMMAINV(...$args);
  21. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  22. }
  23. public function providerGAMMAINV(): array
  24. {
  25. return require 'tests/data/Calculation/Statistical/GAMMAINV.php';
  26. }
  27. /**
  28. * @dataProvider providerGammaInvArray
  29. */
  30. public function testGammaInvArray(array $expectedResult, string $values, string $alpha, string $beta): void
  31. {
  32. $calculation = Calculation::getInstance();
  33. $formula = "=GAMMA.INV({$values}, {$alpha}, {$beta})";
  34. $result = $calculation->_calculateFormulaValue($formula);
  35. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  36. }
  37. public function providerGammaInvArray(): array
  38. {
  39. return [
  40. 'row/column vectors' => [
  41. [
  42. [2.772588722239782, 5.38526905777939, 12.548861396889375],
  43. [5.545177444479563, 10.77053811555878, 25.09772279377875],
  44. [6.931471805599453, 13.463172644448473, 31.372153492223436],
  45. ],
  46. '0.75',
  47. '{1, 2, 5}',
  48. '{2; 4; 5}',
  49. ],
  50. ];
  51. }
  52. }