GammaDistTest.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 GammaDistTest extends TestCase
  8. {
  9. protected function setUp(): void
  10. {
  11. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  12. }
  13. /**
  14. * @dataProvider providerGAMMADIST
  15. *
  16. * @param mixed $expectedResult
  17. */
  18. public function testGAMMADIST($expectedResult, ...$args): void
  19. {
  20. $result = Statistical::GAMMADIST(...$args);
  21. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  22. }
  23. public function providerGAMMADIST(): array
  24. {
  25. return require 'tests/data/Calculation/Statistical/GAMMADIST.php';
  26. }
  27. /**
  28. * @dataProvider providerGammaDistArray
  29. */
  30. public function testGammaDistArray(array $expectedResult, string $values, string $alpha, string $beta): void
  31. {
  32. $calculation = Calculation::getInstance();
  33. $formula = "=GAMMA.DIST({$values}, {$alpha}, {$beta}, false)";
  34. $result = $calculation->_calculateFormulaValue($formula);
  35. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  36. }
  37. public function providerGammaDistArray(): array
  38. {
  39. return [
  40. 'row/column vectors' => [
  41. [
  42. [0.0012393760883331792, 0.007436256529999079, 0.0669263087699917],
  43. [0.012446767091965986, 0.03734030127589798, 0.04200783893538521],
  44. [0.018143590657882503, 0.043544617578918025, 0.02508169972545678],
  45. ],
  46. '12',
  47. '{1, 2, 5}',
  48. '{2; 4; 5}',
  49. ],
  50. ];
  51. }
  52. }