IntTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class IntTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerINT
  8. *
  9. * @param mixed $expectedResult
  10. * @param string $formula
  11. */
  12. public function testINT($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("=INT($formula)");
  21. $result = $sheet->getCell('A1')->getCalculatedValue();
  22. self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
  23. }
  24. public function providerINT(): array
  25. {
  26. return require 'tests/data/Calculation/MathTrig/INT.php';
  27. }
  28. /**
  29. * @dataProvider providerIntArray
  30. */
  31. public function testIntArray(array $expectedResult, string $array): void
  32. {
  33. $calculation = Calculation::getInstance();
  34. $formula = "=INT({$array})";
  35. $result = $calculation->_calculateFormulaValue($formula);
  36. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  37. }
  38. public function providerIntArray(): array
  39. {
  40. return [
  41. 'row vector' => [[[-2, 0, 0]], '{-1.5, 0, 0.3}'],
  42. 'column vector' => [[[-2], [0], [0]], '{-1.5; 0; 0.3}'],
  43. 'matrix' => [[[-2, 0], [0, 12]], '{-1.5, 0; 0.3, 12.5}'],
  44. ];
  45. }
  46. }