BitRShiftTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
  5. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  6. use PHPUnit\Framework\TestCase;
  7. class BitRShiftTest extends TestCase
  8. {
  9. /**
  10. * @dataProvider providerBITRSHIFT
  11. *
  12. * @param mixed $expectedResult
  13. */
  14. public function testBITRSHIFT($expectedResult, string $formula): void
  15. {
  16. if ($expectedResult === 'exception') {
  17. $this->expectException(CalcExp::class);
  18. }
  19. $spreadsheet = new Spreadsheet();
  20. $sheet = $spreadsheet->getActiveSheet();
  21. $sheet->setCellValue('A2', 8);
  22. $sheet->getCell('A1')->setValue("=BITRSHIFT($formula)");
  23. $result = $sheet->getCell('A1')->getCalculatedValue();
  24. self::assertEquals($expectedResult, $result);
  25. }
  26. public function providerBITRSHIFT(): array
  27. {
  28. return require 'tests/data/Calculation/Engineering/BITRSHIFT.php';
  29. }
  30. /**
  31. * @dataProvider providerBitRShiftArray
  32. */
  33. public function testBitRShiftArray(array $expectedResult, string $number, string $bits): void
  34. {
  35. $calculation = Calculation::getInstance();
  36. $formula = "=BITRSHIFT({$number}, {$bits})";
  37. $result = $calculation->_calculateFormulaValue($formula);
  38. self::assertEquals($expectedResult, $result);
  39. }
  40. public function providerBitRShiftArray(): array
  41. {
  42. return [
  43. 'row/column vector' => [
  44. [
  45. [31, 15, 7, 3, 1],
  46. [32, 16, 8, 4, 2],
  47. [37, 18, 9, 4, 2],
  48. ],
  49. '{63; 64; 75}',
  50. '{1, 2, 3, 4, 5}',
  51. ],
  52. ];
  53. }
  54. }