FactTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class FactTest extends AllSetupTeardown
  5. {
  6. const FACT_PRECISION = 1E-12;
  7. /**
  8. * @dataProvider providerFACT
  9. *
  10. * @param mixed $expectedResult
  11. * @param mixed $arg1
  12. */
  13. public function testFACT($expectedResult, $arg1): void
  14. {
  15. $this->mightHaveException($expectedResult);
  16. $sheet = $this->getSheet();
  17. if ($arg1 !== null) {
  18. $sheet->getCell('A1')->setValue($arg1);
  19. }
  20. if ($arg1 === 'omitted') {
  21. $sheet->getCell('B1')->setValue('=FACT()');
  22. } else {
  23. $sheet->getCell('B1')->setValue('=FACT(A1)');
  24. }
  25. $result = $sheet->getCell('B1')->getCalculatedValue();
  26. self::assertEquals($expectedResult, $result);
  27. }
  28. public function providerFACT(): array
  29. {
  30. return require 'tests/data/Calculation/MathTrig/FACT.php';
  31. }
  32. /**
  33. * @dataProvider providerFACTGnumeric
  34. *
  35. * @param mixed $expectedResult
  36. * @param mixed $arg1
  37. */
  38. public function testFACTGnumeric($expectedResult, $arg1): void
  39. {
  40. $this->mightHaveException($expectedResult);
  41. self::setGnumeric();
  42. $sheet = $this->getSheet();
  43. if ($arg1 !== null) {
  44. $sheet->getCell('A1')->setValue($arg1);
  45. }
  46. if ($arg1 === 'omitted') {
  47. $sheet->getCell('B1')->setValue('=FACT()');
  48. } else {
  49. $sheet->getCell('B1')->setValue('=FACT(A1)');
  50. }
  51. $result = $sheet->getCell('B1')->getCalculatedValue();
  52. self::assertEqualsWithDelta($expectedResult, $result, self::FACT_PRECISION);
  53. }
  54. public function providerFACTGnumeric(): array
  55. {
  56. return require 'tests/data/Calculation/MathTrig/FACTGNUMERIC.php';
  57. }
  58. /**
  59. * @dataProvider providerFactArray
  60. */
  61. public function testFactArray(array $expectedResult, string $array): void
  62. {
  63. $calculation = Calculation::getInstance();
  64. $formula = "=FACT({$array})";
  65. $result = $calculation->_calculateFormulaValue($formula);
  66. self::assertEqualsWithDelta($expectedResult, $result, self::FACT_PRECISION);
  67. }
  68. public function providerFactArray(): array
  69. {
  70. return [
  71. 'row vector' => [[['#NUM!', 120, 362880]], '{-2, 5, 9}'],
  72. 'column vector' => [[['#NUM!'], [120], [362880]], '{-2; 5; 9}'],
  73. 'matrix' => [[['#NUM!', 120], [362880, 6]], '{-2, 5; 9, 3.5}'],
  74. ];
  75. }
  76. }