HypGeomDistTest.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\Statistical;
  5. use PHPUnit\Framework\TestCase;
  6. class HypGeomDistTest extends TestCase
  7. {
  8. /**
  9. * @dataProvider providerHYPGEOMDIST
  10. *
  11. * @param mixed $expectedResult
  12. */
  13. public function testHYPGEOMDIST($expectedResult, ...$args): void
  14. {
  15. $result = Statistical::HYPGEOMDIST(...$args);
  16. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  17. }
  18. public function providerHYPGEOMDIST(): array
  19. {
  20. return require 'tests/data/Calculation/Statistical/HYPGEOMDIST.php';
  21. }
  22. /**
  23. * @dataProvider providerHypGeomDistArray
  24. */
  25. public function testHypGeomDistArray(
  26. array $expectedResult,
  27. string $sampleSuccesses,
  28. string $sampleNumber,
  29. string $populationSuccesses,
  30. string $populationNumber
  31. ): void {
  32. $calculation = Calculation::getInstance();
  33. $formula = "=HYPGEOMDIST({$sampleSuccesses}, {$sampleNumber}, {$populationSuccesses}, {$populationNumber})";
  34. $result = $calculation->_calculateFormulaValue($formula);
  35. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  36. }
  37. public function providerHypGeomDistArray(): array
  38. {
  39. return [
  40. 'row/column vectors' => [
  41. [
  42. [0.03230668326324188, 0.11602444697599835, 2.7420710766783583E-5],
  43. [0.00015615400269340616, 0.1000501002971324, 0.02508542192762165],
  44. [7.763976978296478E-9, 0.0013573140575961775, 0.17007598410538344],
  45. ],
  46. '{5, 11, 18}',
  47. '32',
  48. '{28; 42; 57}',
  49. '100',
  50. ],
  51. ];
  52. }
  53. }