More work on refactoring Excel Calculation Function Unit Tests

This commit is contained in:
MarkBaker 2019-07-27 16:02:58 +02:00
parent 0b2dcae1be
commit 905a697639
10 changed files with 174 additions and 102 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### 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)
- 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)

View File

@ -220,11 +220,10 @@ class MathTrig
return Functions::NAN();
}
$factLoop = floor($factVal);
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
if ($factVal > $factLoop) {
if ((Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) &&
($factVal > $factLoop)) {
return Functions::NAN();
}
}
$factorial = 1;
while ($factLoop > 1) {

View File

@ -52,7 +52,7 @@ class TextData
return ($stringValue) ? Calculation::getTRUE() : Calculation::getFALSE();
}
if (self::$invalidChars == null) {
if (self::$invalidChars === null) {
self::$invalidChars = range(chr(0), chr(31));
}
@ -84,6 +84,15 @@ class TextData
return null;
}
private static function convertBooleanValue($value)
{
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
return (int)$value;
}
return ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
}
/**
* ASCIICODE.
*
@ -98,11 +107,7 @@ class TextData
}
$characters = Functions::flattenSingleValue($characters);
if (is_bool($characters)) {
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$characters = (int) $characters;
} else {
$characters = ($characters) ? Calculation::getTRUE() : Calculation::getFALSE();
}
$characters = self::convertBooleanValue($characters);
}
$character = $characters;
@ -126,11 +131,7 @@ class TextData
$aArgs = Functions::flattenArray($args);
foreach ($aArgs as $arg) {
if (is_bool($arg)) {
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$arg = (int) $arg;
} else {
$arg = ($arg) ? Calculation::getTRUE() : Calculation::getFALSE();
}
$arg = self::convertBooleanValue($arg);
}
$returnValue .= $arg;
}
@ -197,7 +198,7 @@ class TextData
}
if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) {
if (StringHelper::countCharacters($needle) == 0) {
if (StringHelper::countCharacters($needle) === 0) {
return $offset;
}
@ -232,7 +233,7 @@ class TextData
}
if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) {
if (StringHelper::countCharacters($needle) == 0) {
if (StringHelper::countCharacters($needle) === 0) {
return $offset;
}
@ -659,11 +660,7 @@ class TextData
if ($ignoreEmpty && trim($arg) == '') {
unset($aArgs[$key]);
} elseif (is_bool($arg)) {
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$arg = (int) $arg;
} else {
$arg = ($arg) ? Calculation::getTRUE() : Calculation::getFALSE();
}
$arg = self::convertBooleanValue($arg);
}
}

View File

@ -13,38 +13,6 @@ class FinancialTest extends TestCase
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
*

View File

@ -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';
}
}

View File

@ -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';
}
}

View File

@ -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';
}
}

View File

@ -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';
}
}

View File

@ -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';
}
}

View File

@ -19,54 +19,6 @@ class LookupRefTest extends TestCase
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
*