ImSubTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
  5. use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  6. use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert;
  7. use PHPUnit\Framework\TestCase;
  8. class ImSubTest extends TestCase
  9. {
  10. const COMPLEX_PRECISION = 1E-8;
  11. /**
  12. * @var ComplexAssert
  13. */
  14. private $complexAssert;
  15. protected function setUp(): void
  16. {
  17. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  18. $this->complexAssert = new ComplexAssert();
  19. }
  20. /**
  21. * @dataProvider providerIMSUB
  22. *
  23. * @param mixed $expectedResult
  24. */
  25. public function testIMSUB($expectedResult, ...$args): void
  26. {
  27. $result = Engineering::IMSUB(...$args);
  28. self::assertTrue(
  29. $this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION),
  30. $this->complexAssert->getErrorMessage()
  31. );
  32. }
  33. public function providerIMSUB(): array
  34. {
  35. return require 'tests/data/Calculation/Engineering/IMSUB.php';
  36. }
  37. /**
  38. * @dataProvider providerImSubArray
  39. */
  40. public function testImSubArray(array $expectedResult, string $subidend, string $subisor): void
  41. {
  42. $calculation = Calculation::getInstance();
  43. $formula = "=IMSUB({$subidend}, {$subisor})";
  44. $result = $calculation->_calculateFormulaValue($formula);
  45. self::assertEquals($expectedResult, $result);
  46. }
  47. public function providerImSubArray(): array
  48. {
  49. return [
  50. 'matrix' => [
  51. [
  52. ['1-7.5i', '-2-2.5i', '-1-4.5i'],
  53. ['1-6i', '-2-i', '-1-3i'],
  54. ['1-4i', '-2+i', '-1-i'],
  55. ['1-2.5i', '-2+2.5i', '-1+0.5i'],
  56. ],
  57. '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}',
  58. '{"-2+5i", 2, "2+2i"}',
  59. ],
  60. ];
  61. }
  62. }