ModeTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
  3. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  4. use PHPUnit\Framework\TestCase;
  5. class ModeTest extends TestCase
  6. {
  7. /**
  8. * @dataProvider providerMODE
  9. *
  10. * @param mixed $expectedResult
  11. */
  12. public function testMODE($expectedResult, string $str): void
  13. {
  14. $workbook = new Spreadsheet();
  15. $sheet = $workbook->getActiveSheet();
  16. $row = 1;
  17. $sheet->setCellValue("B$row", "=MODE($str)");
  18. $sheet->setCellValue("C$row", "=MODE.SNGL($str)");
  19. self::assertEquals($expectedResult, $sheet->getCell("B$row")->getCalculatedValue());
  20. self::assertEquals($expectedResult, $sheet->getCell("C$row")->getCalculatedValue());
  21. }
  22. public function providerMODE(): array
  23. {
  24. return require 'tests/data/Calculation/Statistical/MODE.php';
  25. }
  26. public function testMODENoArgs(): void
  27. {
  28. $this->expectException(\PhpOffice\PhpSpreadsheet\Calculation\Exception::class);
  29. $workbook = new Spreadsheet();
  30. $sheet = $workbook->getActiveSheet();
  31. $sheet->setCellValue('B1', '=MODE()');
  32. self::assertEquals('#N/A', $sheet->getCell('B1')->getCalculatedValue());
  33. }
  34. }