AcosTest.php 1.5 KB

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