SinTest.php 1.5 KB

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