Improve Coverage of BIN2DEC etc. (#1902)

* Improve Coverage of BIN2DEC etc.

The following functions have some special handling
depending on the Calculation mode:
- BIN2DEC
- BIN2HEX
- BIN2OCT
- DEC2BIN
- DEC2HEX
- DEC2OCT
- HEX2BIN
- HEX2DEC
- HEX2OCT
- OCT2BIN
- OCT2DEC
- OCT2HEX

Ods accepts boolean for its numeric argument.
This had already been coded, but there were no tests for it.

Gnumeric allows the use of non-integer argument where Excel/Ods do not.
The existing code allowed this for certain functions but not for others.
Gnumeric consistently allows it, so there is no need for parameter
gnumericCheck in convertBase::ValidateValue.
Again, there were no tests for this.

There were some minor changes needed:
- In functions where you are allowed to specify the numnber of "places" in the
result, there is an upper bound of 10 which had not been enforced.
- Negative values were not handled correctly in some cases.
- There was at least one (avoidable) error on a 32-bit system.
- Some upper and lower bounds were not being enforced. In addition to enforcing
those, the bounds are now defined as class constants in ConvertDecimal.

Many tests have been added, so that Engineering is now almost 100% covered.
The exception is some BESSEL code. There have been some recent changes to
BESSEL which are not yet part of my fork, so I could not address those now.
However, I freely admit that, when I looked at the uncovered portion, it seemed
like it might be a difficult task, so I probably wouldn't have tackled it anyhow.
In particular, the uncovered code seemed to deal with very large numbers,
and, although PhpSpreadsheet and Excel both give very large results for these
conditions, their answers are not particularly close to each other. I think
we're dealing with resuts approaching infinity. More study is needed.
This commit is contained in:
oleibman 2021-03-14 12:04:50 -07:00 committed by GitHub
parent 7e071e8abc
commit d99a4a3fac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 1179 additions and 792 deletions

View File

@ -7,7 +7,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class ConvertBase class ConvertBase
{ {
protected static function validateValue($value, bool $gnumericCheck = false): string protected static function validateValue($value): string
{ {
if (is_bool($value)) { if (is_bool($value)) {
if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) { if (Functions::getCompatibilityMode() !== Functions::COMPATIBILITY_OPENOFFICE) {
@ -16,8 +16,10 @@ class ConvertBase
$value = (int) $value; $value = (int) $value;
} }
if ($gnumericCheck && Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) { if (is_numeric($value)) {
$value = floor((float) $value); if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
$value = floor((float) $value);
}
} }
return strtoupper((string) $value); return strtoupper((string) $value);
@ -30,7 +32,7 @@ class ConvertBase
} }
if (is_numeric($places)) { if (is_numeric($places)) {
if ($places < 0) { if ($places < 0 || $places > 10) {
throw new Exception(Functions::NAN()); throw new Exception(Functions::NAN());
} }

View File

@ -25,7 +25,7 @@ class ConvertBinary extends ConvertBase
public static function toDecimal($value): string public static function toDecimal($value): string
{ {
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value), true); $value = self::validateValue(Functions::flattenSingleValue($value));
$value = self::validateBinary($value); $value = self::validateBinary($value);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
@ -65,7 +65,7 @@ class ConvertBinary extends ConvertBase
public static function toHex($value, $places = null): string public static function toHex($value, $places = null): string
{ {
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value), true); $value = self::validateValue(Functions::flattenSingleValue($value));
$value = self::validateBinary($value); $value = self::validateBinary($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces(Functions::flattenSingleValue($places));
} catch (Exception $e) { } catch (Exception $e) {
@ -73,8 +73,11 @@ class ConvertBinary extends ConvertBase
} }
if (strlen($value) == 10) { if (strlen($value) == 10) {
// Two's Complement $high2 = substr($value, 0, 2);
return str_repeat('F', 8) . substr(strtoupper(dechex((int) bindec(substr($value, -9)))), -2); $low8 = substr($value, 2);
$xarr = ['00' => '00000000', '01' => '00000001', '10' => 'FFFFFFFE', '11' => 'FFFFFFFF'];
return $xarr[$high2] . strtoupper(substr('0' . dechex((int) bindec($low8)), -2));
} }
$hexVal = (string) strtoupper(dechex((int) bindec($value))); $hexVal = (string) strtoupper(dechex((int) bindec($value)));
@ -105,16 +108,15 @@ class ConvertBinary extends ConvertBase
public static function toOctal($value, $places = null): string public static function toOctal($value, $places = null): string
{ {
try { try {
$value = self::validateValue(Functions::flattenSingleValue($value), true); $value = self::validateValue(Functions::flattenSingleValue($value));
$value = self::validateBinary($value); $value = self::validateBinary($value);
$places = self::validatePlaces(Functions::flattenSingleValue($places)); $places = self::validatePlaces(Functions::flattenSingleValue($places));
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
if (strlen($value) == 10) { if (strlen($value) == 10 && substr($value, 0, 1) === '1') { // Two's Complement
// Two's Complement return str_repeat('7', 6) . strtoupper(decoct((int) bindec("11$value")));
return str_repeat('7', 7) . substr(strtoupper(decoct((int) bindec(substr($value, -9)))), -3);
} }
$octVal = (string) decoct((int) bindec($value)); $octVal = (string) decoct((int) bindec($value));

View File

@ -7,6 +7,13 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class ConvertDecimal extends ConvertBase class ConvertDecimal extends ConvertBase
{ {
const LARGEST_OCTAL_IN_DECIMAL = 536870911;
const SMALLEST_OCTAL_IN_DECIMAL = -536870912;
const LARGEST_BINARY_IN_DECIMAL = 511;
const SMALLEST_BINARY_IN_DECIMAL = -512;
const LARGEST_HEX_IN_DECIMAL = 549755813887;
const SMALLEST_HEX_IN_DECIMAL = -549755813888;
/** /**
* toBinary. * toBinary.
* *
@ -43,16 +50,13 @@ class ConvertDecimal extends ConvertBase
} }
$value = (int) floor((float) $value); $value = (int) floor((float) $value);
if ($value < -512 || $value > 511) { if ($value > self::LARGEST_BINARY_IN_DECIMAL || $value < self::SMALLEST_BINARY_IN_DECIMAL) {
return Functions::NAN(); return Functions::NAN();
} }
$r = decbin($value); $r = decbin($value);
// Two's Complement // Two's Complement
$r = substr($r, -10); $r = substr($r, -10);
if (strlen($r) >= 11) {
return Functions::NAN();
}
return self::nbrConversionFormat($r, $places); return self::nbrConversionFormat($r, $places);
} }
@ -92,16 +96,37 @@ class ConvertDecimal extends ConvertBase
return $e->getMessage(); return $e->getMessage();
} }
$value = (int) floor((float) $value); $value = floor((float) $value);
$r = strtoupper(dechex($value)); if ($value > self::LARGEST_HEX_IN_DECIMAL || $value < self::SMALLEST_HEX_IN_DECIMAL) {
if (strlen($r) == 8) { return Functions::NAN();
// Two's Complement
$r = 'FF' . $r;
} }
$r = strtoupper(dechex((int) $value));
$r = self::hex32bit($value, $r);
return self::nbrConversionFormat($r, $places); return self::nbrConversionFormat($r, $places);
} }
public static function hex32bit(float $value, string $hexstr, bool $force = false): string
{
if (PHP_INT_SIZE === 4 || $force) {
if ($value >= 2 ** 32) {
$quotient = (int) ($value / (2 ** 32));
return strtoupper(substr('0' . dechex($quotient), -2) . $hexstr);
}
if ($value < -(2 ** 32)) {
$quotient = 256 - (int) ceil((-$value) / (2 ** 32));
return strtoupper(substr('0' . dechex($quotient), -2) . substr("00000000$hexstr", -8));
}
if ($value < 0) {
return "FF$hexstr";
}
}
return $hexstr;
}
/** /**
* toOctal. * toOctal.
* *
@ -138,11 +163,11 @@ class ConvertDecimal extends ConvertBase
} }
$value = (int) floor((float) $value); $value = (int) floor((float) $value);
$r = decoct($value); if ($value > self::LARGEST_OCTAL_IN_DECIMAL || $value < self::SMALLEST_OCTAL_IN_DECIMAL) {
if (strlen($r) == 11) { return Functions::NAN();
// Two's Complement
$r = substr($r, -10);
} }
$r = decoct($value);
$r = substr($r, -10);
return self::nbrConversionFormat($r, $places); return self::nbrConversionFormat($r, $places);
} }

View File

@ -42,7 +42,9 @@ class ConvertHex extends ConvertBase
return $e->getMessage(); return $e->getMessage();
} }
return ConvertDecimal::toBinary(self::toDecimal($value), $places); $dec = self::toDecimal($value);
return ConvertDecimal::toBinary($dec, $places);
} }
/** /**
@ -129,9 +131,6 @@ class ConvertHex extends ConvertBase
} }
$decimal = self::toDecimal($value); $decimal = self::toDecimal($value);
if ($decimal < -536870912 || $decimal > 536870911) {
return Functions::NAN();
}
return ConvertDecimal::toOctal($decimal, $places); return ConvertDecimal::toOctal($decimal, $places);
} }

View File

@ -127,14 +127,16 @@ class ConvertOctal extends ConvertBase
return $e->getMessage(); return $e->getMessage();
} }
$hexVal = strtoupper(dechex((int) self::toDecimal((int) $value))); $hexVal = strtoupper(dechex((int) self::toDecimal($value)));
$hexVal = (PHP_INT_SIZE === 4 && strlen($value) === 10 && $value[0] >= '4') ? "FF$hexVal" : $hexVal;
return self::nbrConversionFormat($hexVal, $places); return self::nbrConversionFormat($hexVal, $places);
} }
protected static function validateOctal(string $value): string protected static function validateOctal(string $value): string
{ {
if (strlen($value) > preg_match_all('/[01234567]/', $value)) { $numDigits = (int) preg_match_all('/[01234567]/', $value);
if (strlen($value) > $numDigits || $numDigits > 10) {
throw new Exception(Functions::NAN()); throw new Exception(Functions::NAN());
} }

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Bin2DecTest extends TestCase class Bin2DecTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerBIN2DEC * @dataProvider providerBIN2DEC
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testBIN2DEC($expectedResult, ...$args): void public function testBin2Dec($expectedResult, $formula): void
{ {
$result = Engineering::BINTODEC(...$args); if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 101);
$sheet->getCell('A1')->setValue("=BIN2DEC($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,47 @@ class Bin2DecTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BIN2DEC.php'; return require 'tests/data/Calculation/Engineering/BIN2DEC.php';
} }
/**
* @dataProvider providerBIN2DEC
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testBIN2DECOds($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', 101);
$sheet->getCell('A1')->setValue("=BIN2DEC($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public function testBIN2DECFrac(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$cell = 'G1';
$sheet->setCellValue($cell, '=BIN2DEC(101.1)');
self::assertEquals(5, $sheet->getCell($cell)->getCalculatedValue(), 'Gnumeric');
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$cell = 'O1';
$sheet->setCellValue($cell, '=BIN2DEC(101.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Ods');
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
$cell = 'E1';
$sheet->setCellValue($cell, '=BIN2DEC(101.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
}
} }

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Bin2HexTest extends TestCase class Bin2HexTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerBIN2HEX * @dataProvider providerBIN2HEX
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testBIN2HEX($expectedResult, ...$args): void public function testBin2Hex($expectedResult, $formula): void
{ {
$result = Engineering::BINTOHEX(...$args); if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 101);
$sheet->getCell('A1')->setValue("=BIN2HEX($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,47 @@ class Bin2HexTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BIN2HEX.php'; return require 'tests/data/Calculation/Engineering/BIN2HEX.php';
} }
/**
* @dataProvider providerBIN2HEX
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testBIN2HEXOds($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', 101);
$sheet->getCell('A1')->setValue("=BIN2HEX($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public function testBIN2HEXFrac(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$cell = 'G1';
$sheet->setCellValue($cell, '=BIN2HEX(101.1)');
self::assertEquals(5, $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$cell = 'O1';
$sheet->setCellValue($cell, '=BIN2HEX(101.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
$cell = 'E1';
$sheet->setCellValue($cell, '=BIN2HEX(101.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
}
} }

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Bin2OctTest extends TestCase class Bin2OctTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerBIN2OCT * @dataProvider providerBIN2OCT
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testBIN2OCT($expectedResult, ...$args): void public function testBin2Oct($expectedResult, $formula): void
{ {
$result = Engineering::BINTOOCT(...$args); if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 101);
$sheet->getCell('A1')->setValue("=BIN2OCT($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,47 @@ class Bin2OctTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/BIN2OCT.php'; return require 'tests/data/Calculation/Engineering/BIN2OCT.php';
} }
/**
* @dataProvider providerBIN2OCT
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testBIN2OCTOds($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', 101);
$sheet->getCell('A1')->setValue("=BIN2OCT($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public function testBIN2OCTFrac(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$cell = 'G1';
$sheet->setCellValue($cell, '=BIN2OCT(101.1)');
self::assertEquals(5, $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$cell = 'O1';
$sheet->setCellValue($cell, '=BIN2OCT(101.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
$cell = 'E1';
$sheet->setCellValue($cell, '=BIN2OCT(101.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
}
} }

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Dec2BinTest extends TestCase class Dec2BinTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerDEC2BIN * @dataProvider providerDEC2BIN
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testDEC2BIN($expectedResult, ...$args): void public function testDEC2BIN($expectedResult, $formula): void
{ {
$result = Engineering::DECTOBIN(...$args); 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); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,47 @@ class Dec2BinTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/DEC2BIN.php'; 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);
}
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');
}
} }

View File

@ -3,24 +3,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Dec2HexTest extends TestCase class Dec2HexTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerDEC2HEX * @dataProvider providerDEC2HEX
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testDEC2HEX($expectedResult, ...$args): void public function testDEC2HEX($expectedResult, $formula): void
{ {
$result = Engineering::DECTOHEX(...$args); if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 17);
$sheet->getCell('A1')->setValue("=DEC2HEX($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +45,54 @@ class Dec2HexTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/DEC2HEX.php'; return require 'tests/data/Calculation/Engineering/DEC2HEX.php';
} }
/**
* @dataProvider providerDEC2HEX
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testDEC2HEXOds($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', 17);
$sheet->getCell('A1')->setValue("=DEC2HEX($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public function testDEC2HEXFrac(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$cell = 'G1';
$sheet->setCellValue($cell, '=DEC2HEX(17.1)');
self::assertEquals(11, $sheet->getCell($cell)->getCalculatedValue(), 'Gnumeric');
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$cell = 'O1';
$sheet->setCellValue($cell, '=DEC2HEX(17.1)');
self::assertEquals(11, $sheet->getCell($cell)->getCalculatedValue(), 'Ods');
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
$cell = 'E1';
$sheet->setCellValue($cell, '=DEC2HEX(17.1)');
self::assertEquals(11, $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
}
public function test32bitHex(): void
{
self::assertEquals('A2DE246000', Engineering\ConvertDecimal::hex32bit(-400000000000, 'DE246000', true));
self::assertEquals('7FFFFFFFFF', Engineering\ConvertDecimal::hex32bit(549755813887, 'FFFFFFFF', true));
self::assertEquals('FFFFFFFFFF', Engineering\ConvertDecimal::hex32bit(-1, 'FFFFFFFF', true));
}
} }

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Dec2OctTest extends TestCase class Dec2OctTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerDEC2OCT * @dataProvider providerDEC2OCT
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testDEC2OCT($expectedResult, ...$args): void public function testDEC2OCT($expectedResult, $formula): void
{ {
$result = Engineering::DECTOOCT(...$args); if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 17);
$sheet->getCell('A1')->setValue("=DEC2OCT($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,47 @@ class Dec2OctTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/DEC2OCT.php'; return require 'tests/data/Calculation/Engineering/DEC2OCT.php';
} }
/**
* @dataProvider providerDEC2OCT
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testDEC2OCTOds($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', 17);
$sheet->getCell('A1')->setValue("=DEC2OCT($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public function testDEC2OCTFrac(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$cell = 'G1';
$sheet->setCellValue($cell, '=DEC2OCT(17.1)');
self::assertEquals(21, $sheet->getCell($cell)->getCalculatedValue(), 'Gnumeric');
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$cell = 'O1';
$sheet->setCellValue($cell, '=DEC2OCT(17.1)');
self::assertEquals(21, $sheet->getCell($cell)->getCalculatedValue(), 'Ods');
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
$cell = 'E1';
$sheet->setCellValue($cell, '=DEC2OCT(17.1)');
self::assertEquals(21, $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
}
} }

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Hex2BinTest extends TestCase class Hex2BinTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerHEX2BIN * @dataProvider providerHEX2BIN
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testHEX2BIN($expectedResult, ...$args): void public function testHEX2BIN($expectedResult, $formula): void
{ {
$result = Engineering::HEXTOBIN(...$args); if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 'B');
$sheet->getCell('A1')->setValue("=HEX2BIN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,50 @@ class Hex2BinTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/HEX2BIN.php'; return require 'tests/data/Calculation/Engineering/HEX2BIN.php';
} }
/**
* @dataProvider providerHEX2BIN
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testHEX2BINOds($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', 'B');
$sheet->getCell('A1')->setValue("=HEX2BIN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public function testHEX2BINFrac(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$cell = 'G1';
$sheet->setCellValue($cell, '=HEX2BIN(10.1)');
self::assertEquals('10000', $sheet->getCell($cell)->getCalculatedValue());
$cell = 'F21';
$sheet->setCellValue($cell, '=HEX2BIN("A.1")');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$cell = 'O1';
$sheet->setCellValue($cell, '=HEX2BIN(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
$cell = 'E1';
$sheet->setCellValue($cell, '=HEX2BIN(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
}
} }

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Hex2DecTest extends TestCase class Hex2DecTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerHEX2DEC * @dataProvider providerHEX2DEC
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testHEX2DEC($expectedResult, ...$args): void public function testHEX2DEC($expectedResult, $formula): void
{ {
$result = Engineering::HEXTODEC(...$args); if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 'B');
$sheet->getCell('A1')->setValue("=HEX2DEC($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,50 @@ class Hex2DecTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/HEX2DEC.php'; return require 'tests/data/Calculation/Engineering/HEX2DEC.php';
} }
/**
* @dataProvider providerHEX2DEC
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testHEX2DECOds($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', 'B');
$sheet->getCell('A1')->setValue("=HEX2DEC($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public function testHEX2DECFrac(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$cell = 'G1';
$sheet->setCellValue($cell, '=HEX2DEC(10.1)');
self::assertEquals(16, $sheet->getCell($cell)->getCalculatedValue());
$cell = 'F21';
$sheet->setCellValue($cell, '=HEX2DEC("A.1")');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$cell = 'O1';
$sheet->setCellValue($cell, '=HEX2DEC(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
$cell = 'E1';
$sheet->setCellValue($cell, '=HEX2DEC(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
}
} }

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Hex2OctTest extends TestCase class Hex2OctTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerHEX2OCT * @dataProvider providerHEX2OCT
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testHEX2OCT($expectedResult, ...$args): void public function testHEX2OCT($expectedResult, $formula): void
{ {
$result = Engineering::HEXTOOCT(...$args); if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 'B');
$sheet->getCell('A1')->setValue("=HEX2OCT($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,47 @@ class Hex2OctTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/HEX2OCT.php'; return require 'tests/data/Calculation/Engineering/HEX2OCT.php';
} }
/**
* @dataProvider providerHEX2OCT
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testHEX2OCTOds($expectedResult, $formula): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
if ($formula === 'true') {
$expectedResult = 1;
} elseif ($formula === 'false') {
$expectedResult = 0;
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 'B');
$sheet->getCell('A1')->setValue("=HEX2OCT($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public function testHEX2OCTFrac(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$cell = 'G1';
$sheet->setCellValue($cell, '=HEX2OCT(10.1)');
self::assertEquals(20, $sheet->getCell($cell)->getCalculatedValue());
$cell = 'F21';
$sheet->setCellValue($cell, '=HEX2OCT("A.1")');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$cell = 'O1';
$sheet->setCellValue($cell, '=HEX2OCT(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
$cell = 'E1';
$sheet->setCellValue($cell, '=HEX2OCT(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue(), 'Excel');
}
} }

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
use PHPUnit\Framework\TestCase;
// Sanity tests for functions which have been moved out of Engineering
// to their own classes. A deprecated version remains in Engineering;
// this class contains cursory tests to ensure that those work properly.
// If Scrutinizer fails the PR because of these deprecations, I will
// remove this class from the PR.
class MovedFunctionsTest extends TestCase
{
public function testMovedFunctions(): void
{
self::assertEquals(178, Engineering::BINTODEC(10110010));
self::assertEquals('B2', Engineering::BINTOHEX(10110010));
self::assertEquals(144, Engineering::BINTOOCT(1100100));
self::assertEquals(101100101, Engineering::DECTOBIN(357));
self::assertEquals(165, Engineering::DECTOHEX(357));
self::assertEquals(545, Engineering::DECTOOCT(357));
self::assertEquals(1100100, Engineering::HEXTOBIN(64));
self::assertEquals(357, Engineering::HEXTODEC(165));
self::assertEquals(653, Engineering::HEXTOOCT('01AB'));
self::assertEquals(1100100, Engineering::OCTTOBIN(144));
self::assertEquals(357, Engineering::OCTTODEC(545));
self::assertEquals('1AB', Engineering::OCTTOHEX(653));
}
}

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Oct2BinTest extends TestCase class Oct2BinTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerOCT2BIN * @dataProvider providerOCT2BIN
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testOCT2BIN($expectedResult, ...$args): void public function testOCT2BIN($expectedResult, $formula): void
{ {
$result = Engineering::OCTTOBIN(...$args); if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 101);
$sheet->getCell('A1')->setValue("=OCT2BIN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,47 @@ class Oct2BinTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/OCT2BIN.php'; return require 'tests/data/Calculation/Engineering/OCT2BIN.php';
} }
/**
* @dataProvider providerOCT2BIN
*
* @param mixed $expectedResult
* @param mixed $formula
*/
public function testOCT2BINOds($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("=OCT2BIN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public function testOCT2BINFrac(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
$cell = 'G1';
$sheet->setCellValue($cell, '=HEX2BIN(10.1)');
self::assertEquals('10000', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$cell = 'O1';
$sheet->setCellValue($cell, '=OCT2BIN(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
$cell = 'E1';
$sheet->setCellValue($cell, '=OCT2BIN(10.1)');
self::assertEquals('#NUM!', $sheet->getCell($cell)->getCalculatedValue());
}
} }

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Oct2DecTest extends TestCase class Oct2DecTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerOCT2DEC * @dataProvider providerOCT2DEC
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testOCT2DEC($expectedResult, ...$args): void public function testOCT2DEC($expectedResult, $formula): void
{ {
$result = Engineering::OCTTODEC(...$args); 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); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,47 @@ class Oct2DecTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/OCT2DEC.php'; 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);
}
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());
}
} }

View File

@ -2,25 +2,41 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
use PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class Oct2HexTest extends TestCase class Oct2HexTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
} }
/** /**
* @dataProvider providerOCT2HEX * @dataProvider providerOCT2HEX
* *
* @param mixed $expectedResult * @param mixed $expectedResult
* @param mixed $formula
*/ */
public function testOCT2HEX($expectedResult, ...$args): void public function testOCT2HEX($expectedResult, $formula): void
{ {
$result = Engineering::OCTTOHEX(...$args); 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); self::assertEquals($expectedResult, $result);
} }
@ -28,4 +44,47 @@ class Oct2HexTest extends TestCase
{ {
return require 'tests/data/Calculation/Engineering/OCT2HEX.php'; 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());
}
} }

View File

@ -1,49 +1,26 @@
<?php <?php
return [ return [
[ ['178', '10110010'],
'178', ['100', '1100100'],
'10110010', ['#NUM!', '111001010101'], // Too large
], ['5', '101'],
[ ['2', '10'],
'100', ['0', '0'],
'1100100', ['#NUM!', '21'], // Invalid binary number
], ['#VALUE!', 'true'], // Boolean okay for ODS, not for Excel/Gnumeric
// Too large ['#VALUE!', 'false'], // Boolean okay for ODS, not for Excel/Gnumeric
[ ['-107', '1110010101'], // 2's Complement
'#NUM!', ['-1', '1111111111'], // 2's Complement
'111001010101', ['-512', '1000000000'], // lowest negative
], ['511', '111111111'], // highest positive
[ ['0', '0000000000'],
'5', ['1', '000000001'],
'101', ['256', '0100000000'],
], ['256', '100000000'],
[ ['-256', '1100000000'],
'2', [5, 'A2'],
'10', ['#NUM!', '"A2"'],
], [0, 'A3'],
[ ['exception', ''],
'0',
'0',
],
// Invalid binary number
[
'#NUM!',
'21',
],
// Non string
[
'#VALUE!',
true,
],
// 2's Complement
[
'-107',
'1110010101',
],
// 2's Complement
[
'-1',
'1111111111',
],
]; ];

View File

@ -1,73 +1,36 @@
<?php <?php
return [ return [
[ ['B2', '10110010'],
'B2', ['#NUM!', '111001010101'], // Too large
'10110010', ['00FB', '11111011, 4'], // Leading places
], ['0FB', '11111011, 3.75'], // Leading places as a float
// Too large ['#NUM!', '11111011, -1'], // Leading places negative
[ ['#VALUE!', '11111011, "ABC"'], // Leading places non-numeric
'#NUM!', ['E', '"1110"'],
'111001010101', ['5', '101'],
], ['2', '10'],
// Leading places ['0', '0'],
[ ['#NUM!', '21'], // Invalid binary number
'00FB', ['#VALUE!', 'true'], // ODS accepts Boolean, Excel/Gnumeric don't
'11111011', ['#VALUE!', 'false'], // ODS accepts Boolean, Excel/Gnumeric don't
4, ['FFFFFFFF95', '1110010101'], // 2's Complement
], ['FFFFFFFFFF', '1111111111'], // 2's Complement
// Leading places as a float ['FFFFFFFE00', '1000000000'], // lowest negative
[ ['1FF', '111111111'], // highest positive
'0FB', ['0', '0000000000'],
'11111011', ['1', '000000001'],
3.75, ['100', '0100000000'],
], ['100', '100000000'],
// Leading places negative ['FFFFFFFF00', '1100000000'],
[ ['0003', '11, 4'],
'#NUM!', ['#NUM!', '11, 0'],
'11111011', ['#NUM!', '11, -1'],
-1, ['#NUM!', '11, 14'],
], ['#NUM!', '10001, 1'],
// Leading places non-numeric ['11', '10001, 2'],
[ [5, 'A2'],
'#VALUE!', ['#NUM!', '"A2"'],
'11111011', [0, 'A3'],
'ABC', ['exception', ''],
],
[
'E',
'1110',
],
[
'5',
'101',
],
[
'2',
'10',
],
[
'0',
'0',
],
// Invalid binary number
[
'#NUM!',
'21',
],
// Non string
[
'#VALUE!',
true,
],
// 2's Complement
[
'FFFFFFFF95',
'1110010101',
],
// 2's Complement
[
'FFFFFFFFFF',
'1111111111',
],
]; ];

View File

@ -1,77 +1,37 @@
<?php <?php
return [ return [
[ ['144', 1100100],
'144', ['262', '10110010'],
'1100100', ['#NUM!', '111001010101'], // Too large
], ['011', '1001, 3'], // Leading places
[ ['0011', '1001, 4.75'], // Leading places as a float
'262', ['#NUM!', '1001, -1'], // Leading places negative
'10110010', ['#VALUE!', '1001, "ABC"'], // Leading places non-numeric
], ['2', '00000010'],
// Too large ['5', '00000101'],
[ ['15', '00001101'],
'#NUM!', ['0', '0'],
'111001010101', ['#NUM!', '21'], // Invalid binary number
], ['#VALUE!', 'true'], // Boolean okay for ODS, not for others
// Leading places ['#VALUE!', 'false'], // Boolean okay for ODS, not for others
[ ['7777777625', '1110010101'], // 2's Complement
'011', ['7777777777', '1111111111'], // 2's Complement
'1001', ['7777777000', '1000000000'], // lowest negative
3, ['777', '111111111'], // highest positive
], ['0', '0000000000'],
// Leading places as a float ['1', '000000001'],
[ ['400', '0100000000'],
'0011', ['400', '100000000'],
'1001', ['7777777400', '1100000000'],
4.75, ['0003', '11, 4'],
], ['#NUM!', '11, 0'],
// Leading places negative ['#NUM!', '11, -1'],
[ ['#NUM!', '11, 14'],
'#NUM!', ['#NUM!', '10001, 1'],
'1001', ['21', '10001, 2'],
-1, [5, 'A2'],
], ['#NUM!', '"A2"'],
// Leading places non-numeric [0, 'A3'],
[ ['exception', ''],
'#VALUE!',
'1001',
'ABC',
],
[
'2',
'00000010',
],
[
'5',
'00000101',
],
[
'15',
'00001101',
],
[
'0',
'0',
],
// Invalid binary number
[
'#NUM!',
'21',
],
// Non string
[
'#VALUE!',
true,
],
// 2's Complement
[
'7777777625',
'1110010101',
],
// 2's Complement
[
'7777777777',
'1111111111',
],
]; ];

View File

@ -1,91 +1,36 @@
<?php <?php
return [ return [
[ ['101100101', '357'],
'101100101', ['#NUM!', '512'], // Too large
357, ['#NUM!', '-513'], // Too small
], ['1001', '9, 4'],
// Too large ['00001001', '9, 8'],
[ ['001001', '9, 6.75'], // Leading places as a float
'#NUM!', ['#NUM!', '9, -1'], // Leading places negative
512, ['#VALUE!', '9, "ABC"'], // Leading places non-numeric
], ['11110110', '"246"'],
// Too small ['#NUM!', '12345'],
[ ['#NUM!', '123456789'],
'#NUM!', ['1111011', '123.45'],
-513, ['0', '0'],
], ['#VALUE!', '"3579A"'], // Invalid decimal
[ ['#VALUE!', 'true'], // ODS accepts boolean, Excel/Gnumeric don't
'1001', ['#VALUE!', 'false'], // ODS accepts boolean, Excel/Gnumeric don't
9, ['1110011100', '-100'], // 2's Complement
4, ['1110010101', '-107'], // 2's Complement
], ['1000000000', '-512'], // lowest negative
[ ['111111111', '511'], // highest positive
'00001001', ['#NUM!', '-513'],
9, ['#NUM!', '512'],
8, ['0011', '3, 4'],
], ['#NUM!', '3, 0'],
// Leading places as a float ['#NUM!', '3, -1'],
[ ['#NUM!', '3, 14'],
'001001', ['#NUM!', '3, 1'],
9, ['11', '3, 2'],
6.75, [101, 'A2'],
], ['#VALUE!', '"A2"'],
// Leading places negative [0, 'A3'],
[ ['exception', ''],
'#NUM!',
9,
-1,
],
// Leading places non-numeric
[
'#VALUE!',
9,
'ABC',
],
[
'11110110',
246,
],
[
'#NUM!',
12345,
],
[
'#NUM!',
123456789,
],
[
'1111011',
123.45,
],
[
'0',
0,
],
// Invalid decimal
[
'#VALUE!',
'3579A',
],
// Non string
[
'#VALUE!',
true,
],
// 2's Complement
[
'1110011100',
-100,
],
// 2's Complement
[
'1110010101',
-107,
],
// 2's Complement
[
'1000000000',
-512,
],
]; ];

View File

@ -1,75 +1,37 @@
<?php <?php
return [ return [
[ ['165', '357'],
'165', ['54D', '1357'],
'357', ['F6', '246'],
], ['3039', '12345'],
[ ['75BCD15', '123456789'],
'54D', ['0064', '100, 4'],
'1357', ['00064', '100, 5.75'], // Leading places as a float
], ['#NUM!', '100, -1'], // Leading places negative
[ ['#VALUE!', '100, "ABC"'], // Leading places non-numeric
'F6', ['7B', '123.45'],
'246', ['0', '0'],
], ['#VALUE!', '"3579A"'], // Invalid decimal
[ ['#VALUE!', 'true'], // ODS accepts boolean, Excel/Gnumeric don't
'3039', ['#VALUE!', 'false'],
'12345', ['FFFFFFFFCA', '-54'], // 2's Complement
], ['FFFFFFFF95', '-107'], // 2's Complement
[ ['FF80000001', '-2147483647'], // 2's Complement
'75BCD15', ['FF80000000', '-2147483648'], // 2's Complement
'123456789', ['7FFFFFFFFF', 549755813887], // highest positive, succeeds even for 32-bit
], ['#NUM!', 549755813888],
[ ['8000000000', -549755813888], // lowest negative, succeeds even for 32-bit
'0064', ['A2DE246000', -400000000000],
'100', ['5D21DBA000', 400000000000],
4, ['#NUM!', -549755813889],
], ['0103', '259, 4'],
// Leading places as a float ['#NUM!', '259, 0'],
[ ['#NUM!', '259, -1'],
'00064', ['#NUM!', '259, 14'],
'100', ['#NUM!', '259, 1'],
5.75, ['103', '259, 3'],
], ['11', 'A2'],
// Leading places negative ['0', 'C2'],
[ ['exception', ''],
'#NUM!',
'100',
-1,
],
// Leading places non-numeric
[
'#VALUE!',
'100',
'ABC',
],
[
'7B',
'123.45',
],
[
'0',
'0',
],
// Invalid decimal
[
'#VALUE!',
'3579A',
],
// Non string
[
'#VALUE!',
true,
],
// 2's Complement
[
'FFFFFFFFCA',
'-54',
],
// 2's Complement
[
'FFFFFFFF95',
'-107',
],
]; ];

View File

@ -1,57 +1,27 @@
<?php <?php
return [ return [
[ ['545', '357'],
'545', ['2515', '1357'],
'357', ['366', '246'],
], ['30071', '12345'],
[ ['726746425', '123456789'],
'2515', ['173', '123.45'],
'1357', ['072', '58, 3'],
], ['0', '0'],
[ ['#VALUE!', '"3579A"'], // Invalid decimal
'366', ['#VALUE!', 'true'], // ODS accepts bool, Excel/Gnumeric do not
'246', ['#VALUE!', 'false'],
], ['7777777634', '-100'], // 2's Complement
[ ['7777777625', '-107'], // 2's Complement
'30071', ['3777777777', 536870911], // highest positive
'12345', ['#NUM!', 536870912],
], ['4000000000', -536870912], // lowest negative
[ ['#NUM!', -536870913],
'726746425', ['0403', '259, 4'],
'123456789', ['#NUM!', '259, 0'],
], ['#NUM!', '259, -1'],
[ ['#NUM!', '259, 14'],
'173', ['#NUM!', '259, 1'],
'123.45', ['403', '259, 3'],
],
[
'072',
'58',
3,
],
[
'0',
'0',
],
// Invalid decimal
[
'#VALUE!',
'3579A',
],
// Non string
[
'#VALUE!',
true,
],
// 2's Complement
[
'7777777634',
'-100',
],
// 2's Complement
[
'7777777625',
'-107',
],
]; ];

View File

@ -1,71 +1,33 @@
<?php <?php
return [ return [
[ ['11111111', '"FF"'],
'11111111', ['111111111', '"1FF"'],
'FF', ['#NUM!', '200'],
], ['1000000000', '"FFFFFFFE00"'], // 2's Complement
[ ['#NUM!', '"FFFFFFFDFF"'], // 2's Complement
'111111111', ['111111111', '"01FF"'], // highest positive
'1FF', ['#NUM!', '"0200"'],
], ['1000000000', '"FFFFFFFE00"'], // lowest negative
[ ['#NUM!', '"FFFFFFFDFF"'],
'#NUM!', ['110101011', '"01AB"'],
'200', ['#NUM!', '"ABCD"'],
], ['11110110', '"F6"'],
// 2's Complement ['00001111', '"F", 8'],
[ ['10110111', '"B7"'],
'1000000000', ['#NUM!', '12345'],
'FFFFFFFE00', ['#NUM!', '123456789'],
], ['#NUM!', '123.45'],
// 2's Complement ['0', '0'],
[ ['#NUM!', '"G3579A"'],
'#NUM!', ['#VALUE!', 'true'],
'FFFFFFFDFF', ['#VALUE!', 'false'],
], ['01010', '"A", 5'],
[ ['#NUM!', '"A", 0'],
'110101011', ['#NUM!', '"A", -1'],
'01AB', ['#NUM!', '"A", 14'],
], ['#NUM!', '"A", 3'],
[ ['1010', '"A", 4'],
'#NUM!', ['1011', 'A2'],
'ABCD', ['0', 'A3'],
],
[
'11110110',
'F6',
],
[
'00001111',
'F',
8,
],
[
'10110111',
'B7',
],
[
'#NUM!',
'12345',
],
[
'#NUM!',
'123456789',
],
[
'#NUM!',
'123.45',
],
[
'0',
'0',
],
[
'#NUM!',
'G3579A',
],
[
'#VALUE!',
true,
],
]; ];

View File

@ -1,67 +1,27 @@
<?php <?php
return [ return [
[ ['427', '"01AB"'],
'427', ['43981', '"ABCD"'],
'01AB', ['246', '"F6"'],
], ['74565', '12345'],
[ ['4886718345', '123456789'],
'43981', ['#NUM!', '123.45'],
'ABCD', ['0', '0'],
], ['#NUM!', '"G3579A"'],
[ ['#VALUE!', 'true'],
'246', ['#VALUE!', 'false'],
'F6', ['#NUM!', '-107'],
], ['165', '"A5"'],
[ ['1034160313', '"3DA408B9"'],
'74565', ['-165', '"FFFFFFFF5B"'], // 2's Complement
'12345', ['-1', '"FFFFFFFFFF"'], // 2's Complement
], ['#NUM!', '"1FFFFFFFFFF"'], // Too large
[ [11, 'A2'],
'4886718345', [0, 'A3'],
'123456789', [549755813887, '"7fffffffff"'], // highest positive, succeeds even for 32-bit
], [-549755813888, '"8000000000"'], // lowest negative, succeeds even for 32-bit
[ [-2147483648, '"ff80000000"'],
'#NUM!', [2147483648, '"80000000"'],
'123.45', [2147483647, '"7fffffff"'],
],
[
'0',
'0',
],
[
'#NUM!',
'G3579A',
],
[
'#VALUE!',
true,
],
[
'#NUM!',
'-107',
],
[
'165',
'A5',
],
[
'1034160313',
'3DA408B9',
],
// 2's Complement
[
'-165',
'FFFFFFFF5B',
],
// 2's Complement
[
'-1',
'FFFFFFFFFF',
],
// Too large
[
'#NUM!',
'1FFFFFFFFFF',
],
]; ];

View File

@ -1,58 +1,30 @@
<?php <?php
return [ return [
[ ['653', '"01AB"'],
'653', ['125715', '"ABCD"'],
'01AB', ['366', '"F6"'],
], ['35516', '"3B4E"'],
[ ['017', '"F", 3'],
'125715', ['221505', '12345'],
'ABCD', ['#NUM!', '123456789'],
], ['#NUM!', '123.45'],
[ ['0', '0'],
'366', ['#NUM!', '"G3579A"'],
'F6', ['#VALUE!', 'true'],
], ['#VALUE!', 'false'],
[ ['#NUM!', '-107'],
'35516', ['7777777400', '"FFFFFFFF00"'], // 2's Complement
'3B4E', ['3777777777', '"1FFFFFFF"'], // highest positive
], ['#NUM!', '"20000000"'],
[ ['4000000000', '"FFE0000000"'], // lowest negative
'017', ['#NUM!', '"FFDFFFFFFF"'],
'F', ['00012', '"A", 5'],
3, ['#NUM!', '"A", 0'],
], ['#NUM!', '"A", -1'],
[ ['#NUM!', '"A", 14'],
'221505', ['#NUM!', '"A", 1'],
'12345', ['12', '"A", 2'],
], ['13', 'A2'],
[ ['0', 'A3'],
'#NUM!',
'123456789',
],
[
'#NUM!',
'123.45',
],
[
'0',
'0',
],
[
'#NUM!',
'G3579A',
],
[
'#VALUE!',
true,
],
[
'#NUM!',
'-107',
],
// 2's Complement
[
'7777777400',
'FFFFFFFF00',
],
]; ];

View File

@ -1,61 +1,31 @@
<?php <?php
return [ return [
[ ['#NUM!', '1357'],
'#NUM!', ['10100110', '246'],
'1357', ['011', '3, 3'],
], ['#NUM!', '12345'],
[ ['#NUM!', '123.45'],
'10100110', ['0', '0'],
'246', ['#VALUE!', 'true'],
], ['#VALUE!', 'false'],
[ ['#NUM!', '3579'],
'011', ['1000000000', '7777777000'], // 2's Complement
'3', ['1111111111', '7777777777'], // 2's Complement
3, ['#NUM!', '17777777777'], // Too small
], ['#NUM!', '1777'], // Too large
[ ['111111111', '777'], // highest positive
'#NUM!', ['#NUM!', '1000'],
'12345', ['1000000000', '"7777777000"'], // lowest negative
], ['#NUM!', '"7777776777"'],
[ ['01010', '12, 5'],
'#NUM!', ['#NUM!', '12, 0'],
'123.45', ['#NUM!', '12, -1'],
], ['#NUM!', '12, 14'],
[ ['#NUM!', '12, 3'],
'0', ['1010', '12, 4'],
'0', ['1000001', 'A2'],
], ['#NUM!', '"A2"'],
[ [0, 'A3'],
'#VALUE!', ['exception', ''],
true,
],
[
'#NUM!',
'3579',
],
// 2's Complement
[
'1000000000',
'7777777000',
],
// 2's Complement
[
'1111111111',
'7777777777',
],
// Too small
[
'#NUM!',
'17777777777',
],
[
'111111111',
'777',
],
// Too large
[
'#NUM!',
'1777',
],
]; ];

View File

@ -1,41 +1,20 @@
<?php <?php
return [ return [
[ ['751', '1357'],
'751', ['166', '246'],
'1357', ['5349', '12345'],
], ['#NUM!', '123.45'],
[ ['0', '0'],
'166', ['#VALUE!', 'true'],
'246', ['#VALUE!', 'false'],
], ['#NUM!', '3579'],
[ ['44', '54'],
'5349', ['-165', '7777777533'], // 2's Complement
'12345', ['65', 'A2'],
], ['0', 'A3'],
[ ['exception', ''],
'#NUM!', ['#NUM!', '"37777777770"'], // too many digits
'123.45', [536870911, '"3777777777"'], // highest positive
], [-536870912, '"4000000000"'], // lowest negative
[
'0',
'0',
],
[
'#VALUE!',
true,
],
[
'#NUM!',
'3579',
],
[
'44',
'54',
],
// 2's Complement
[
'-165',
'7777777533',
],
]; ];

View File

@ -1,42 +1,26 @@
<?php <?php
return [ return [
[ ['2EF', '1357'],
'2EF', ['A6', '246'],
'1357', ['14E5', '12345'],
], ['0040', '100, 4'],
[ ['#NUM!', '123.45'],
'A6', ['0', '0'],
'246', ['#VALUE!', 'true'],
], ['#VALUE!', 'false'],
[ ['#NUM!', '3579'],
'14E5', ['FFFFFFFF5B', '7777777533'], // 2's Complement
'12345', ['00108', '410, 5'],
], ['#NUM!', '410, 0'],
[ ['#NUM!', '410, -1'],
'0040', ['#NUM!', '410, 14'],
'100', ['#NUM!', '410, 2'],
4, ['108', '410, 3'],
], ['41', 'A2'],
[ ['0', 'A3'],
'#NUM!', ['exception', ''],
'123.45', ['#NUM!', '"37777777770"'], // too many digits
], ['1FFFFFFF', '"3777777777"'], // highest positive
[ ['FFE0000000', '"4000000000"'], // lowest negative
'0',
'0',
],
[
'#VALUE!',
true,
],
[
'#NUM!',
'3579',
],
// 2's Complement
[
'FFFFFFFF5B',
'7777777533',
],
]; ];