BinomDistRangeTest.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 BinomDistRangeTest extends TestCase
  8. {
  9. protected function setUp(): void
  10. {
  11. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  12. }
  13. /**
  14. * @dataProvider providerBINOMDISTRANGE
  15. *
  16. * @param mixed $expectedResult
  17. */
  18. public function testBINOMDISTRANGE($expectedResult, ...$args): void
  19. {
  20. $result = Statistical\Distributions\Binomial::range(...$args);
  21. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  22. }
  23. public function providerBINOMDISTRANGE(): array
  24. {
  25. return require 'tests/data/Calculation/Statistical/BINOMDISTRANGE.php';
  26. }
  27. /**
  28. * @dataProvider providerBinomDistRangeArray
  29. */
  30. public function testBinomDistRangeArray(
  31. array $expectedResult,
  32. string $trials,
  33. string $probabilities,
  34. string $successes
  35. ): void {
  36. $calculation = Calculation::getInstance();
  37. $formula = "=BINOM.DIST.RANGE({$trials}, {$probabilities}, {$successes})";
  38. $result = $calculation->_calculateFormulaValue($formula);
  39. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  40. }
  41. public function providerBinomDistRangeArray(): array
  42. {
  43. return [
  44. 'row/column vectors' => [
  45. [[0.17303466796875, 0.01153564453125], [0.258103609085083, 0.1032414436340332]],
  46. '{7; 12}',
  47. '0.25',
  48. '{3, 5}',
  49. ],
  50. ];
  51. }
  52. }