2019-07-20 16:40:05 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
|
|
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class CountTest extends TestCase
|
|
|
|
{
|
Restoring State After Static Changes in Tests (#1571)
This request does not change any source code, only tests.
For a change on which I was working, a test passed when run on its own,
but failed when run as part of the full test suite. It turned out that
an existing test had changed a static value,
thousands separator in this case, and failed to restore it.
The test turned out to be AdvancedBinderTest.
The search for the offending test was more difficult than it should have
been because 26 test scripts which had nothing to do with thousands
separator nevertheless changed that value. They all changed
decimal separator, currency code, and compatibility mode as well,
again for no reason. I changed all of those to eliminate those operations.
I changed the following tests, which actually do change the static
properties identified above for a reason, to restore them as part of teardown.
- CalculationTest sets compatibilityMode and locale
- DayTest sets compatibilityMode, returnDateType, and excelCalendar
- CountTest sets compatibilityMode
- FunctionsTest sets compatibilityMode and returnDateType
- AdvancedValueBinderTest sets currencyCode, decimalSeparator, thousandsSeparator
- StringHelperTest sets currencyCode, decimalSeparator, thousandsSeparator
- NumberFormatTest sets currencyCode, decimalSeparator, thousandsSeparator
- HtmlNumberFormatTest sets currencyCode, decimalSeparator, thousandsSeparator
2020-07-15 11:23:00 +00:00
|
|
|
private $compatibilityMode;
|
|
|
|
|
2020-04-27 10:28:36 +00:00
|
|
|
protected function setUp(): void
|
2019-07-20 16:40:05 +00:00
|
|
|
{
|
Restoring State After Static Changes in Tests (#1571)
This request does not change any source code, only tests.
For a change on which I was working, a test passed when run on its own,
but failed when run as part of the full test suite. It turned out that
an existing test had changed a static value,
thousands separator in this case, and failed to restore it.
The test turned out to be AdvancedBinderTest.
The search for the offending test was more difficult than it should have
been because 26 test scripts which had nothing to do with thousands
separator nevertheless changed that value. They all changed
decimal separator, currency code, and compatibility mode as well,
again for no reason. I changed all of those to eliminate those operations.
I changed the following tests, which actually do change the static
properties identified above for a reason, to restore them as part of teardown.
- CalculationTest sets compatibilityMode and locale
- DayTest sets compatibilityMode, returnDateType, and excelCalendar
- CountTest sets compatibilityMode
- FunctionsTest sets compatibilityMode and returnDateType
- AdvancedValueBinderTest sets currencyCode, decimalSeparator, thousandsSeparator
- StringHelperTest sets currencyCode, decimalSeparator, thousandsSeparator
- NumberFormatTest sets currencyCode, decimalSeparator, thousandsSeparator
- HtmlNumberFormatTest sets currencyCode, decimalSeparator, thousandsSeparator
2020-07-15 11:23:00 +00:00
|
|
|
$this->compatibilityMode = Functions::getCompatibilityMode();
|
2019-07-20 16:40:05 +00:00
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
|
|
}
|
|
|
|
|
Restoring State After Static Changes in Tests (#1571)
This request does not change any source code, only tests.
For a change on which I was working, a test passed when run on its own,
but failed when run as part of the full test suite. It turned out that
an existing test had changed a static value,
thousands separator in this case, and failed to restore it.
The test turned out to be AdvancedBinderTest.
The search for the offending test was more difficult than it should have
been because 26 test scripts which had nothing to do with thousands
separator nevertheless changed that value. They all changed
decimal separator, currency code, and compatibility mode as well,
again for no reason. I changed all of those to eliminate those operations.
I changed the following tests, which actually do change the static
properties identified above for a reason, to restore them as part of teardown.
- CalculationTest sets compatibilityMode and locale
- DayTest sets compatibilityMode, returnDateType, and excelCalendar
- CountTest sets compatibilityMode
- FunctionsTest sets compatibilityMode and returnDateType
- AdvancedValueBinderTest sets currencyCode, decimalSeparator, thousandsSeparator
- StringHelperTest sets currencyCode, decimalSeparator, thousandsSeparator
- NumberFormatTest sets currencyCode, decimalSeparator, thousandsSeparator
- HtmlNumberFormatTest sets currencyCode, decimalSeparator, thousandsSeparator
2020-07-15 11:23:00 +00:00
|
|
|
protected function tearDown(): void
|
|
|
|
{
|
|
|
|
Functions::setCompatibilityMode($this->compatibilityMode);
|
|
|
|
}
|
|
|
|
|
2019-07-20 16:40:05 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providerBasicCOUNT
|
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testBasicCOUNT($expectedResult, ...$args): void
|
2019-07-20 16:40:05 +00:00
|
|
|
{
|
|
|
|
$result = Statistical::COUNT(...$args);
|
2020-05-18 04:49:57 +00:00
|
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
2019-07-20 16:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerBasicCOUNT()
|
|
|
|
{
|
2020-05-17 09:35:55 +00:00
|
|
|
return require 'tests/data/Calculation/Statistical/BasicCOUNT.php';
|
2019-07-20 16:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerExcelCOUNT
|
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testExcelCOUNT($expectedResult, ...$args): void
|
2019-07-20 16:40:05 +00:00
|
|
|
{
|
|
|
|
$result = Statistical::COUNT(...$args);
|
2020-05-18 04:49:57 +00:00
|
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
2019-07-20 16:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerExcelCOUNT()
|
|
|
|
{
|
2020-05-17 09:35:55 +00:00
|
|
|
return require 'tests/data/Calculation/Statistical/ExcelCOUNT.php';
|
2019-07-20 16:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerOpenOfficeCOUNT
|
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testOpenOfficeCOUNT($expectedResult, ...$args): void
|
2019-07-20 16:40:05 +00:00
|
|
|
{
|
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
|
|
|
|
|
|
|
|
$result = Statistical::COUNT(...$args);
|
2020-05-18 04:49:57 +00:00
|
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
2019-07-20 16:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerOpenOfficeCOUNT()
|
|
|
|
{
|
2020-05-17 09:35:55 +00:00
|
|
|
return require 'tests/data/Calculation/Statistical/OpenOfficeCOUNT.php';
|
2019-07-20 16:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerGnumericCOUNT
|
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testGnumericCOUNT($expectedResult, ...$args): void
|
2019-07-20 16:40:05 +00:00
|
|
|
{
|
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
|
|
|
|
|
|
|
|
$result = Statistical::COUNT(...$args);
|
2020-05-18 04:49:57 +00:00
|
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
|
2019-07-20 16:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providerGnumericCOUNT()
|
|
|
|
{
|
2020-05-17 09:35:55 +00:00
|
|
|
return require 'tests/data/Calculation/Statistical/GnumericCOUNT.php';
|
2019-07-20 16:40:05 +00:00
|
|
|
}
|
|
|
|
}
|