ExpTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class ExpTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerEXP
  8. *
  9. * @param mixed $expectedResult
  10. * @param mixed $number
  11. */
  12. public function testEXP($expectedResult, $number = 'omitted'): void
  13. {
  14. $this->mightHaveException($expectedResult);
  15. $sheet = $this->getSheet();
  16. if ($number !== null) {
  17. $sheet->getCell('A1')->setValue($number);
  18. }
  19. if ($number === 'omitted') {
  20. $sheet->getCell('B1')->setValue('=EXP()');
  21. } else {
  22. $sheet->getCell('B1')->setValue('=EXP(A1)');
  23. }
  24. $result = $sheet->getCell('B1')->getCalculatedValue();
  25. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  26. }
  27. public function providerEXP(): array
  28. {
  29. return require 'tests/data/Calculation/MathTrig/EXP.php';
  30. }
  31. /**
  32. * @dataProvider providerExpArray
  33. */
  34. public function testExpArray(array $expectedResult, string $array): void
  35. {
  36. $calculation = Calculation::getInstance();
  37. $formula = "=EXP({$array})";
  38. $result = $calculation->_calculateFormulaValue($formula);
  39. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  40. }
  41. public function providerExpArray(): array
  42. {
  43. return [
  44. 'row vector' => [[[1.0, 2.718281828459045, 12.182493960703473]], '{0, 1, 2.5}'],
  45. 'column vector' => [[[1.0], [2.718281828459045], [12.182493960703473]], '{0; 1; 2.5}'],
  46. 'matrix' => [[[1.0, 2.718281828459045], [12.182493960703473, 0.0820849986239]], '{0, 1; 2.5, -2.5}'],
  47. ];
  48. }
  49. }