ImDivTest.php 2.2 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 ImDivTest 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 providerIMDIV
  22. *
  23. * @param mixed $expectedResult
  24. */
  25. public function testIMDIV($expectedResult, ...$args): void
  26. {
  27. $result = Engineering::IMDIV(...$args);
  28. self::assertTrue(
  29. $this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION),
  30. $this->complexAssert->getErrorMessage()
  31. );
  32. }
  33. public function providerIMDIV(): array
  34. {
  35. return require 'tests/data/Calculation/Engineering/IMDIV.php';
  36. }
  37. /**
  38. * @dataProvider providerImDivArray
  39. */
  40. public function testImDivArray(array $expectedResult, string $dividend, string $divisor): void
  41. {
  42. $calculation = Calculation::getInstance();
  43. $formula = "=IMDIV({$dividend}, {$divisor})";
  44. $result = $calculation->_calculateFormulaValue($formula);
  45. self::assertEquals($expectedResult, $result);
  46. }
  47. public function providerImDivArray(): array
  48. {
  49. return [
  50. 'matrix' => [
  51. [
  52. ['-0.36206896551724+0.3448275862069i', '-1.25i', '-0.375-0.875i'],
  53. ['-0.10344827586207+0.24137931034483i', '-0.5i', '-0.5i'],
  54. ['0.24137931034483+0.10344827586207i', '0.5i', '0.5'],
  55. ['0.5', '1.25i', '0.875+0.375i'],
  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. }