DollarTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class DollarTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerDOLLAR
  8. *
  9. * @param mixed $expectedResult
  10. * @param mixed $amount
  11. * @param mixed $decimals
  12. */
  13. public function testDOLLAR($expectedResult, $amount = 'omitted', $decimals = 'omitted'): void
  14. {
  15. $this->mightHaveException($expectedResult);
  16. $sheet = $this->getSheet();
  17. if ($amount === 'omitted') {
  18. $sheet->getCell('B1')->setValue('=DOLLAR()');
  19. } elseif ($decimals === 'omitted') {
  20. $this->setCell('A1', $amount);
  21. $sheet->getCell('B1')->setValue('=DOLLAR(A1)');
  22. } else {
  23. $this->setCell('A1', $amount);
  24. $this->setCell('A2', $decimals);
  25. $sheet->getCell('B1')->setValue('=DOLLAR(A1, A2)');
  26. }
  27. $result = $sheet->getCell('B1')->getCalculatedValue();
  28. self::assertEquals($expectedResult, $result);
  29. }
  30. public function providerDOLLAR(): array
  31. {
  32. return require 'tests/data/Calculation/TextData/DOLLAR.php';
  33. }
  34. /**
  35. * @dataProvider providerDollarArray
  36. */
  37. public function testDollarArray(array $expectedResult, string $argument1, string $argument2): void
  38. {
  39. $calculation = Calculation::getInstance();
  40. $formula = "=DOLLAR({$argument1}, {$argument2})";
  41. $result = $calculation->_calculateFormulaValue($formula);
  42. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  43. }
  44. public function providerDollarArray(): array
  45. {
  46. return [
  47. 'row vector #1' => [[['-$123.32', '$123.46', '$12,345.68']], '{-123.321, 123.456, 12345.6789}', '2'],
  48. 'column vector #1' => [[['-$123.32'], ['$123.46'], ['$12,345.68']], '{-123.321; 123.456; 12345.6789}', '2'],
  49. 'matrix #1' => [[['-$123.46', '$12,345.68'], ['-$123.456', '$12,345.679']], '{-123.456, 12345.6789}', '{2; 3}'],
  50. ];
  51. }
  52. }