ImExpTest.php 2.4 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 ImExpTest 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 providerIMEXP
  22. *
  23. * @param mixed $expectedResult
  24. * @param mixed $value
  25. */
  26. public function testIMEXP($expectedResult, $value): void
  27. {
  28. $result = Engineering::IMEXP($value);
  29. self::assertTrue(
  30. $this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION),
  31. $this->complexAssert->getErrorMessage()
  32. );
  33. }
  34. public function providerIMEXP(): array
  35. {
  36. return require 'tests/data/Calculation/Engineering/IMEXP.php';
  37. }
  38. /**
  39. * @dataProvider providerImExpArray
  40. */
  41. public function testImExpArray(array $expectedResult, string $complex): void
  42. {
  43. $calculation = Calculation::getInstance();
  44. $formula = "=IMEXP({$complex})";
  45. $result = $calculation->_calculateFormulaValue($formula);
  46. self::assertEquals($expectedResult, $result);
  47. }
  48. public function providerImExpArray(): array
  49. {
  50. return [
  51. 'row/column vector' => [
  52. [
  53. ['-0.29472426558547-0.22016559792964i', '-0.80114361554693-0.59847214410396i', '-2.1777341321272-1.6268159541567i'],
  54. ['0.19876611034641-0.30955987565311i', '0.54030230586814-0.8414709848079i', '1.4686939399159-2.2873552871788i'],
  55. ['0.19876611034641+0.30955987565311i', '0.54030230586814+0.8414709848079i', '1.4686939399159+2.2873552871788i'],
  56. ['-0.29472426558547+0.22016559792964i', '-0.80114361554693+0.59847214410396i', '-2.1777341321272+1.6268159541567i'],
  57. ],
  58. '{"-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"}',
  59. ],
  60. ];
  61. }
  62. }