AtanTest.php 1.6 KB

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