ExactTest.php 1.9 KB

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