BaseTest.php 2.0 KB

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