XNpvTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Financial;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  5. use PHPUnit\Framework\TestCase;
  6. class XNpvTest extends TestCase
  7. {
  8. protected function setUp(): void
  9. {
  10. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  11. }
  12. /**
  13. * @dataProvider providerXNPV
  14. *
  15. * @param mixed $expectedResult
  16. * @param mixed $message
  17. */
  18. public function testXNPV($expectedResult, $message, ...$args): void
  19. {
  20. $result = Financial::XNPV(...$args);
  21. if (is_numeric($result) && is_numeric($expectedResult)) {
  22. if ($expectedResult != 0) {
  23. $frac = $result / $expectedResult;
  24. if ($frac > 0.999999 && $frac < 1.000001) {
  25. $result = $expectedResult;
  26. }
  27. }
  28. }
  29. self::assertEquals($expectedResult, $result, $message);
  30. }
  31. public function providerXNPV(): array
  32. {
  33. return require 'tests/data/Calculation/Financial/XNPV.php';
  34. }
  35. }