SignTest.php 1.5 KB

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