Atan2Test.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class Atan2Test extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerATAN2
  8. *
  9. * @param mixed $expectedResult
  10. */
  11. public function testATAN2($expectedResult, string $formula): void
  12. {
  13. $this->mightHaveException($expectedResult);
  14. $sheet = $this->getSheet();
  15. $sheet->getCell('A2')->setValue(5);
  16. $sheet->getCell('A3')->setValue(6);
  17. $sheet->getCell('A1')->setValue("=ATAN2($formula)");
  18. $result = $sheet->getCell('A1')->getCalculatedValue();
  19. self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
  20. }
  21. public function providerATAN2(): array
  22. {
  23. return require 'tests/data/Calculation/MathTrig/ATAN2.php';
  24. }
  25. /**
  26. * @dataProvider providerAtan2Array
  27. */
  28. public function testAtan2Array(array $expectedResult, string $argument1, string $argument2): void
  29. {
  30. $calculation = Calculation::getInstance();
  31. $formula = "=ATAN2({$argument1},{$argument2})";
  32. $result = $calculation->_calculateFormulaValue($formula);
  33. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  34. }
  35. public function providerAtan2Array(): array
  36. {
  37. return [
  38. 'first argument row vector' => [
  39. [[1.81577498992176, 1.17600520709514]],
  40. '{-0.75, 1.25}',
  41. '3',
  42. ],
  43. 'first argument column vector' => [
  44. [[1.17600520709514], [0.98279372324733]],
  45. '{1.25; 2}',
  46. '3',
  47. ],
  48. 'first argument matrix' => [
  49. [[2.03444393579570, 1.48765509490646], [1.57079632679490, 1.24904577239825]],
  50. '{-1.5, 0.25; 0, 1}',
  51. '3',
  52. ],
  53. 'second argument row vector' => [
  54. [[-0.24497866312686, 0.39479111969976]],
  55. '3',
  56. '{-0.75, 1.25}',
  57. ],
  58. 'second argument column vector' => [
  59. [[0.39479111969976], [0.58800260354757]],
  60. '3',
  61. '{1.25; 2}',
  62. ],
  63. 'second argument matrix' => [
  64. [[-0.46364760900081, 0.08314123188844], [0.0, 0.32175055439664]],
  65. '3',
  66. '{-1.5, 0.25; 0, 1}',
  67. ],
  68. 'A row and a column vector' => [
  69. [
  70. [-2.21429743558818, 2.81984209919315, 2.55359005004223, 1.92956699706547],
  71. [-1.69515132134166, 2.03444393579570, 1.81577498992176, 1.63321513679085],
  72. [-1.01219701145133, 0.38050637711237, 0.67474094222355, 1.26791145841993],
  73. [-0.51914611424652, 0.14189705460416, 0.27829965900511, 0.85196632717327],
  74. ],
  75. '{-1.5; -0.25; 1.25; 3.5}',
  76. '{-2, 0.5, 1, 4}',
  77. ],
  78. 'Two row vectors' => [
  79. [[-2.21429743558818, 2.03444393579570, 0.67474094222355, 0.85196632717327]],
  80. '{-1.5, -0.25, 1.25, 3.5}',
  81. '{-2, 0.5, 1, 4}',
  82. ],
  83. 'Two column vectors' => [
  84. [[-2.21429743558818], [2.03444393579570], [0.67474094222355], [0.85196632717327]],
  85. '{-1.5; -0.25; 1.25; 3.5}',
  86. '{-2; 0.5; 1; 4}',
  87. ],
  88. ];
  89. }
  90. }