LogTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class LogTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerLOG
  8. *
  9. * @param mixed $expectedResult
  10. * @param mixed $number
  11. * @param mixed $base
  12. */
  13. public function testLOG($expectedResult, $number = 'omitted', $base = 'omitted'): void
  14. {
  15. $this->mightHaveException($expectedResult);
  16. $sheet = $this->getSheet();
  17. if ($number !== null) {
  18. $sheet->getCell('A1')->setValue($number);
  19. }
  20. if ($base !== null) {
  21. $sheet->getCell('A2')->setValue($base);
  22. }
  23. if ($number === 'omitted') {
  24. $sheet->getCell('B1')->setValue('=LOG()');
  25. } elseif ($base === 'omitted') {
  26. $sheet->getCell('B1')->setValue('=LOG(A1)');
  27. } else {
  28. $sheet->getCell('B1')->setValue('=LOG(A1,A2)');
  29. }
  30. $result = $sheet->getCell('B1')->getCalculatedValue();
  31. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  32. }
  33. public function providerLOG(): array
  34. {
  35. return require 'tests/data/Calculation/MathTrig/LOG.php';
  36. }
  37. /**
  38. * @dataProvider providerLogArray
  39. */
  40. public function testLogArray(array $expectedResult, string $argument1, string $argument2): void
  41. {
  42. $calculation = Calculation::getInstance();
  43. $formula = "=LOG({$argument1}, {$argument2})";
  44. $result = $calculation->_calculateFormulaValue($formula);
  45. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  46. }
  47. public function providerLogArray(): array
  48. {
  49. return [
  50. 'matrix' => [
  51. [
  52. [-0.90308998699194, 0.3701428470511, 0.0, 1.09691001300806],
  53. [-2.07944154167984, 0.85228540189824, 0.0, 2.525728644308256],
  54. ],
  55. '{0.125, 2.345, 1.0, 12.5}',
  56. '{10; 2.718281828459045}',
  57. ],
  58. ];
  59. }
  60. }