PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/MathTrigTest.php

898 lines
23 KiB
PHP
Raw Normal View History

2012-07-31 20:56:11 +00:00
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
2012-07-31 20:56:11 +00:00
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
2018-05-07 02:53:55 +00:00
use PhpOffice\PhpSpreadsheet\Worksheet\ColumnDimension;
use PhpOffice\PhpSpreadsheet\Worksheet\RowDimension;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\TestCase;
class MathTrigTest extends TestCase
2012-07-31 20:56:11 +00:00
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerATAN2
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testATAN2($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::ATAN2(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerATAN2()
{
return require 'data/Calculation/MathTrig/ATAN2.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerCEILING
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testCEILING($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::CEILING(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerCEILING()
{
return require 'data/Calculation/MathTrig/CEILING.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerCOMBIN
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testCOMBIN($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::COMBIN(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerCOMBIN()
{
return require 'data/Calculation/MathTrig/COMBIN.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerEVEN
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testEVEN($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::EVEN(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerEVEN()
{
return require 'data/Calculation/MathTrig/EVEN.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerODD
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testODD($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::ODD(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerODD()
{
return require 'data/Calculation/MathTrig/ODD.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerFACT
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testFACT($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::FACT(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerFACT()
{
return require 'data/Calculation/MathTrig/FACT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerFACTDOUBLE
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testFACTDOUBLE($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::FACTDOUBLE(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerFACTDOUBLE()
{
return require 'data/Calculation/MathTrig/FACTDOUBLE.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerFLOOR
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testFLOOR($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::FLOOR(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerFLOOR()
{
return require 'data/Calculation/MathTrig/FLOOR.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerGCD
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testGCD($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::GCD(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerGCD()
{
return require 'data/Calculation/MathTrig/GCD.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerLCM
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testLCM($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::LCM(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerLCM()
{
return require 'data/Calculation/MathTrig/LCM.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerINT
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testINT($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::INT(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerINT()
{
return require 'data/Calculation/MathTrig/INT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerSIGN
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testSIGN($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::SIGN(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerSIGN()
{
return require 'data/Calculation/MathTrig/SIGN.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerPOWER
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testPOWER($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::POWER(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerPOWER()
{
return require 'data/Calculation/MathTrig/POWER.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerLOG
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testLOG($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::logBase(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerLOG()
{
return require 'data/Calculation/MathTrig/LOG.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMOD
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMOD($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::MOD(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMOD()
{
return require 'data/Calculation/MathTrig/MOD.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMDETERM
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMDETERM($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::MDETERM(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMDETERM()
{
return require 'data/Calculation/MathTrig/MDETERM.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMINVERSE
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMINVERSE($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$this->markTestIncomplete('TODO: This test should be fixed');
$result = MathTrig::MINVERSE(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMINVERSE()
{
return require 'data/Calculation/MathTrig/MINVERSE.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMMULT
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMMULT($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$this->markTestIncomplete('TODO: This test should be fixed');
$result = MathTrig::MMULT(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMMULT()
{
return require 'data/Calculation/MathTrig/MMULT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMULTINOMIAL
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMULTINOMIAL($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::MULTINOMIAL(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMULTINOMIAL()
{
return require 'data/Calculation/MathTrig/MULTINOMIAL.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMROUND
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMROUND($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE);
$result = MathTrig::MROUND(...$args);
Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMROUND()
{
return require 'data/Calculation/MathTrig/MROUND.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerPRODUCT
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testPRODUCT($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::PRODUCT(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerPRODUCT()
{
return require 'data/Calculation/MathTrig/PRODUCT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerQUOTIENT
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testQUOTIENT($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::QUOTIENT(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerQUOTIENT()
{
return require 'data/Calculation/MathTrig/QUOTIENT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerROUNDUP
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testROUNDUP($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::ROUNDUP(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerROUNDUP()
{
return require 'data/Calculation/MathTrig/ROUNDUP.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerROUNDDOWN
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testROUNDDOWN($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::ROUNDDOWN(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerROUNDDOWN()
{
return require 'data/Calculation/MathTrig/ROUNDDOWN.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerSERIESSUM
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testSERIESSUM($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::SERIESSUM(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerSERIESSUM()
{
return require 'data/Calculation/MathTrig/SERIESSUM.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerSUMSQ
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testSUMSQ($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::SUMSQ(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerSUMSQ()
{
return require 'data/Calculation/MathTrig/SUMSQ.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
Add further new Functions introduced in MS Excel 2013 and 2016 (#608) - Fix ISFORMULA() function to work with a cell reference to another worksheet - Added calculation engine support for the new functions that were added in MS Excel 2013 and MS Excel 2016 - Text Functions - CONCAT() Synonym for CONCATENATE() - NUMBERVALUE() Converts text to a number, in a locale-independent way - UNICHAR() Synonym for CHAR() in PHPSpreadsheet, which has always used UTF-8 internally - UNIORD() Synonym for ORD() in PHPSpreadsheet, which has always used UTF-8 internally - TEXTJOIN() Joins together two or more text strings, separated by a delimiter - Logical Functions - XOR() Returns a logical Exclusive Or of all arguments - Date/Time Functions - ISOWEEKNUM() Returns the ISO 8601 week number of the year for a given date - Lookup and Reference Functions - FORMULATEXT() Returns a formula as a string - Engineering Functions - ERF.PRECISE() Returns the error function integrated between 0 and a supplied limit - ERFC.PRECISE() Synonym for ERFC - Math and Trig Functions - SEC() Returns the secant of an angle - SECH() Returns the hyperbolic secant of an angle - CSC() Returns the cosecant of an angle - CSCH() Returns the hyperbolic cosecant of an angle - COT() Returns the cotangent of an angle - COTH() Returns the hyperbolic cotangent of an angle - ACOT() Returns the cotangent of an angle - ACOTH() Returns the hyperbolic cotangent of an angle - Financial Functions - PDURATION() Calculates the number of periods required for an investment to reach a specified value - RRI() Calculates the interest rate required for an investment to grow to a specified future value
2018-07-22 18:17:04 +00:00
/**
* @dataProvider providerSUMPRODUCT
*
* @param mixed $expectedResult
*/
public function testSUMPRODUCT($expectedResult, ...$args)
{
$result = MathTrig::SUMPRODUCT(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerSUMPRODUCT()
{
return require 'data/Calculation/MathTrig/SUMPRODUCT.php';
}
/**
* @dataProvider providerSUMX2MY2
*
* @param mixed $expectedResult
*/
public function testSUMX2MY2($expectedResult, ...$args)
{
$result = MathTrig::SUMX2MY2(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerSUMX2MY2()
{
return require 'data/Calculation/MathTrig/SUMX2MY2.php';
}
/**
* @dataProvider providerSUMX2PY2
*
* @param mixed $expectedResult
*/
public function testSUMX2PY2($expectedResult, ...$args)
{
$result = MathTrig::SUMX2PY2(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerSUMX2PY2()
{
return require 'data/Calculation/MathTrig/SUMX2PY2.php';
}
/**
* @dataProvider providerSUMXMY2
*
* @param mixed $expectedResult
*/
public function testSUMXMY2($expectedResult, ...$args)
{
$result = MathTrig::SUMXMY2(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerSUMXMY2()
{
return require 'data/Calculation/MathTrig/SUMXMY2.php';
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerTRUNC
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testTRUNC($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::TRUNC(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerTRUNC()
{
return require 'data/Calculation/MathTrig/TRUNC.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerROMAN
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testROMAN($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::ROMAN(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerROMAN()
{
return require 'data/Calculation/MathTrig/ROMAN.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerSQRTPI
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testSQRTPI($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::SQRTPI(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerSQRTPI()
{
return require 'data/Calculation/MathTrig/SQRTPI.php';
}
/**
* @dataProvider providerSUMIF
*
* @param mixed $expectedResult
*/
public function testSUMIF($expectedResult, ...$args)
{
$result = MathTrig::SUMIF(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerSUMIF()
{
return require 'data/Calculation/MathTrig/SUMIF.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerSUMIFS
*
* @param mixed $expectedResult
*/
public function testSUMIFS($expectedResult, ...$args)
{
$result = MathTrig::SUMIFS(...$args);
self::assertEquals($expectedResult, $result, '', 1E-12);
}
public function providerSUMIFS()
{
return require 'data/Calculation/MathTrig/SUMIFS.php';
}
/**
* @dataProvider providerSUBTOTAL
*
* @param mixed $expectedResult
*/
public function testSUBTOTAL($expectedResult, ...$args)
{
$cell = $this->getMockBuilder(Cell::class)
->setMethods(['getValue'])
->disableOriginalConstructor()
->getMock();
$cell->method('getValue')
->willReturn(null);
$worksheet = $this->getMockBuilder(Worksheet::class)
->setMethods(['cellExists', 'getCell'])
->disableOriginalConstructor()
->getMock();
$worksheet->method('cellExists')
->willReturn(true);
$worksheet->method('getCell')
->willReturn($cell);
$cellReference = $this->getMockBuilder(Cell::class)
->setMethods(['getWorksheet'])
->disableOriginalConstructor()
->getMock();
$cellReference->method('getWorksheet')
->willReturn($worksheet);
array_push($args, $cellReference);
$result = MathTrig::SUBTOTAL(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerSUBTOTAL()
{
return require 'data/Calculation/MathTrig/SUBTOTAL.php';
}
2018-05-07 02:53:55 +00:00
protected function rowVisibility()
{
$data = [1 => false, 2 => true, 3 => false, 4 => true, 5 => false, 6 => false, 7 => false, 8 => true, 9 => false, 10 => true, 11 => true];
foreach ($data as $k => $v) {
yield $k => $v;
}
}
/**
* @dataProvider providerHiddenSUBTOTAL
*
* @param mixed $expectedResult
*/
public function testHiddenSUBTOTAL($expectedResult, ...$args)
{
2018-04-21 19:34:25 +00:00
$visibilityGenerator = $this->rowVisibility();
$rowDimension = $this->getMockBuilder(RowDimension::class)
->setMethods(['getVisible'])
->disableOriginalConstructor()
->getMock();
$rowDimension->method('getVisible')
2018-05-07 02:53:55 +00:00
->will($this->returnCallback(function () use ($visibilityGenerator) {
$result = $visibilityGenerator->current();
$visibilityGenerator->next();
return $result;
}));
$columnDimension = $this->getMockBuilder(ColumnDimension::class)
->setMethods(['getVisible'])
->disableOriginalConstructor()
->getMock();
$columnDimension->method('getVisible')
->willReturn(true);
$cell = $this->getMockBuilder(Cell::class)
->setMethods(['getValue'])
->disableOriginalConstructor()
->getMock();
$cell->method('getValue')
->willReturn('');
$worksheet = $this->getMockBuilder(Worksheet::class)
->setMethods(['cellExists', 'getCell', 'getRowDimension', 'getColumnDimension'])
->disableOriginalConstructor()
->getMock();
$worksheet->method('cellExists')
->willReturn(true);
$worksheet->method('getCell')
->willReturn($cell);
$worksheet->method('getRowDimension')
->willReturn($rowDimension);
$worksheet->method('getColumnDimension')
->willReturn($columnDimension);
$cellReference = $this->getMockBuilder(Cell::class)
->setMethods(['getWorksheet'])
->disableOriginalConstructor()
->getMock();
$cellReference->method('getWorksheet')
->willReturn($worksheet);
array_push($args, $cellReference);
$result = MathTrig::SUBTOTAL(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerHiddenSUBTOTAL()
{
return require 'data/Calculation/MathTrig/SUBTOTALHIDDEN.php';
}
2018-05-07 02:53:55 +00:00
protected function cellValues(array $cellValues)
{
foreach ($cellValues as $k => $v) {
yield $k => $v;
}
2018-05-06 22:43:02 +00:00
}
2018-05-07 02:53:55 +00:00
protected function cellIsFormula(array $cellValues)
{
foreach ($cellValues as $cellValue) {
2018-05-06 22:43:02 +00:00
yield $cellValue[0] === '=';
}
2018-04-21 19:34:25 +00:00
}
/**
* @dataProvider providerNestedSUBTOTAL
*
* @param mixed $expectedResult
*/
public function testNestedSUBTOTAL($expectedResult, ...$args)
{
$cellValueGenerator = $this->cellValues(Functions::flattenArray(array_slice($args, 1)));
2018-05-06 22:43:02 +00:00
$cellIsFormulaGenerator = $this->cellIsFormula(Functions::flattenArray(array_slice($args, 1)));
2018-04-21 19:34:25 +00:00
$cell = $this->getMockBuilder(Cell::class)
2018-04-21 19:34:25 +00:00
->setMethods(['getValue', 'isFormula'])
->disableOriginalConstructor()
->getMock();
$cell->method('getValue')
2018-05-07 02:53:55 +00:00
->will($this->returnCallback(function () use ($cellValueGenerator) {
$result = $cellValueGenerator->current();
$cellValueGenerator->next();
return $result;
}));
2018-04-21 19:34:25 +00:00
$cell->method('isFormula')
2018-05-07 02:53:55 +00:00
->will($this->returnCallback(function () use ($cellIsFormulaGenerator) {
$result = $cellIsFormulaGenerator->current();
$cellIsFormulaGenerator->next();
return $result;
}));
$worksheet = $this->getMockBuilder(Worksheet::class)
->setMethods(['cellExists', 'getCell'])
->disableOriginalConstructor()
->getMock();
$worksheet->method('cellExists')
->willReturn(true);
$worksheet->method('getCell')
->willReturn($cell);
$cellReference = $this->getMockBuilder(Cell::class)
->setMethods(['getWorksheet'])
->disableOriginalConstructor()
->getMock();
$cellReference->method('getWorksheet')
->willReturn($worksheet);
array_push($args, $cellReference);
2018-05-06 22:43:02 +00:00
$result = MathTrig::SUBTOTAL(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerNestedSUBTOTAL()
{
return require 'data/Calculation/MathTrig/SUBTOTALNESTED.php';
}
Add further new Functions introduced in MS Excel 2013 and 2016 (#608) - Fix ISFORMULA() function to work with a cell reference to another worksheet - Added calculation engine support for the new functions that were added in MS Excel 2013 and MS Excel 2016 - Text Functions - CONCAT() Synonym for CONCATENATE() - NUMBERVALUE() Converts text to a number, in a locale-independent way - UNICHAR() Synonym for CHAR() in PHPSpreadsheet, which has always used UTF-8 internally - UNIORD() Synonym for ORD() in PHPSpreadsheet, which has always used UTF-8 internally - TEXTJOIN() Joins together two or more text strings, separated by a delimiter - Logical Functions - XOR() Returns a logical Exclusive Or of all arguments - Date/Time Functions - ISOWEEKNUM() Returns the ISO 8601 week number of the year for a given date - Lookup and Reference Functions - FORMULATEXT() Returns a formula as a string - Engineering Functions - ERF.PRECISE() Returns the error function integrated between 0 and a supplied limit - ERFC.PRECISE() Synonym for ERFC - Math and Trig Functions - SEC() Returns the secant of an angle - SECH() Returns the hyperbolic secant of an angle - CSC() Returns the cosecant of an angle - CSCH() Returns the hyperbolic cosecant of an angle - COT() Returns the cotangent of an angle - COTH() Returns the hyperbolic cotangent of an angle - ACOT() Returns the cotangent of an angle - ACOTH() Returns the hyperbolic cotangent of an angle - Financial Functions - PDURATION() Calculates the number of periods required for an investment to reach a specified value - RRI() Calculates the interest rate required for an investment to grow to a specified future value
2018-07-22 18:17:04 +00:00
/**
* @dataProvider providerSEC
*
* @param mixed $expectedResult
* @param mixed $angle
*/
public function testSEC($expectedResult, $angle)
{
$result = MathTrig::SEC($angle);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerSEC()
{
return require 'data/Calculation/MathTrig/SEC.php';
}
/**
* @dataProvider providerSECH
*
* @param mixed $expectedResult
* @param mixed $angle
*/
public function testSECH($expectedResult, $angle)
{
$result = MathTrig::SECH($angle);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerSECH()
{
return require 'data/Calculation/MathTrig/SECH.php';
}
/**
* @dataProvider providerCSC
*
* @param mixed $expectedResult
* @param mixed $angle
*/
public function testCSC($expectedResult, $angle)
{
$result = MathTrig::CSC($angle);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerCSC()
{
return require 'data/Calculation/MathTrig/CSC.php';
}
/**
* @dataProvider providerCSCH
*
* @param mixed $expectedResult
* @param mixed $angle
*/
public function testCSCH($expectedResult, $angle)
{
$result = MathTrig::CSCH($angle);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerCSCH()
{
return require 'data/Calculation/MathTrig/CSCH.php';
}
/**
* @dataProvider providerCOT
*
* @param mixed $expectedResult
* @param mixed $angle
*/
public function testCOT($expectedResult, $angle)
{
$result = MathTrig::COT($angle);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerCOT()
{
return require 'data/Calculation/MathTrig/COT.php';
}
/**
* @dataProvider providerCOTH
*
* @param mixed $expectedResult
* @param mixed $angle
*/
public function testCOTH($expectedResult, $angle)
{
$result = MathTrig::COTH($angle);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerCOTH()
{
return require 'data/Calculation/MathTrig/COTH.php';
}
/**
* @dataProvider providerACOT
*
* @param mixed $expectedResult
* @param mixed $number
*/
public function testACOT($expectedResult, $number)
{
$result = MathTrig::ACOT($number);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerACOT()
{
return require 'data/Calculation/MathTrig/ACOT.php';
}
/**
* @dataProvider providerACOTH
*
* @param mixed $expectedResult
* @param mixed $number
*/
public function testACOTH($expectedResult, $number)
{
$result = MathTrig::ACOTH($number);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerACOTH()
{
return require 'data/Calculation/MathTrig/ACOTH.php';
}
2012-07-31 20:56:11 +00:00
}