BitAndTest.php 1.7 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 BitAndTest extends TestCase
  8. {
  9. /**
  10. * @dataProvider providerBITAND
  11. *
  12. * @param mixed $expectedResult
  13. */
  14. public function testBITAND($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', 24);
  22. $sheet->getCell('A1')->setValue("=BITAND($formula)");
  23. $result = $sheet->getCell('A1')->getCalculatedValue();
  24. self::assertEquals($expectedResult, $result);
  25. }
  26. public function providerBITAND(): array
  27. {
  28. return require 'tests/data/Calculation/Engineering/BITAND.php';
  29. }
  30. /**
  31. * @dataProvider providerBitAndArray
  32. */
  33. public function testBitAndArray(array $expectedResult, string $number1, string $number2): void
  34. {
  35. $calculation = Calculation::getInstance();
  36. $formula = "=BITAND({$number1}, {$number2})";
  37. $result = $calculation->_calculateFormulaValue($formula);
  38. self::assertEquals($expectedResult, $result);
  39. }
  40. public function providerBitAndArray(): array
  41. {
  42. return [
  43. 'row/column vector' => [
  44. [
  45. [3, 0, 1],
  46. [4, 0, 0],
  47. [5, 0, 1],
  48. ],
  49. '{7, 8, 9}',
  50. '{3; 4; 5}',
  51. ],
  52. ];
  53. }
  54. }