91 lines
3.0 KiB
PHP
91 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class Oct2HexTest extends TestCase
|
|
{
|
|
private $compatibilityMode;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->compatibilityMode = Functions::getCompatibilityMode();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Functions::setCompatibilityMode($this->compatibilityMode);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerOCT2HEX
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param mixed $formula
|
|
*/
|
|
public function testOCT2HEX($expectedResult, $formula): void
|
|
{
|
|
if ($expectedResult === 'exception') {
|
|
$this->expectException(CalcExp::class);
|
|
}
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->setCellValue('A2', 101);
|
|
$sheet->getCell('A1')->setValue("=OCT2HEX($formula)");
|
|
$result = $sheet->getCell('A1')->getCalculatedValue();
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function providerOCT2HEX()
|
|
{
|
|
return require 'tests/data/Calculation/Engineering/OCT2HEX.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerOCT2HEX
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param mixed $formula
|
|
*/
|
|
public function testOCT2HEXOds($expectedResult, $formula): void
|
|
{
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
|
|
if ($expectedResult === 'exception') {
|
|
$this->expectException(CalcExp::class);
|
|
}
|
|
if ($formula === 'true') {
|
|
$expectedResult = 1;
|
|
} elseif ($formula === 'false') {
|
|
$expectedResult = 0;
|
|
}
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
$sheet->setCellValue('A2', 101);
|
|
$sheet->getCell('A1')->setValue("=OCT2HEX($formula)");
|
|
$result = $sheet->getCell('A1')->getCalculatedValue();
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function testOCT2HEXFrac(): void
|
|
{
|
|
$spreadsheet = new Spreadsheet();
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
|
|
$cell = 'G1';
|
|
$sheet->setCellValue($cell, '=OCT2HEX(20.1)');
|
|
self::assertEquals(10, $sheet->getCell($cell)->getCalculatedValue());
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
|
|
$cell = 'O1';
|
|
$sheet->setCellValue($cell, '=OCT2HEX(20.1)');
|
|
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
$cell = 'E1';
|
|
$sheet->setCellValue($cell, '=OCT2HEX(20.1)');
|
|
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
|
|
}
|
|
}
|