OddTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. class OddTest extends AllSetupTeardown
  5. {
  6. /**
  7. * @dataProvider providerODD
  8. *
  9. * @param mixed $expectedResult
  10. * @param mixed $value
  11. */
  12. public function testODD($expectedResult, $value): void
  13. {
  14. $this->mightHaveException($expectedResult);
  15. $sheet = $this->getSheet();
  16. $sheet->getCell('A1')->setValue("=ODD($value)");
  17. $sheet->getCell('A2')->setValue(3.7);
  18. self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
  19. }
  20. public function providerODD(): array
  21. {
  22. return require 'tests/data/Calculation/MathTrig/ODD.php';
  23. }
  24. /**
  25. * @dataProvider providerOddArray
  26. */
  27. public function testOddArray(array $expectedResult, string $array): void
  28. {
  29. $calculation = Calculation::getInstance();
  30. $formula = "=ODD({$array})";
  31. $result = $calculation->_calculateFormulaValue($formula);
  32. self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
  33. }
  34. public function providerOddArray(): array
  35. {
  36. return [
  37. 'row vector' => [[[-3, 1, 5]], '{-3, 1, 4}'],
  38. 'column vector' => [[[-3], [1], [5]], '{-3; 1; 4}'],
  39. 'matrix' => [[[-3, 1], [5, 3]], '{-3, 1; 4, 1.5}'],
  40. ];
  41. }
  42. }