Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2DecTest.php
T
oleibman d93a303371 Fix Unintential Deprecated Calls in Tests - ENGINEERING (#3176)
* 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.
2022-11-24 07:57:41 -08:00

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 Oct2DecTest extends TestCase
{
/**
* @var string
*/
private $compatibilityMode;
protected function setUp(): void
{
$this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
}
/**
* @dataProvider providerOCT2DEC
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testOCT2DEC($expectedResult, $formula): void
{
if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 101);
$sheet->getCell('A1')->setValue("=OCT2DEC($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public function providerOCT2DEC(): array
{
return require 'tests/data/Calculation/Engineering/OCT2DEC.php';
}
/**
* @dataProvider providerOCT2DEC
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testOCT2DECOds($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("=OCT2DEC($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public function testOCT2DECFrac(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$cell = 'G1';
$sheet->setCellValue($cell, '=OCT2DEC(10.1)');
self::assertEquals(8, $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$cell = 'O1';
$sheet->setCellValue($cell, '=OCT2DEC(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
$cell = 'E1';
$sheet->setCellValue($cell, '=OCT2DEC(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
$spreadsheet->disconnectWorksheets();
}
/**
* @dataProvider providerOct2DecArray
*/
public function testOct2DecArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();
$formula = "=OCT2DEC({$value})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerOct2DecArray(): array
{
return [
'row/column vector' => [
[[4, 7, 63, 153, 204, 341]],
'{"4", "7", "77", "231", "314", "525"}',
],
];
}
}