ImPowerTest.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 ImPowerTest 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 providerIMPOWER
  22. *
  23. * @param mixed $expectedResult
  24. */
  25. public function testIMPOWER($expectedResult, ...$args): void
  26. {
  27. $result = Engineering::IMPOWER(...$args);
  28. self::assertTrue(
  29. $this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION),
  30. $this->complexAssert->getErrorMessage()
  31. );
  32. }
  33. public function providerIMPOWER(): array
  34. {
  35. return require 'tests/data/Calculation/Engineering/IMPOWER.php';
  36. }
  37. /**
  38. * @dataProvider providerImPowerArray
  39. */
  40. public function testImPowerArray(array $expectedResult, string $complex, string $real): void
  41. {
  42. $calculation = Calculation::getInstance();
  43. $formula = "=IMPOWER({$complex}, {$real})";
  44. $result = $calculation->_calculateFormulaValue($formula);
  45. self::assertEquals($expectedResult, $result);
  46. }
  47. public function providerImPowerArray(): array
  48. {
  49. return [
  50. 'matrix' => [
  51. [
  52. ['-5.25+5i', '-2.8702659355016E-15+15.625i', '2.5625+52.5i'],
  53. ['-3.6739403974421E-16+2i', '-1.836970198721E-16+i', '-4-4.8985871965894E-16i'],
  54. ['-3.6739403974421E-16-2i', '-1.836970198721E-16-i', '-4+4.8985871965894E-16i'],
  55. ['-5.25-5i', '-2.8702659355016E-15-15.625i', '2.5625-52.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, 3, 4}',
  59. ],
  60. ];
  61. }
  62. }