CountTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
  5. use PHPUnit\Framework\TestCase;
  6. class CountTest extends TestCase
  7. {
  8. /**
  9. * @var string
  10. */
  11. private $compatibilityMode;
  12. protected function setUp(): void
  13. {
  14. $this->compatibilityMode = Functions::getCompatibilityMode();
  15. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  16. }
  17. protected function tearDown(): void
  18. {
  19. Functions::setCompatibilityMode($this->compatibilityMode);
  20. }
  21. /**
  22. * @dataProvider providerBasicCOUNT
  23. *
  24. * @param mixed $expectedResult
  25. */
  26. public function testBasicCOUNT($expectedResult, ...$args): void
  27. {
  28. $result = Statistical::COUNT(...$args);
  29. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  30. }
  31. public function providerBasicCOUNT(): array
  32. {
  33. return require 'tests/data/Calculation/Statistical/BasicCOUNT.php';
  34. }
  35. /**
  36. * @dataProvider providerExcelCOUNT
  37. *
  38. * @param mixed $expectedResult
  39. */
  40. public function testExcelCOUNT($expectedResult, ...$args): void
  41. {
  42. $result = Statistical::COUNT(...$args);
  43. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  44. }
  45. public function providerExcelCOUNT(): array
  46. {
  47. return require 'tests/data/Calculation/Statistical/ExcelCOUNT.php';
  48. }
  49. /**
  50. * @dataProvider providerOpenOfficeCOUNT
  51. *
  52. * @param mixed $expectedResult
  53. */
  54. public function testOpenOfficeCOUNT($expectedResult, ...$args): void
  55. {
  56. Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
  57. $result = Statistical::COUNT(...$args);
  58. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  59. }
  60. public function providerOpenOfficeCOUNT(): array
  61. {
  62. return require 'tests/data/Calculation/Statistical/OpenOfficeCOUNT.php';
  63. }
  64. /**
  65. * @dataProvider providerGnumericCOUNT
  66. *
  67. * @param mixed $expectedResult
  68. */
  69. public function testGnumericCOUNT($expectedResult, ...$args): void
  70. {
  71. Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
  72. $result = Statistical::COUNT(...$args);
  73. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  74. }
  75. public function providerGnumericCOUNT(): array
  76. {
  77. return require 'tests/data/Calculation/Statistical/GnumericCOUNT.php';
  78. }
  79. }