RoundUpTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class RoundUpTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerRoundUp
  8. *
  9. * @param mixed $expectedResult
  10. * @param mixed $formula
  11. */
  12. public function testRoundUp($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("=ROUNDUP($formula)");
  21. $result = $sheet->getCell('A1')->getCalculatedValue();
  22. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  23. }
  24. public function providerRoundUp(): array
  25. {
  26. return require 'tests/data/Calculation/MathTrig/ROUNDUP.php';
  27. }
  28. /**
  29. * @dataProvider providerRoundUpArray
  30. */
  31. public function testRoundUpArray(array $expectedResult, string $argument1, string $argument2): void
  32. {
  33. $calculation = Calculation::getInstance();
  34. $formula = "=ROUNDUP({$argument1},{$argument2})";
  35. $result = $calculation->_calculateFormulaValue($formula);
  36. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  37. }
  38. public function providerRoundUpArray(): array
  39. {
  40. return [
  41. 'first argument row vector' => [
  42. [[0.146, 1.373, -931.683, 3.142]],
  43. '{0.14527, 1.3725, -931.6829, 3.14159265}',
  44. '3',
  45. ],
  46. 'first argument column vector' => [
  47. [[0.146], [1.373], [-931.683], [3.142]],
  48. '{0.14527; 1.3725; -931.6829; 3.14159265}',
  49. '3',
  50. ],
  51. 'first argument matrix' => [
  52. [[0.146, 1.373], [-931.683, 3.142]],
  53. '{0.14527, 1.3725; -931.6829, 3.14159265}',
  54. '3',
  55. ],
  56. 'second argument row vector' => [
  57. [[0.2, 0.15, 0.146, 0.1453, 0.14527]],
  58. '0.14527',
  59. '{1, 2, 3, 4, 5}',
  60. ],
  61. 'second argument column vector' => [
  62. [[0.2], [0.15], [0.146], [0.1453], [0.14527]],
  63. '0.14527',
  64. '{1; 2; 3; 4; 5}',
  65. ],
  66. 'second argument matrix' => [
  67. [[0.2, 0.15], [0.146, 0.1453]],
  68. '0.14527',
  69. '{1, 2; 3, 4}',
  70. ],
  71. 'A row and a column vector' => [
  72. [
  73. [0.2, 0.15, 0.146, 0.1453],
  74. [1.4, 1.38, 1.373, 1.3725],
  75. [-931.7, -931.69, -931.683, -931.6829],
  76. [3.2, 3.15, 3.142, 3.1416],
  77. ],
  78. '{0.14527; 1.37250; -931.68290; 3.14159265}',
  79. '{1, 2, 3, 4}',
  80. ],
  81. 'Two row vectors' => [
  82. [[0.2, 1.38, -931.683, 3.1416]],
  83. '{0.14527, 1.37250, -931.68290, 3.14159265}',
  84. '{1, 2, 3, 4}',
  85. ],
  86. 'Two column vectors' => [
  87. [[0.2], [1.38], [-931.683], [3.1416]],
  88. '{0.14527; 1.37250; -931.68290; 3.14159265}',
  89. '{1; 2; 3; 4}',
  90. ],
  91. ];
  92. }
  93. }