SecTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class SecTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerSEC
  8. *
  9. * @param mixed $expectedResult
  10. * @param mixed $angle
  11. */
  12. public function testSEC($expectedResult, $angle): void
  13. {
  14. $this->mightHaveException($expectedResult);
  15. $sheet = $this->getSheet();
  16. $sheet->setCellValue('A2', 1.3);
  17. $sheet->setCellValue('A3', 2.7);
  18. $sheet->setCellValue('A4', -3.8);
  19. $sheet->setCellValue('A5', -5.2);
  20. $sheet->getCell('A1')->setValue("=SEC($angle)");
  21. $result = $sheet->getCell('A1')->getCalculatedValue();
  22. self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
  23. }
  24. public function providerSEC(): array
  25. {
  26. return require 'tests/data/Calculation/MathTrig/SEC.php';
  27. }
  28. /**
  29. * @dataProvider providerSecArray
  30. */
  31. public function testSecArray(array $expectedResult, string $array): void
  32. {
  33. $calculation = Calculation::getInstance();
  34. $formula = "=SEC({$array})";
  35. $result = $calculation->_calculateFormulaValue($formula);
  36. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  37. }
  38. public function providerSecArray(): array
  39. {
  40. return [
  41. 'row vector' => [[[1.85081571768093, 1.13949392732455, 1.85081571768093]], '{1, 0.5, -1}'],
  42. 'column vector' => [[[1.85081571768093], [1.13949392732455], [1.85081571768093]], '{1; 0.5; -1}'],
  43. 'matrix' => [[[1.85081571768093, 1.13949392732455], [1.0, 1.85081571768093]], '{1, 0.5; 0, -1}'],
  44. ];
  45. }
  46. }