CeilingTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class CeilingTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerCEILING
  8. *
  9. * @param mixed $expectedResult
  10. * @param string $formula
  11. */
  12. public function testCEILING($expectedResult, $formula): void
  13. {
  14. $this->mightHaveException($expectedResult);
  15. $sheet = $this->getSheet();
  16. $sheet->setCellValue('A2', 1.3);
  17. $sheet->setCellValue('A3', 2.7);
  18. $sheet->setCellValue('A4', -3.8);
  19. $sheet->setCellValue('A5', -5.2);
  20. $sheet->getCell('A1')->setValue("=CEILING($formula)");
  21. $result = $sheet->getCell('A1')->getCalculatedValue();
  22. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  23. }
  24. public function providerCEILING(): array
  25. {
  26. return require 'tests/data/Calculation/MathTrig/CEILING.php';
  27. }
  28. public function testCEILINGGnumeric1Arg(): void
  29. {
  30. self::setGnumeric();
  31. $sheet = $this->getSheet();
  32. $sheet->getCell('A1')->setValue('=CEILING(5.1)');
  33. $result = $sheet->getCell('A1')->getCalculatedValue();
  34. self::assertEqualsWithDelta(6, $result, 1E-12);
  35. }
  36. public function testCELINGOpenOffice1Arg(): void
  37. {
  38. self::setOpenOffice();
  39. $sheet = $this->getSheet();
  40. $sheet->getCell('A1')->setValue('=CEILING(5.1)');
  41. $result = $sheet->getCell('A1')->getCalculatedValue();
  42. self::assertEqualsWithDelta(6, $result, 1E-12);
  43. }
  44. public function testCEILINGExcel1Arg(): void
  45. {
  46. $this->mightHaveException('exception');
  47. $sheet = $this->getSheet();
  48. $sheet->getCell('A1')->setValue('=CEILING(5.1)');
  49. $result = $sheet->getCell('A1')->getCalculatedValue();
  50. self::assertEqualsWithDelta(6, $result, 1E-12);
  51. }
  52. /**
  53. * @dataProvider providerCeilingArray
  54. */
  55. public function testCeilingArray(array $expectedResult, string $argument1, string $argument2): void
  56. {
  57. $calculation = Calculation::getInstance();
  58. $formula = "=CEILING({$argument1}, {$argument2})";
  59. $result = $calculation->_calculateFormulaValue($formula);
  60. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  61. }
  62. public function providerCeilingArray(): array
  63. {
  64. return [
  65. 'matrix' => [[[3.15, 3.142], [3.1416, 3.141594]], '3.1415926536', '{0.01, 0.002; 0.00005, 0.000002}'],
  66. ];
  67. }
  68. }