IrrTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
  3. class IrrTest extends AllSetupTeardown
  4. {
  5. /**
  6. * @dataProvider providerIRR
  7. *
  8. * @param mixed $expectedResult
  9. * @param mixed $values
  10. */
  11. public function testIRR($expectedResult, $values = null): void
  12. {
  13. $this->mightHaveException($expectedResult);
  14. $sheet = $this->getSheet();
  15. $formula = '=IRR(';
  16. if ($values !== null) {
  17. if (is_array($values)) {
  18. $row = 0;
  19. foreach ($values as $value) {
  20. if (is_array($value)) {
  21. foreach ($value as $arrayValue) {
  22. ++$row;
  23. $sheet->getCell("A$row")->setValue($arrayValue);
  24. }
  25. } else {
  26. ++$row;
  27. $sheet->getCell("A$row")->setValue($value);
  28. }
  29. }
  30. $formula .= "A1:A$row";
  31. } else {
  32. $sheet->getCell('A1')->setValue($values);
  33. $formula .= 'A1';
  34. }
  35. }
  36. $formula .= ')';
  37. $sheet->getCell('D1')->setValue($formula);
  38. $result = $sheet->getCell('D1')->getCalculatedValue();
  39. $this->adjustResult($result, $expectedResult);
  40. self::assertEqualsWithDelta($expectedResult, $result, 0.1E-8);
  41. }
  42. public function providerIRR(): array
  43. {
  44. return require 'tests/data/Calculation/Financial/IRR.php';
  45. }
  46. }