Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php
Mark Baker 291ea88a6c Initial work enabling Excel function implementations for handling arrays as arguments when used in "array formulae". (#2562)
* Initial work enabling Excel function implementations for handling arrays as aguments when used in "array formulae".

So far:
 - handling for single argument functions
 - for functions where only one of the arguments is an array (a matrix or a row/column vector)
 - for when there are two array arguments, and one is a row vector, the other a column vector
 - for when there are either 2 row vectors, or 2 column vectors
 - for a matrix and either a row or column vector 

Will work ok, as long as there are no more than two array arguments; still need to identify the logic to apply when there are more than two arrays; or there are two that aren't an already supported row vector/column vector pairing (ie two matrices).

* Throw an exception if we have three or more array arguments (after flattening) passed to a supported function until we can identify the abstruse non-euclidian logic behind how Excel handles building, using and presenting those n-dimensional result arrays

* Implement array arguments for the DATE() function so that we can verify that paired arrays/vectors work with functions that support more than 2 arguments

* Implement array arguments for the many of the Math/Trig functions

* Update change log
2022-02-09 15:12:54 +01:00

98 lines
3.4 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class Atan2Test extends AllSetupTeardown
{
/**
* @dataProvider providerATAN2
*
* @param mixed $expectedResult
*/
public function testATAN2($expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(5);
$sheet->getCell('A3')->setValue(6);
$sheet->getCell('A1')->setValue("=ATAN2($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public function providerATAN2(): array
{
return require 'tests/data/Calculation/MathTrig/ATAN2.php';
}
/**
* @dataProvider providerAtan2Array
*/
public function testAtan2Array(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=ATAN2({$argument1},{$argument2})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public function providerAtan2Array(): array
{
return [
'first argument row vector' => [
[[1.81577498992176, 1.17600520709514]],
'{-0.75, 1.25}',
'3',
],
'first argument column vector' => [
[[1.17600520709514], [0.98279372324733]],
'{1.25; 2}',
'3',
],
'first argument matrix' => [
[[2.03444393579570, 1.48765509490646], [1.57079632679490, 1.24904577239825]],
'{-1.5, 0.25; 0, 1}',
'3',
],
'second argument row vector' => [
[[-0.24497866312686, 0.39479111969976]],
'3',
'{-0.75, 1.25}',
],
'second argument column vector' => [
[[0.39479111969976], [0.58800260354757]],
'3',
'{1.25; 2}',
],
'second argument matrix' => [
[[-0.46364760900081, 0.08314123188844], [0.0, 0.32175055439664]],
'3',
'{-1.5, 0.25; 0, 1}',
],
'A row and a column vector' => [
[
[-2.21429743558818, 2.81984209919315, 2.55359005004223, 1.92956699706547],
[-1.69515132134166, 2.03444393579570, 1.81577498992176, 1.63321513679085],
[-1.01219701145133, 0.38050637711237, 0.67474094222355, 1.26791145841993],
[-0.51914611424652, 0.14189705460416, 0.27829965900511, 0.85196632717327],
],
'{-1.5; -0.25; 1.25; 3.5}',
'{-2, 0.5, 1, 4}',
],
'Two row vectors' => [
[[-2.21429743558818, 2.03444393579570, 0.67474094222355, 0.85196632717327]],
'{-1.5, -0.25, 1.25, 3.5}',
'{-2, 0.5, 1, 4}',
],
'Two column vectors' => [
[[-2.21429743558818], [2.03444393579570], [0.67474094222355], [0.85196632717327]],
'{-1.5; -0.25; 1.25; 3.5}',
'{-2; 0.5; 1; 4}',
],
];
}
}