RomanTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class RomanTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerROMAN
  8. *
  9. * @param mixed $expectedResult
  10. * @param mixed $formula
  11. */
  12. public function testROMAN($expectedResult, $formula): void
  13. {
  14. $this->mightHaveException($expectedResult);
  15. $sheet = $this->getSheet();
  16. $sheet->setCellValue('A3', 49);
  17. $sheet->getCell('A1')->setValue("=ROMAN($formula)");
  18. $result = $sheet->getCell('A1')->getCalculatedValue();
  19. self::assertEquals($expectedResult, $result);
  20. }
  21. public function providerROMAN(): array
  22. {
  23. return require 'tests/data/Calculation/MathTrig/ROMAN.php';
  24. }
  25. /**
  26. * @dataProvider providerRomanArray
  27. */
  28. public function testRomanArray(array $expectedResult, string $values, string $styles): void
  29. {
  30. $calculation = Calculation::getInstance();
  31. $formula = "=ROMAN({$values}, {$styles})";
  32. $result = $calculation->_calculateFormulaValue($formula);
  33. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  34. }
  35. public function providerRomanArray(): array
  36. {
  37. return [
  38. 'row vector' => [[['XLIX', 'MMXXII', 'CDXCIX']], '{49, 2022, 499}', '0'],
  39. 'column vector' => [[['XLIX'], ['MMXXII'], ['CDXCIX']], '{49; 2022; 499}', '0'],
  40. 'matrix' => [[['XLIX', 'MMXXII'], ['LXIV', 'CDXCIX']], '{49, 2022; 64, 499}', '0'],
  41. ];
  42. }
  43. }