TanhTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class TanhTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerTanh
  8. *
  9. * @param mixed $expectedResult
  10. */
  11. public function testTanh($expectedResult, string $formula): void
  12. {
  13. $this->mightHaveException($expectedResult);
  14. $sheet = $this->getSheet();
  15. $sheet->setCellValue('A2', 1);
  16. $sheet->getCell('A1')->setValue("=TANH($formula)");
  17. $result = $sheet->getCell('A1')->getCalculatedValue();
  18. self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
  19. }
  20. public function providerTanh(): array
  21. {
  22. return require 'tests/data/Calculation/MathTrig/TANH.php';
  23. }
  24. /**
  25. * @dataProvider providerTanhArray
  26. */
  27. public function testTanhArray(array $expectedResult, string $array): void
  28. {
  29. $calculation = Calculation::getInstance();
  30. $formula = "=TANH({$array})";
  31. $result = $calculation->_calculateFormulaValue($formula);
  32. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  33. }
  34. public function providerTanhArray(): array
  35. {
  36. return [
  37. 'row vector' => [[[0.76159415595577, 0.46211715726001, -0.76159415595577]], '{1, 0.5, -1}'],
  38. 'column vector' => [[[0.76159415595577], [0.46211715726001], [-0.76159415595577]], '{1; 0.5; -1}'],
  39. 'matrix' => [[[0.76159415595577, 0.46211715726001], [0.0, -0.76159415595577]], '{1, 0.5; 0, -1}'],
  40. ];
  41. }
  42. }