mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-03 14:10:27 +00:00
d93a303371
* Fix Unintential Deprecated Calls in Tests - ENGINEERING I think it's best to install these before PR #3166. There are no changes to source code, only to test members which continue to inadvertently use calls to deprecated functions. * Fix deprecation DocBlocks Deprecated->deprecated, adjust see and comments * Fix Deliberate Deprecated Tests Add annotations. * Run Unit Tests in Spreadsheet Context This turned up only one error, in IMSUB. The only group that still needs this is Statistical. Not sure if I will get to that quickly.
120 lines
3.8 KiB
PHP
120 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class Dec2BinTest extends TestCase
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $compatibilityMode;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->compatibilityMode = Functions::getCompatibilityMode();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Functions::setCompatibilityMode($this->compatibilityMode);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerDEC2BIN
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param mixed $formula
|
|
*/
|
|
public function testDEC2BIN($expectedResult, $formula): void
|
|
{
|
|
if ($expectedResult === 'exception') {
|
|
$this->expectException(CalcExp::class);
|
|
}
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->setCellValue('A2', 5);
|
|
$sheet->getCell('A1')->setValue("=DEC2BIN($formula)");
|
|
$result = $sheet->getCell('A1')->getCalculatedValue();
|
|
self::assertEquals($expectedResult, $result);
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
public function providerDEC2BIN(): array
|
|
{
|
|
return require 'tests/data/Calculation/Engineering/DEC2BIN.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerDEC2BIN
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param mixed $formula
|
|
*/
|
|
public function testDEC2BINOds($expectedResult, $formula): void
|
|
{
|
|
if ($expectedResult === 'exception') {
|
|
$this->expectException(CalcExp::class);
|
|
}
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
|
|
if ($formula === 'true') {
|
|
$expectedResult = 1;
|
|
} elseif ($formula === 'false') {
|
|
$expectedResult = 0;
|
|
}
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->setCellValue('A2', 5);
|
|
$sheet->getCell('A1')->setValue("=DEC2BIN($formula)");
|
|
$result = $sheet->getCell('A1')->getCalculatedValue();
|
|
self::assertEquals($expectedResult, $result);
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
public function testDEC2BINFrac(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
|
|
$cell = 'G1';
|
|
$sheet->setCellValue($cell, '=DEC2BIN(5.1)');
|
|
self::assertEquals(101, $sheet->getCell($cell)->getCalculatedValue(), 'Gnumeric');
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
|
|
$cell = 'O1';
|
|
$sheet->setCellValue($cell, '=DEC2BIN(5.1)');
|
|
self::assertEquals(101, $sheet->getCell($cell)->getCalculatedValue(), 'Ods');
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
$cell = 'E1';
|
|
$sheet->setCellValue($cell, '=DEC2BIN(5.1)');
|
|
self::assertEquals(101, $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerDec2BinArray
|
|
*/
|
|
public function testDec2BinArray(array $expectedResult, string $value): void
|
|
{
|
|
$calculation = Calculation::getInstance();
|
|
|
|
$formula = "=DEC2BIN({$value})";
|
|
$result = $calculation->_calculateFormulaValue($formula);
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function providerDec2BinArray(): array
|
|
{
|
|
return [
|
|
'row/column vector' => [
|
|
[['100', '111', '111111', '10011001', '11001100', '101010101']],
|
|
'{4, 7, 63, 153, 204, 341}',
|
|
],
|
|
];
|
|
}
|
|
}
|