mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-22 16:19:19 +00:00
Merge branch 'master' into fix_excel_overwrite
This commit is contained in:
@@ -2,31 +2,26 @@
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AbsTest extends TestCase
|
||||
class AbsTest extends AllSetupTeardown
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerAbs
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
* @param mixed $val
|
||||
* @param mixed $number
|
||||
*/
|
||||
public function testRound($expectedResult, $val = null): void
|
||||
public function testRound($expectedResult, $number = 'omitted'): void
|
||||
{
|
||||
if ($val === null) {
|
||||
$this->expectException(CalcExp::class);
|
||||
$formula = '=ABS()';
|
||||
$sheet = $this->sheet;
|
||||
$this->mightHaveException($expectedResult);
|
||||
$this->setCell('A1', $number);
|
||||
if ($number === 'omitted') {
|
||||
$sheet->getCell('B1')->setValue('=ABS()');
|
||||
} else {
|
||||
$formula = "=ABS($val)";
|
||||
$sheet->getCell('B1')->setValue('=ABS(A1)');
|
||||
}
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->getCell('A1')->setValue($formula);
|
||||
$result = $sheet->getCell('A1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||
self::assertSame($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function providerAbs()
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\DataType;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -49,4 +50,18 @@ class AllSetupTeardown extends TestCase
|
||||
$this->expectException(CalcException::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
protected function setCell(string $cell, $value): void
|
||||
{
|
||||
if ($value !== null) {
|
||||
if (is_string($value) && is_numeric($value)) {
|
||||
$this->sheet->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
|
||||
} else {
|
||||
$this->sheet->getCell($cell)->setValue($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,31 +2,26 @@
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DegreesTest extends TestCase
|
||||
class DegreesTest extends AllSetupTeardown
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerDEGREES
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
* @param mixed $val
|
||||
* @param mixed $number
|
||||
*/
|
||||
public function testDEGREES($expectedResult, $val = null): void
|
||||
public function testDegrees($expectedResult, $number = 'omitted'): void
|
||||
{
|
||||
if ($val === null) {
|
||||
$this->expectException(CalcExp::class);
|
||||
$formula = '=DEGREES()';
|
||||
$sheet = $this->sheet;
|
||||
$this->mightHaveException($expectedResult);
|
||||
$this->setCell('A1', $number);
|
||||
if ($number === 'omitted') {
|
||||
$sheet->getCell('B1')->setValue('=DEGREES()');
|
||||
} else {
|
||||
$formula = "=DEGREES($val)";
|
||||
$sheet->getCell('B1')->setValue('=DEGREES(A1)');
|
||||
}
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->getCell('A1')->setValue($formula);
|
||||
$result = $sheet->getCell('A1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
|
||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
||||
}
|
||||
|
||||
public function providerDegrees()
|
||||
|
||||
@@ -2,31 +2,28 @@
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ExpTest extends TestCase
|
||||
class ExpTest extends AllSetupTeardown
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerEXP
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
* @param mixed $val
|
||||
* @param mixed $number
|
||||
*/
|
||||
public function testEXP($expectedResult, $val = null): void
|
||||
public function testEXP($expectedResult, $number = 'omitted'): void
|
||||
{
|
||||
if ($val === null) {
|
||||
$this->expectException(CalcExp::class);
|
||||
$formula = '=EXP()';
|
||||
} else {
|
||||
$formula = "=EXP($val)";
|
||||
$this->mightHaveException($expectedResult);
|
||||
$sheet = $this->sheet;
|
||||
if ($number !== null) {
|
||||
$sheet->getCell('A1')->setValue($number);
|
||||
}
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->getCell('A1')->setValue($formula);
|
||||
$result = $sheet->getCell('A1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
|
||||
if ($number === 'omitted') {
|
||||
$sheet->getCell('B1')->setValue('=EXP()');
|
||||
} else {
|
||||
$sheet->getCell('B1')->setValue('=EXP(A1)');
|
||||
}
|
||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||
}
|
||||
|
||||
public function providerEXP()
|
||||
|
||||
@@ -11,9 +11,9 @@ class MInverseTest extends AllSetupTeardown
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testMINVERSE($expectedResult, ...$args): void
|
||||
public function testMINVERSE($expectedResult, array $args): void
|
||||
{
|
||||
$result = MathTrig::MINVERSE(...$args);
|
||||
$result = MathTrig\MatrixFunctions::funcMInverse($args);
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class MMultTest extends AllSetupTeardown
|
||||
*/
|
||||
public function testMMULT($expectedResult, ...$args): void
|
||||
{
|
||||
$result = MathTrig::MMULT(...$args);
|
||||
$result = MathTrig\MatrixFunctions::funcMMult(...$args);
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ class MovedFunctionsTest extends TestCase
|
||||
{
|
||||
public function testMovedFunctions(): void
|
||||
{
|
||||
self::assertSame(1, MathTrig::builtinABS(1));
|
||||
self::assertEqualsWithDelta(0, MathTrig::builtinACOS(1), 1E-9);
|
||||
self::assertEqualsWithDelta(0, MathTrig::builtinACOSH(1), 1E-9);
|
||||
self::assertEqualsWithDelta(3.04192400109863, MathTrig::ACOT(-10), 1E-9);
|
||||
@@ -35,12 +36,15 @@ class MovedFunctionsTest extends TestCase
|
||||
self::assertEquals('#DIV/0!', MathTrig::COTH(0));
|
||||
self::assertEquals('#DIV/0!', MathTrig::CSC(0));
|
||||
self::assertEquals('#DIV/0!', MathTrig::CSCH(0));
|
||||
self::assertEquals(0, MathTrig::builtinDEGREES(0));
|
||||
self::assertEquals(6, MathTrig::EVEN(4.5));
|
||||
self::assertEquals(1, MathTrig::builtinEXP(0));
|
||||
self::assertEquals(6, MathTrig::FACT(3));
|
||||
self::assertEquals(105, MathTrig::FACTDOUBLE(7));
|
||||
self::assertEquals(-6, MathTrig::FLOOR(-4.5, 2));
|
||||
self::assertEquals(0.23, MathTrig::FLOORMATH(0.234, 0.01));
|
||||
self::assertEquals(-4, MathTrig::FLOORPRECISE(-2.5, 2));
|
||||
self::assertEquals(2, MathTrig::GCD(4, 6));
|
||||
self::assertEquals(-9, MathTrig::INT(-8.3));
|
||||
self::assertEquals(12, MathTrig::LCM(4, 6));
|
||||
self::assertEqualswithDelta(2.302585, MathTrig::builtinLN(10), 1E-6);
|
||||
@@ -58,10 +62,12 @@ class MovedFunctionsTest extends TestCase
|
||||
self::assertEquals(1, MathTrig::MOD(5, 2));
|
||||
self::assertEquals(6, MathTrig::MROUND(7.3, 3));
|
||||
self::assertEquals(1, MathTrig::MULTINOMIAL(1));
|
||||
self::assertEquals(0, MathTrig::numberOrNan(0));
|
||||
self::assertEquals(5, MathTrig::ODD(4.5));
|
||||
self::assertEquals(8, MathTrig::POWER(2, 3));
|
||||
self::assertEquals(8, MathTrig::PRODUCT(1, 2, 4));
|
||||
self::assertEquals(8, MathTrig::QUOTIENT(17, 2));
|
||||
self::assertEquals(0, MathTrig::builtinRADIANS(0));
|
||||
self::assertGreaterThanOrEqual(0, MATHTRIG::RAND());
|
||||
self::assertEquals('I', MathTrig::ROMAN(1));
|
||||
self::assertEquals(3.3, MathTrig::builtinROUND(3.27, 1));
|
||||
@@ -73,10 +79,23 @@ class MovedFunctionsTest extends TestCase
|
||||
self::assertEquals(1, MathTrig::SIGN(79.2));
|
||||
self::assertEquals(0, MathTrig::builtinSIN(0));
|
||||
self::assertEquals(0, MathTrig::builtinSINH(0));
|
||||
self::assertEquals(0, MathTrig::builtinSQRT(0));
|
||||
self::assertEqualswithDelta(3.54490770181103, MathTrig::SQRTPI(4), 1E-6);
|
||||
self::assertEquals(0, MathTrig::SUBTOTAL(2, [0, 0]));
|
||||
self::assertEquals(7, MathTrig::SUM(1, 2, 4));
|
||||
self::assertEquals(4, MathTrig::SUMIF([[2], [4]], '>2'));
|
||||
self::assertEquals(2, MathTrig::SUMIFS(
|
||||
[[1], [1], [1]],
|
||||
[['Y'], ['Y'], ['N']],
|
||||
'=Y',
|
||||
[['H'], ['H'], ['H']],
|
||||
'=H'
|
||||
));
|
||||
self::assertEquals(17, MathTrig::SUMPRODUCT([1, 2, 3], [5, 0, 4]));
|
||||
self::assertEquals(21, MathTrig::SUMSQ(1, 2, 4));
|
||||
self::assertEquals(-20, MathTrig::SUMX2MY2([1, 2], [3, 4]));
|
||||
self::assertEquals(30, MathTrig::SUMX2PY2([1, 2], [3, 4]));
|
||||
self::assertEquals(8, MathTrig::SUMXMY2([1, 2], [3, 4]));
|
||||
self::assertEquals(0, MathTrig::builtinTAN(0));
|
||||
self::assertEquals(0, MathTrig::builtinTANH(0));
|
||||
self::assertEquals(70, MathTrig::TRUNC(79.2, -1));
|
||||
|
||||
@@ -2,31 +2,26 @@
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RadiansTest extends TestCase
|
||||
class RadiansTest extends AllSetupTeardown
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerRADIANS
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
* @param mixed $val
|
||||
* @param mixed $number
|
||||
*/
|
||||
public function testRADIANS($expectedResult, $val = null): void
|
||||
public function testRADIANS($expectedResult, $number = 'omitted'): void
|
||||
{
|
||||
if ($val === null) {
|
||||
$this->expectException(CalcExp::class);
|
||||
$formula = '=RADIANS()';
|
||||
$sheet = $this->sheet;
|
||||
$this->mightHaveException($expectedResult);
|
||||
$this->setCell('A1', $number);
|
||||
if ($number === 'omitted') {
|
||||
$sheet->getCell('B1')->setValue('=RADIANS()');
|
||||
} else {
|
||||
$formula = "=RADIANS($val)";
|
||||
$sheet->getCell('B1')->setValue('=RADIANS(A1)');
|
||||
}
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->getCell('A1')->setValue($formula);
|
||||
$result = $sheet->getCell('A1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
|
||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
|
||||
}
|
||||
|
||||
public function providerRADIANS()
|
||||
|
||||
@@ -2,26 +2,27 @@
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SqrtPiTest extends TestCase
|
||||
class SqrtPiTest extends AllSetupTeardown
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSQRTPI
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
* @param mixed $value
|
||||
* @param mixed $number
|
||||
*/
|
||||
public function testSQRTPI($expectedResult, $value): void
|
||||
public function testSQRTPI($expectedResult, $number): void
|
||||
{
|
||||
$result = MathTrig::SQRTPI($value);
|
||||
$this->mightHaveException($expectedResult);
|
||||
$sheet = $this->sheet;
|
||||
if ($number !== null) {
|
||||
$sheet->getCell('A1')->setValue($number);
|
||||
}
|
||||
if ($number === 'omitted') {
|
||||
$sheet->getCell('B1')->setValue('=SQRTPI()');
|
||||
} else {
|
||||
$sheet->getCell('B1')->setValue('=SQRTPI(A1)');
|
||||
}
|
||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,30 +2,25 @@
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SqrtTest extends TestCase
|
||||
class SqrtTest extends AllSetupTeardown
|
||||
{
|
||||
/**
|
||||
* @dataProvider providerSQRT
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
* @param mixed $val
|
||||
* @param mixed $number
|
||||
*/
|
||||
public function testSQRT($expectedResult, $val = null): void
|
||||
public function testSQRT($expectedResult, $number = 'omitted'): void
|
||||
{
|
||||
if ($val === null) {
|
||||
$this->expectException(CalcExp::class);
|
||||
$formula = '=SQRT()';
|
||||
$sheet = $this->sheet;
|
||||
$this->mightHaveException($expectedResult);
|
||||
$this->setCell('A1', $number);
|
||||
if ($number === 'omitted') {
|
||||
$sheet->getCell('B1')->setValue('=SQRT()');
|
||||
} else {
|
||||
$formula = "=SQRT($val)";
|
||||
$sheet->getCell('B1')->setValue('=SQRT(A1)');
|
||||
}
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
$sheet->getCell('A1')->setValue($formula);
|
||||
$result = $sheet->getCell('A1')->getCalculatedValue();
|
||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,17 +2,10 @@
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
||||
|
||||
class SumIfsTest extends TestCase
|
||||
class SumIfsTest extends AllSetupTeardown
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSUMIFS
|
||||
*
|
||||
@@ -20,7 +13,7 @@ class SumIfsTest extends TestCase
|
||||
*/
|
||||
public function testSUMIFS($expectedResult, ...$args): void
|
||||
{
|
||||
$result = MathTrig::SUMIFS(...$args);
|
||||
$result = Statistical\Conditional::SUMIFS(...$args);
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,17 +2,8 @@
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SumSqTest extends TestCase
|
||||
class SumSqTest extends AllSetupTeardown
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSUMSQ
|
||||
*
|
||||
@@ -20,7 +11,19 @@ class SumSqTest extends TestCase
|
||||
*/
|
||||
public function testSUMSQ($expectedResult, ...$args): void
|
||||
{
|
||||
$result = MathTrig::SUMSQ(...$args);
|
||||
$this->mightHaveException($expectedResult);
|
||||
$maxRow = 0;
|
||||
$funcArg = '';
|
||||
$sheet = $this->sheet;
|
||||
foreach ($args as $arg) {
|
||||
++$maxRow;
|
||||
$funcArg = "A1:A$maxRow";
|
||||
if ($arg !== null) {
|
||||
$sheet->getCell("A$maxRow")->setValue($arg);
|
||||
}
|
||||
}
|
||||
$sheet->getCell('B1')->setValue("=SUMSQ($funcArg)");
|
||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,24 +3,34 @@
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SumX2MY2Test extends TestCase
|
||||
class SumX2MY2Test extends AllSetupTeardown
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSUMX2MY2
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testSUMX2MY2($expectedResult, ...$args): void
|
||||
public function testSUMX2MY2($expectedResult, array $matrixData1, array $matrixData2): void
|
||||
{
|
||||
$result = MathTrig::SUMX2MY2(...$args);
|
||||
$this->mightHaveException($expectedResult);
|
||||
$sheet = $this->sheet;
|
||||
$maxRow = 0;
|
||||
$funcArg1 = '';
|
||||
foreach (Functions::flattenArray($matrixData1) as $arg) {
|
||||
++$maxRow;
|
||||
$funcArg1 = "A1:A$maxRow";
|
||||
$this->setCell("A$maxRow", $arg);
|
||||
}
|
||||
$maxRow = 0;
|
||||
$funcArg2 = '';
|
||||
foreach (Functions::flattenArray($matrixData2) as $arg) {
|
||||
++$maxRow;
|
||||
$funcArg2 = "C1:C$maxRow";
|
||||
$this->setCell("C$maxRow", $arg);
|
||||
}
|
||||
$sheet->getCell('B1')->setValue("=SUMX2MY2($funcArg1, $funcArg2)");
|
||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,24 +3,34 @@
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SumX2PY2Test extends TestCase
|
||||
class SumX2PY2Test extends AllSetupTeardown
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSUMX2PY2
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testSUMX2PY2($expectedResult, ...$args): void
|
||||
public function testSUMX2PY2($expectedResult, array $matrixData1, array $matrixData2): void
|
||||
{
|
||||
$result = MathTrig::SUMX2PY2(...$args);
|
||||
$this->mightHaveException($expectedResult);
|
||||
$sheet = $this->sheet;
|
||||
$maxRow = 0;
|
||||
$funcArg1 = '';
|
||||
foreach (Functions::flattenArray($matrixData1) as $arg) {
|
||||
++$maxRow;
|
||||
$funcArg1 = "A1:A$maxRow";
|
||||
$this->setCell("A$maxRow", $arg);
|
||||
}
|
||||
$maxRow = 0;
|
||||
$funcArg2 = '';
|
||||
foreach (Functions::flattenArray($matrixData2) as $arg) {
|
||||
++$maxRow;
|
||||
$funcArg2 = "C1:C$maxRow";
|
||||
$this->setCell("C$maxRow", $arg);
|
||||
}
|
||||
$sheet->getCell('B1')->setValue("=SUMX2PY2($funcArg1, $funcArg2)");
|
||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,24 +3,34 @@
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SumXMY2Test extends TestCase
|
||||
class SumXMY2Test extends AllSetupTeardown
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSUMXMY2
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testSUMXMY2($expectedResult, ...$args): void
|
||||
public function testSUMXMY2($expectedResult, array $matrixData1, array $matrixData2): void
|
||||
{
|
||||
$result = MathTrig::SUMXMY2(...$args);
|
||||
$this->mightHaveException($expectedResult);
|
||||
$sheet = $this->sheet;
|
||||
$maxRow = 0;
|
||||
$funcArg1 = '';
|
||||
foreach (Functions::flattenArray($matrixData1) as $arg) {
|
||||
++$maxRow;
|
||||
$funcArg1 = "A1:A$maxRow";
|
||||
$this->setCell("A$maxRow", $arg);
|
||||
}
|
||||
$maxRow = 0;
|
||||
$funcArg2 = '';
|
||||
foreach (Functions::flattenArray($matrixData2) as $arg) {
|
||||
++$maxRow;
|
||||
$funcArg2 = "C1:C$maxRow";
|
||||
$this->setCell("C$maxRow", $arg);
|
||||
}
|
||||
$sheet->getCell('B1')->setValue("=SUMXMY2($funcArg1, $funcArg2)");
|
||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
['#VALUE!'], // exception - not enough args
|
||||
['#VALUE!', '"ABC"'],
|
||||
[35.51, '"35.51"'],
|
||||
['exception'], // exception - not enough args
|
||||
['#VALUE!', 'ABC'],
|
||||
[35.51, '35.51'],
|
||||
[35.51, '=35.51'],
|
||||
[35.51, '="35.51"'],
|
||||
[35.51, 35.51],
|
||||
[35.51, -35.51],
|
||||
[6, '"6"'],
|
||||
[7, '"-7"'],
|
||||
[6, '6'],
|
||||
[7, '-7'],
|
||||
[0, 0],
|
||||
[0, null],
|
||||
[0, false],
|
||||
[1, true],
|
||||
['#VALUE!', ''],
|
||||
];
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
['#VALUE!'], // exception not enough args
|
||||
['#VALUE!', '"ABC"'],
|
||||
['exception'], // exception not enough args
|
||||
['#VALUE!', 'ABC'],
|
||||
[45, M_PI / 4],
|
||||
[0, 0],
|
||||
[0, null],
|
||||
[0, false],
|
||||
['#VALUE!', ''],
|
||||
[57.29577951, true],
|
||||
];
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
['#VALUE!'], // exception not enough args
|
||||
['#VALUE!', '"ABC"'],
|
||||
[2.718282, 1],
|
||||
['exception'], // exception not enough args
|
||||
['#VALUE!', 'ABC'],
|
||||
[2.7182818284590, 1],
|
||||
[2.7182818284590, true],
|
||||
[1, false],
|
||||
[1, null],
|
||||
['#VALUE!', ''],
|
||||
];
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
['#VALUE!'], // exception not enough args
|
||||
['#VALUE!', '"ABC"'],
|
||||
['exception'], // exception not enough args
|
||||
['#VALUE!', 'ABC'],
|
||||
[M_PI / 4, 45],
|
||||
[0, 0],
|
||||
[0, null],
|
||||
[0, false],
|
||||
['#VALUE!', ''],
|
||||
['#VALUE!', '=15+""'],
|
||||
[0, '=15+"-15"'],
|
||||
[0.017453293, true],
|
||||
];
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
['#VALUE!'], // exception not enough args
|
||||
['#VALUE!', '"ABC"'],
|
||||
['exception'], // exception not enough args
|
||||
['#VALUE!', 'ABC'],
|
||||
[0, 0],
|
||||
[0, null],
|
||||
[0, false],
|
||||
['#VALUE!', ''],
|
||||
[1, true],
|
||||
[1.5, 2.25],
|
||||
[1.5, '2.25'],
|
||||
[1.5, '="2.25"'],
|
||||
[1.772454, M_PI],
|
||||
['#NUM!', -2.1],
|
||||
];
|
||||
|
||||
@@ -61,4 +61,8 @@ return [
|
||||
3.9633272976060101,
|
||||
5,
|
||||
],
|
||||
['#VALUE!', true],
|
||||
['#VALUE!', false],
|
||||
['0', null],
|
||||
['exception', 'omitted'],
|
||||
];
|
||||
|
||||
@@ -44,4 +44,13 @@ return [
|
||||
2,
|
||||
3,
|
||||
],
|
||||
[14, 1, '2', 3],
|
||||
[14, 1, '=2', 3],
|
||||
[14, 1, '="2"', 3],
|
||||
['#VALUE!', 1, 'X', 3],
|
||||
['#VALUE!', 1, '', 3],
|
||||
['#VALUE!', false, 2, 3],
|
||||
['#VALUE!', 1, 2, true],
|
||||
[5, 1, 2, null],
|
||||
[10, 1, null, 3, null],
|
||||
];
|
||||
|
||||
@@ -16,4 +16,14 @@ return [
|
||||
[[1, 2], [3, 4]],
|
||||
[[5, 6], [7, 8]],
|
||||
],
|
||||
[-20, [1, 2], [3, 4]],
|
||||
[-20, [1, '=2'], [3, 4]],
|
||||
[-8, [1, '2'], [3, 4]],
|
||||
[-8, [1, '="2"'], [3, 4]],
|
||||
[-8, [1, 'X'], [3, 4]],
|
||||
[-8, [1, false], [3, 4]],
|
||||
[-12, [1, 2], ['', 4]],
|
||||
[-12, [1, 2], [null, 4]],
|
||||
[-12, [1, 2], [true, 4]],
|
||||
['#N/A', [1, 2], [3, 4, 5]], // different dimensions
|
||||
];
|
||||
|
||||
@@ -16,4 +16,14 @@ return [
|
||||
[[1, 2], [3, 4]],
|
||||
[[5, 6], [7, 8]],
|
||||
],
|
||||
[30, [1, 2], [3, 4]],
|
||||
[30, [1, '=2'], [3, 4]],
|
||||
[10, [1, ''], [3, 4]],
|
||||
[10, [1, '2'], [3, 4]],
|
||||
[10, [1, '="2"'], [3, 4]],
|
||||
[10, [1, 'X'], [3, 4]],
|
||||
[10, [1, false], [3, 4]],
|
||||
[20, [1, 2], [null, 4]],
|
||||
[20, [1, 2], [true, 4]],
|
||||
['#N/A', [1, 2], [3, 4, 5]], // different dimensions
|
||||
];
|
||||
|
||||
@@ -16,4 +16,14 @@ return [
|
||||
[[1, 2], [3, 4]],
|
||||
[[5, 6], [7, 8]],
|
||||
],
|
||||
[8, [1, 2], [3, 4]],
|
||||
[8, [1, '=2'], [3, 4]],
|
||||
[4, [1, ''], [3, 4]],
|
||||
[4, [1, '2'], [3, 4]],
|
||||
[4, [1, '="2"'], [3, 4]],
|
||||
[4, [1, 'X'], [3, 4]],
|
||||
[4, [1, false], [3, 4]],
|
||||
[4, [1, 2], [null, 4]],
|
||||
[4, [1, 2], [true, 4]],
|
||||
['#N/A', [1, 2], [3, 4, 5]], // different dimensions
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user