PriceTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 PriceTest extends TestCase
  7. {
  8. protected function setUp(): void
  9. {
  10. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  11. }
  12. /**
  13. * @dataProvider providerPRICE
  14. *
  15. * @param mixed $expectedResult
  16. */
  17. public function testPRICE($expectedResult, ...$args): void
  18. {
  19. $result = Financial::PRICE(...$args);
  20. self::assertEqualsWithDelta($expectedResult, $result, 1E-7);
  21. }
  22. public function providerPRICE(): array
  23. {
  24. return require 'tests/data/Calculation/Financial/PRICE.php';
  25. }
  26. /**
  27. * @dataProvider providerPRICE3
  28. *
  29. * @param mixed $expectedResult
  30. */
  31. public function testPRICE3($expectedResult, ...$args): void
  32. {
  33. // These results (PRICE function with basis codes 2 and 3)
  34. // agree with published algorithm, LibreOffice, and Gnumeric.
  35. // They do not agree with Excel.
  36. $result = Financial::PRICE(...$args);
  37. self::assertEqualsWithDelta($expectedResult, $result, 1E-7);
  38. }
  39. public function providerPRICE3(): array
  40. {
  41. return require 'tests/data/Calculation/Financial/PRICE3.php';
  42. }
  43. }