NegBinomDistTest.php 1.7 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 NegBinomDistTest extends TestCase
  8. {
  9. protected function setUp(): void
  10. {
  11. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  12. }
  13. /**
  14. * @dataProvider providerNEGBINOMDIST
  15. *
  16. * @param mixed $expectedResult
  17. */
  18. public function testNEGBINOMDIST($expectedResult, ...$args): void
  19. {
  20. $result = Statistical::NEGBINOMDIST(...$args);
  21. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  22. }
  23. public function providerNEGBINOMDIST(): array
  24. {
  25. return require 'tests/data/Calculation/Statistical/NEGBINOMDIST.php';
  26. }
  27. /**
  28. * @dataProvider providerNegBinomDistArray
  29. */
  30. public function testNegBinomDistArray(
  31. array $expectedResult,
  32. string $failures,
  33. string $successes,
  34. string $probabilities
  35. ): void {
  36. $calculation = Calculation::getInstance();
  37. $formula = "=NEGBINOMDIST({$failures}, {$successes}, {$probabilities})";
  38. $result = $calculation->_calculateFormulaValue($formula);
  39. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  40. }
  41. public function providerNegBinomDistArray(): array
  42. {
  43. return [
  44. 'row/column vectors' => [
  45. [[0.07508468627929688, 0.04301726818084717], [0.04503981303423643, 0.05629976629279554]],
  46. '{7; 12}',
  47. '{3, 5}',
  48. '0.25',
  49. ],
  50. ];
  51. }
  52. }