QuotientTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class QuotientTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerQUOTIENT
  8. *
  9. * @param mixed $expectedResult
  10. * @param mixed $arg1
  11. * @param mixed $arg2
  12. */
  13. public function testQUOTIENT($expectedResult, $arg1 = 'omitted', $arg2 = 'omitted'): void
  14. {
  15. $this->mightHaveException($expectedResult);
  16. $sheet = $this->getSheet();
  17. if ($arg1 !== null) {
  18. $sheet->getCell('A1')->setValue($arg1);
  19. }
  20. if ($arg2 !== null) {
  21. $sheet->getCell('A2')->setValue($arg2);
  22. }
  23. if ($arg1 === 'omitted') {
  24. $sheet->getCell('B1')->setValue('=QUOTIENT()');
  25. } elseif ($arg2 === 'omitted') {
  26. $sheet->getCell('B1')->setValue('=QUOTIENT(A1)');
  27. } else {
  28. $sheet->getCell('B1')->setValue('=QUOTIENT(A1, A2)');
  29. }
  30. $result = $sheet->getCell('B1')->getCalculatedValue();
  31. self::assertSame($expectedResult, $result);
  32. }
  33. public function providerQUOTIENT(): array
  34. {
  35. return require 'tests/data/Calculation/MathTrig/QUOTIENT.php';
  36. }
  37. /**
  38. * @dataProvider providerQuotientArray
  39. */
  40. public function testQuotientArray(array $expectedResult, string $argument1, string $argument2): void
  41. {
  42. $calculation = Calculation::getInstance();
  43. $formula = "=QUOTIENT({$argument1}, {$argument2})";
  44. $result = $calculation->_calculateFormulaValue($formula);
  45. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  46. }
  47. public function providerQuotientArray(): array
  48. {
  49. return [
  50. 'matrix' => [[[3, 3, 2], [2, 2, 1], [1, 0, 0]], '{9, 8, 7; 6, 5, 4; 3, 2, 1}', '2.5'],
  51. ];
  52. }
  53. }