ComplexTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
  5. use PHPUnit\Framework\TestCase;
  6. class ComplexTest extends TestCase
  7. {
  8. /**
  9. * @dataProvider providerCOMPLEX
  10. *
  11. * @param mixed $expectedResult
  12. */
  13. public function testCOMPLEX($expectedResult, ...$args): void
  14. {
  15. if (count($args) === 0) {
  16. $result = Engineering::COMPLEX();
  17. } elseif (count($args) === 1) {
  18. $result = Engineering::COMPLEX($args[0]);
  19. } elseif (count($args) === 2) {
  20. $result = Engineering::COMPLEX($args[0], $args[1]);
  21. } else {
  22. $result = Engineering::COMPLEX($args[0], $args[1], $args[2]);
  23. }
  24. self::assertEquals($expectedResult, $result);
  25. }
  26. public function providerCOMPLEX(): array
  27. {
  28. return require 'tests/data/Calculation/Engineering/COMPLEX.php';
  29. }
  30. /**
  31. * @dataProvider providerComplexArray
  32. */
  33. public function testComplexArray(array $expectedResult, string $real, string $imaginary): void
  34. {
  35. $calculation = Calculation::getInstance();
  36. $formula = "=COMPLEX({$real}, {$imaginary})";
  37. $result = $calculation->_calculateFormulaValue($formula);
  38. self::assertEquals($expectedResult, $result);
  39. }
  40. public function providerComplexArray(): array
  41. {
  42. return [
  43. 'row/column vector' => [
  44. [
  45. ['-2.5-2.5i', '-1-2.5i', '-2.5i', '1-2.5i', '2.5-2.5i'],
  46. ['-2.5-i', '-1-i', '-i', '1-i', '2.5-i'],
  47. ['-2.5', '-1', '0.0', '1', '2.5'],
  48. ['-2.5+i', '-1+i', 'i', '1+i', '2.5+i'],
  49. ['-2.5+2.5i', '-1+2.5i', '2.5i', '1+2.5i', '2.5+2.5i'],
  50. ],
  51. '{-2.5, -1, 0, 1, 2.5}',
  52. '{-2.5; -1; 0; 1; 2.5}',
  53. ],
  54. ];
  55. }
  56. }