More work on refactoring Excel Calculation Function Unit Tests
This commit is contained in:
parent
0b2dcae1be
commit
905a697639
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Implementation of IFNA() Logical Function
|
||||||
- When <br> appears in a table cell, set the cell to wrap [Issue #1071](https://github.com/PHPOffice/PhpSpreadsheet/issues/1071) and [PR #1070](https://github.com/PHPOffice/PhpSpreadsheet/pull/1070)
|
- When <br> appears in a table cell, set the cell to wrap [Issue #1071](https://github.com/PHPOffice/PhpSpreadsheet/issues/1071) and [PR #1070](https://github.com/PHPOffice/PhpSpreadsheet/pull/1070)
|
||||||
- Add MAXIFS, MINIFS, COUNTIFS and Remove MINIF, MAXIF - [Issue #1056](https://github.com/PHPOffice/PhpSpreadsheet/issues/1056)
|
- Add MAXIFS, MINIFS, COUNTIFS and Remove MINIF, MAXIF - [Issue #1056](https://github.com/PHPOffice/PhpSpreadsheet/issues/1056)
|
||||||
- HLookup needs an ordered list even if range_lookup is set to false [Issue #1055](https://github.com/PHPOffice/PhpSpreadsheet/issues/1055) and [PR #1076](https://github.com/PHPOffice/PhpSpreadsheet/pull/1076)
|
- HLookup needs an ordered list even if range_lookup is set to false [Issue #1055](https://github.com/PHPOffice/PhpSpreadsheet/issues/1055) and [PR #1076](https://github.com/PHPOffice/PhpSpreadsheet/pull/1076)
|
||||||
|
|
|
@ -220,10 +220,9 @@ class MathTrig
|
||||||
return Functions::NAN();
|
return Functions::NAN();
|
||||||
}
|
}
|
||||||
$factLoop = floor($factVal);
|
$factLoop = floor($factVal);
|
||||||
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
|
if ((Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) &&
|
||||||
if ($factVal > $factLoop) {
|
($factVal > $factLoop)) {
|
||||||
return Functions::NAN();
|
return Functions::NAN();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$factorial = 1;
|
$factorial = 1;
|
||||||
|
|
|
@ -52,7 +52,7 @@ class TextData
|
||||||
return ($stringValue) ? Calculation::getTRUE() : Calculation::getFALSE();
|
return ($stringValue) ? Calculation::getTRUE() : Calculation::getFALSE();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::$invalidChars == null) {
|
if (self::$invalidChars === null) {
|
||||||
self::$invalidChars = range(chr(0), chr(31));
|
self::$invalidChars = range(chr(0), chr(31));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +84,15 @@ class TextData
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function convertBooleanValue($value)
|
||||||
|
{
|
||||||
|
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
|
||||||
|
return (int)$value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ASCIICODE.
|
* ASCIICODE.
|
||||||
*
|
*
|
||||||
|
@ -98,11 +107,7 @@ class TextData
|
||||||
}
|
}
|
||||||
$characters = Functions::flattenSingleValue($characters);
|
$characters = Functions::flattenSingleValue($characters);
|
||||||
if (is_bool($characters)) {
|
if (is_bool($characters)) {
|
||||||
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
|
$characters = self::convertBooleanValue($characters);
|
||||||
$characters = (int) $characters;
|
|
||||||
} else {
|
|
||||||
$characters = ($characters) ? Calculation::getTRUE() : Calculation::getFALSE();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$character = $characters;
|
$character = $characters;
|
||||||
|
@ -126,11 +131,7 @@ class TextData
|
||||||
$aArgs = Functions::flattenArray($args);
|
$aArgs = Functions::flattenArray($args);
|
||||||
foreach ($aArgs as $arg) {
|
foreach ($aArgs as $arg) {
|
||||||
if (is_bool($arg)) {
|
if (is_bool($arg)) {
|
||||||
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
|
$arg = self::convertBooleanValue($arg);
|
||||||
$arg = (int) $arg;
|
|
||||||
} else {
|
|
||||||
$arg = ($arg) ? Calculation::getTRUE() : Calculation::getFALSE();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$returnValue .= $arg;
|
$returnValue .= $arg;
|
||||||
}
|
}
|
||||||
|
@ -197,7 +198,7 @@ class TextData
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) {
|
if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) {
|
||||||
if (StringHelper::countCharacters($needle) == 0) {
|
if (StringHelper::countCharacters($needle) === 0) {
|
||||||
return $offset;
|
return $offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +233,7 @@ class TextData
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) {
|
if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) {
|
||||||
if (StringHelper::countCharacters($needle) == 0) {
|
if (StringHelper::countCharacters($needle) === 0) {
|
||||||
return $offset;
|
return $offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,11 +660,7 @@ class TextData
|
||||||
if ($ignoreEmpty && trim($arg) == '') {
|
if ($ignoreEmpty && trim($arg) == '') {
|
||||||
unset($aArgs[$key]);
|
unset($aArgs[$key]);
|
||||||
} elseif (is_bool($arg)) {
|
} elseif (is_bool($arg)) {
|
||||||
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
|
$arg = self::convertBooleanValue($arg);
|
||||||
$arg = (int) $arg;
|
|
||||||
} else {
|
|
||||||
$arg = ($arg) ? Calculation::getTRUE() : Calculation::getFALSE();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,38 +13,6 @@ class FinancialTest extends TestCase
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider providerACCRINT
|
|
||||||
*
|
|
||||||
* @param mixed $expectedResult
|
|
||||||
*/
|
|
||||||
public function testACCRINT($expectedResult, ...$args)
|
|
||||||
{
|
|
||||||
$result = Financial::ACCRINT(...$args);
|
|
||||||
self::assertEquals($expectedResult, $result, '', 1E-8);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function providerACCRINT()
|
|
||||||
{
|
|
||||||
return require 'data/Calculation/Financial/ACCRINT.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider providerACCRINTM
|
|
||||||
*
|
|
||||||
* @param mixed $expectedResult
|
|
||||||
*/
|
|
||||||
public function testACCRINTM($expectedResult, ...$args)
|
|
||||||
{
|
|
||||||
$result = Financial::ACCRINTM(...$args);
|
|
||||||
self::assertEquals($expectedResult, $result, '', 1E-8);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function providerACCRINTM()
|
|
||||||
{
|
|
||||||
return require 'data/Calculation/Financial/ACCRINTM.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerAMORDEGRC
|
* @dataProvider providerAMORDEGRC
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class AccrintMTest extends TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerACCRINTM
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
*/
|
||||||
|
public function testACCRINTM($expectedResult, ...$args)
|
||||||
|
{
|
||||||
|
$result = Financial::ACCRINTM(...$args);
|
||||||
|
self::assertEquals($expectedResult, $result, '', 1E-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerACCRINTM()
|
||||||
|
{
|
||||||
|
return require 'data/Calculation/Financial/ACCRINTM.php';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class AccrintTest extends TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerACCRINT
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
*/
|
||||||
|
public function testACCRINT($expectedResult, ...$args)
|
||||||
|
{
|
||||||
|
$result = Financial::ACCRINT(...$args);
|
||||||
|
$this->assertEquals($expectedResult, $result, '', 1E-8);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerACCRINT()
|
||||||
|
{
|
||||||
|
return require 'data/Calculation/Financial/ACCRINT.php';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class HLookupTest extends TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerHLOOKUP
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
*/
|
||||||
|
public function testHLOOKUP($expectedResult, ...$args)
|
||||||
|
{
|
||||||
|
$result = LookupRef::HLOOKUP(...$args);
|
||||||
|
$this->assertEquals($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerHLOOKUP()
|
||||||
|
{
|
||||||
|
return require 'data/Calculation/LookupRef/HLOOKUP.php';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class LookupTest extends TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerLOOKUP
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
*/
|
||||||
|
public function testLOOKUP($expectedResult, ...$args)
|
||||||
|
{
|
||||||
|
$result = LookupRef::LOOKUP(...$args);
|
||||||
|
$this->assertEquals($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerLOOKUP()
|
||||||
|
{
|
||||||
|
return require 'data/Calculation/LookupRef/LOOKUP.php';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class VLookupTest extends TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerVLOOKUP
|
||||||
|
*
|
||||||
|
* @param mixed $expectedResult
|
||||||
|
*/
|
||||||
|
public function testVLOOKUP($expectedResult, ...$args)
|
||||||
|
{
|
||||||
|
$result = LookupRef::VLOOKUP(...$args);
|
||||||
|
$this->assertEquals($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerVLOOKUP()
|
||||||
|
{
|
||||||
|
return require 'data/Calculation/LookupRef/VLOOKUP.php';
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,54 +19,6 @@ class LookupRefTest extends TestCase
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider providerHLOOKUP
|
|
||||||
*
|
|
||||||
* @param mixed $expectedResult
|
|
||||||
*/
|
|
||||||
public function testHLOOKUP($expectedResult, ...$args)
|
|
||||||
{
|
|
||||||
$result = LookupRef::HLOOKUP(...$args);
|
|
||||||
self::assertEquals($expectedResult, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function providerHLOOKUP()
|
|
||||||
{
|
|
||||||
return require 'data/Calculation/LookupRef/HLOOKUP.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider providerVLOOKUP
|
|
||||||
*
|
|
||||||
* @param mixed $expectedResult
|
|
||||||
*/
|
|
||||||
public function testVLOOKUP($expectedResult, ...$args)
|
|
||||||
{
|
|
||||||
$result = LookupRef::VLOOKUP(...$args);
|
|
||||||
self::assertEquals($expectedResult, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function providerVLOOKUP()
|
|
||||||
{
|
|
||||||
return require 'data/Calculation/LookupRef/VLOOKUP.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider providerLOOKUP
|
|
||||||
*
|
|
||||||
* @param mixed $expectedResult
|
|
||||||
*/
|
|
||||||
public function testLOOKUP($expectedResult, ...$args)
|
|
||||||
{
|
|
||||||
$result = LookupRef::LOOKUP(...$args);
|
|
||||||
self::assertEquals($expectedResult, $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function providerLOOKUP()
|
|
||||||
{
|
|
||||||
return require 'data/Calculation/LookupRef/LOOKUP.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerMATCH
|
* @dataProvider providerMATCH
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue