repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Web; use PhpOffice\PhpSpreadsheet\Calculation\Web\Service; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class WebServiceTest extends TestCase { private ?Spreadsheet $spreadsheet = null; private const WHITELIST = [ 'www.example.com', 'www.google.com', 'www.invalid.com', ]; protected function tearDown(): void { if ($this->spreadsheet !== null) { $this->spreadsheet->disconnectWorksheets(); $this->spreadsheet = null; } } #[DataProvider('providerWEBSERVICE')] public function testWEBSERVICE(string $expectedResult, string $url): void { if (str_starts_with($url, 'https') && getenv('SKIP_URL_IMAGE_TEST') === '1') { self::markTestSkipped('Skipped due to setting of environment variable'); } $this->spreadsheet = new Spreadsheet(); $this->spreadsheet->setDomainWhiteList(self::WHITELIST); $sheet = $this->spreadsheet->getActiveSheet(); $sheet->getCell('Z1')->setValue('http://www.example.com'); $sheet->getCell('Z2')->setValue(2); if (str_starts_with($url, 'Z')) { $sheet->getCell('A1')->setValue("=WEBSERVICE($url)"); } else { $sheet->getCell('A1')->setValue("=WEBSERVICE(\"$url\")"); } $result = $sheet->getCell('A1')->getCalculatedValue(); self::assertStringContainsString($expectedResult, $result); } public static function providerWEBSERVICE(): array { return require 'tests/data/Calculation/Web/WEBSERVICE.php'; } public function testOldCalculated(): void { $reader = new XlsxReader(); $this->spreadsheet = $reader->load('tests/data/Reader/XLSX/fakewebservice.xlsx'); $this->spreadsheet->setDomainWhiteList(self::WHITELIST); $sheet = $this->spreadsheet->getActiveSheet(); $a1Formula = $sheet->getCell('A1')->getValue(); self::assertSame( '=WEBSERVICE("http://www.phonydomain.com")', // not in whitelist $a1Formula ); self::assertSame( 'phony result', $sheet->getCell('A1')->getCalculatedValue(), 'result should be oldCalculatedValue' ); $sheet->getCell('A2')->setValue($a1Formula); self::assertNull( $sheet->getCell('A2')->getCalculatedValue(), 'no oldCalculatedValue to fall back on' ); $sheet->getCell('A3')->setValue($a1Formula); $sheet->getCell('A3')->setCalculatedValue('random string'); self::assertSame( 'random string', $sheet->getCell('A3')->getCalculatedValue(), 'oldCalculatedValue explicitly set above' ); self::assertNull( Service::webService('http://www.example.com'), 'no Spreadsheet so no whitelist' ); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DVar; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DVarTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDVar')] public function testDirectCallToDVar(float|string $expectedResult, array $database, ?string $field, array $criteria): void { $result = DVar::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDVar')] public function testDVarAsWorksheetFormula(float|string $expectedResult, array $database, ?string $field, array $criteria): void { $this->prepareWorksheetWithFormula('DVAR', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerDVar(): array { return [ [ 8.8, self::database1(), 'Yield', [ ['Tree'], ['=Apple'], ['=Pear'], ], ], [ 0.038433333333, self::database3FilledIn(), 'Score', [ ['Subject', 'Gender'], ['Math', 'Male'], ], ], [ 0.017433333333, self::database3FilledIn(), 'Score', [ ['Subject', 'Age'], ['Science', '>8'], ], ], 'omitted field name' => [ ExcelError::VALUE(), self::database1(), null, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DAverageTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DAverageTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DAverage; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DAverageTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDAverage')] public function testDirectCallToDAverage(int|float|string $expectedResult, array $database, string|int|null $field, array $criteria): void { $result = DAverage::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDAverage')] public function testDAverageAsWorksheetFormula(int|float|string $expectedResult, array $database, string|int|null $field, array $criteria): void { $this->prepareWorksheetWithFormula('DAVERAGE', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerDAverage(): array { return [ [ 12, self::database1(), 'Yield', [ ['Tree', 'Height'], ['=Apple', '>10'], ], ], [ 268333.333333333333, self::database2(), 'Sales', [ ['Quarter', 'Sales Rep.'], ['>1', 'Tina'], ], ], [ 372500, self::database2(), 'Sales', [ ['Quarter', 'Area'], ['1', 'South'], ], ], 'numeric column, in this case referring to age' => [ 13, self::database1(), 3, self::database1(), ], 'null field' => [ ExcelError::VALUE(), self::database1(), null, self::database1(), ], 'field unknown column' => [ ExcelError::VALUE(), self::database1(), 'xyz', self::database1(), ], 'multiple criteria, omit equal sign' => [ 10.5, self::database1(), 'Yield', [ ['Tree', 'Height'], ['=Apple', '>10'], ['Pear'], ], ], 'multiple criteria for same field' => [ 10, self::database1(), 'Yield', [ ['Tree', 'Height', 'Age', 'Height'], ['=Apple', '>10', null, '<16'], ], ], /* Excel seems to return #NAME? when column number is too high or too low. This makes so little sense to me that I'm not going to bother coding that up, content to return #VALUE! as an invalid name would */ 'field column number too high' => [ ExcelError::VALUE(), self::database1(), 99, self::database1(), ], 'field column number too low' => [ ExcelError::VALUE(), self::database1(), 0, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DStDev; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DStDevTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDStDev')] public function testDirectCallToDStDev(float|string $expectedResult, array $database, ?string $field, array $criteria): void { $result = DStDev::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDStDev')] public function testDStDevAsWorksheetFormula(float|string $expectedResult, array $database, ?string $field, array $criteria): void { $this->prepareWorksheetWithFormula('DSTDEV', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerDStDev(): array { return [ [ 2.966479394838, self::database1(), 'Yield', [ ['Tree'], ['=Apple'], ['=Pear'], ], ], [ 0.104403065089, self::database3FilledIn(), 'Score', [ ['Subject', 'Gender'], ['English', 'Male'], ], ], [ 0.196723155729, self::database3FilledIn(), 'Score', [ ['Subject', 'Age'], ['Math', '>8'], ], ], 'omitted field name' => [ ExcelError::VALUE(), self::database1(), null, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMinTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMinTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DMin; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DMinTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDMin')] public function testDirectCallToDMin(int|float|string $expectedResult, array $database, string|null|int $field, array $criteria): void { $result = DMin::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDMin')] public function testDMinAsWorksheetFormula(int|float|string $expectedResult, array $database, string|null|int $field, array $criteria): void { $this->prepareWorksheetWithFormula('DMIN', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerDMin(): array { return [ [ 75, self::database1(), 'Profit', [ ['Tree', 'Height', 'Height'], ['=Apple', '>10', '<16'], ['=Pear', '>12', null], ], ], [ 0.48, self::database3(), 'Score', [ ['Subject', 'Age'], ['Science', '>8'], ], ], [ 0.55, self::database3(), 'Score', [ ['Subject', 'Gender'], ['Math', 'Male'], ], ], 'omitted field name' => [ ExcelError::VALUE(), self::database1(), null, self::database1(), ], 'field column number okay' => [ 8, self::database1(), 2, self::database1(), ], /* Excel seems to return #NAME? when column number is too high or too low. This makes so little sense to me that I'm not going to bother coding that up, content to return #VALUE! as an invalid name would */ 'field column number too high' => [ ExcelError::VALUE(), self::database1(), 99, self::database1(), ], 'field column number too low' => [ ExcelError::VALUE(), self::database1(), 0, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DGetTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DGetTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DGet; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DGetTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDGet')] public function testDirectCallToDGet(string|int $expectedResult, array $database, ?string $field, array $criteria): void { $result = DGet::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDGet')] public function testDGetAsWorksheetFormula(string|int $expectedResult, array $database, ?string $field, array $criteria): void { $this->prepareWorksheetWithFormula('DGET', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerDGet(): array { return [ [ ExcelError::NAN(), self::database1(), 'Yield', [ ['Tree'], ['=Apple'], ['=Pear'], ], ], [ 10, self::database1(), 'Yield', [ ['Tree', 'Height', 'Height'], ['=Apple', '>10', '<16'], ['=Pear', '>12', null], ], ], [ 188000, self::database2(), 'Sales', [ ['Sales Rep.', 'Quarter'], ['Tina', 4], ], ], [ ExcelError::NAN(), self::database2(), 'Sales', [ ['Area', 'Quarter'], ['South', 4], ], ], 'omitted field name' => [ ExcelError::VALUE(), self::database1(), null, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DSumTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DSumTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DSum; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DSumTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDSum')] public function testDirectCallToDSum(int|float|string $expectedResult, array $database, ?string $field, array $criteria): void { $result = DSum::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDSum')] public function testDSumAsWorksheetFormula(int|float|string $expectedResult, array $database, ?string $field, array $criteria): void { $this->prepareWorksheetWithFormula('DSUM', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerDSum(): array { return [ [ 225, self::database1(), 'Profit', [ ['Tree'], ['=Apple'], ], ], [ 247.8, self::database1(), 'Profit', [ ['Tree', 'Height', 'Height'], ['=Apple', '>10', '<16'], ['=Pear', null, null], ], ], [ 1210000, self::database2(), 'Sales', [ ['Quarter', 'Area'], ['>2', 'North'], ], ], [ 710000, self::database2(), 'Sales', [ ['Quarter', 'Sales Rep.'], ['3', 'C*'], ], ], [ 705000, self::database2(), 'Sales', [ ['Quarter', 'Sales Rep.'], ['3', '<>C*'], ], ], 'omitted field name' => [ ExcelError::VALUE(), self::database1(), null, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DCount; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DCountTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDCount')] public function testDirectCallToDCount(int|string $expectedResult, array $database, string|int|null $field, array $criteria): void { $result = DCount::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDCount')] public function testDCountAsWorksheetFormula(int|string $expectedResult, array $database, string|int|null $field, array $criteria): void { $this->prepareWorksheetWithFormula('DCOUNT', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** @return array<array{mixed, mixed}> */ private static function database4(): array { return [ ['Status', 'Value'], [false, 1], [true, 2], [true, 4], [false, 8], [true, 16], [false, 32], [false, 64], [false, 128], ]; } public static function providerDCount(): array { return [ [ 1, self::database1(), 'Age', [ ['Tree', 'Height', 'Height'], ['=Apple', '>10', '<16'], ], ], [ 1, self::database3(), 'Score', [ ['Subject', 'Gender'], ['Science', 'Male'], ], ], [ 1, self::database3(), 'Score', [ ['Subject', 'Gender'], ['Math', 'Female'], ], ], [ 3, self::database4(), 'Value', [ ['Status'], [true], ], ], [ 5, self::database4(), 'Value', [ ['Status'], ['<>true'], ], ], 'field column number okay' => [ 0, self::database1(), 1, self::database1(), ], 'omitted field name' => [ ExcelError::VALUE(), self::database3(), null, [ ['Subject', 'Score'], ['English', '>63%'], ], ], /* Excel seems to return #NAME? when column number is too high or too low. This makes so little sense to me that I'm not going to bother coding that up, content to return #VALUE! as an invalid name would */ 'field column number too high' => [ ExcelError::VALUE(), self::database1(), 99, self::database1(), ], 'field column number too low' => [ ExcelError::VALUE(), self::database1(), 0, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountATest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountATest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DCountA; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DCountATest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDCountA')] public function testDirectCallToDCountA(int|string $expectedResult, array $database, string $field, array $criteria): void { $result = DCountA::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDCountA')] public function testDCountAAsWorksheetFormula(int|string $expectedResult, array $database, string $field, array $criteria): void { $this->prepareWorksheetWithFormula('DCOUNTA', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerDCountA(): array { return [ [ 1, self::database1(), 'Profit', [ ['Tree', 'Height', 'Height'], ['=Apple', '>10', '<16'], ], ], [ 2, self::database3(), 'Score', [ ['Subject', 'Gender'], ['Science', 'Male'], ], ], [ 1, self::database3(), 'Score', [ ['Subject', 'Gender'], ['Math', 'Female'], ], ], [ 3, self::database3(), 'Score', [ ['Subject', 'Score'], ['English', '>60%'], ], ], 'invalid field name' => [ ExcelError::VALUE(), self::database3(), 'Scorex', [ ['Subject', 'Score'], ['English', '>60%'], ], ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/SetupTeardownDatabases.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/SetupTeardownDatabases.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PHPUnit\Framework\TestCase; class SetupTeardownDatabases extends TestCase { protected const RESULT_CELL = 'Z1'; private ?Spreadsheet $spreadsheet = null; private ?Worksheet $sheet = null; protected function setUp(): void { Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); } protected function tearDown(): void { $this->sheet = null; if ($this->spreadsheet !== null) { $this->spreadsheet->disconnectWorksheets(); $this->spreadsheet = null; } Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); } /** @return mixed[][] */ protected static function database1(): array { return [ ['Tree', 'Height', 'Age', 'Yield', 'Profit'], ['Apple', 18, 20, 14, 105], ['Pear', 12, 12, 10, 96], ['Cherry', 13, 14, 9, 105], ['Apple', 14, 15, 10, 75], ['Pear', 9, 8, 8, 76.8], ['Apple', 8, 9, 6, 45], ]; } /** @return mixed[][] */ protected static function database2(): array { return [ ['Quarter', 'Area', 'Sales Rep.', 'Sales'], [1, 'North', 'Jeff', 223000], [1, 'North', 'Chris', 125000], [1, 'South', 'Carol', 456000], [1, 'South', 'Tina', 289000], [2, 'North', 'Jeff', 322000], [2, 'North', 'Chris', 340000], [2, 'South', 'Carol', 198000], [2, 'South', 'Tina', 222000], [3, 'North', 'Jeff', 310000], [3, 'North', 'Chris', 250000], [3, 'South', 'Carol', 460000], [3, 'South', 'Tina', 395000], [4, 'North', 'Jeff', 261000], [4, 'North', 'Chris', 389000], [4, 'South', 'Carol', 305000], [4, 'South', 'Tina', 188000], ]; } /** @return mixed[][] */ protected static function database3(): array { return [ ['Name', 'Gender', 'Age', 'Subject', 'Score'], ['Amy', 'Female', 8, 'Math', 0.63], ['Amy', 'Female', 8, 'English', 0.78], ['Amy', 'Female', 8, 'Science', 0.39], ['Bill', 'Male', 8, 'Math', 0.55], ['Bill', 'Male', 8, 'English', 0.71], ['Bill', 'Male', 8, 'Science', 'awaiting'], ['Sue', 'Female', 9, 'Math', null], ['Sue', 'Female', 9, 'English', 0.52], ['Sue', 'Female', 9, 'Science', 0.48], ['Tom', 'Male', 9, 'Math', 0.78], ['Tom', 'Male', 9, 'English', 0.69], ['Tom', 'Male', 9, 'Science', 0.65], ]; } /** @return mixed[][] */ protected static function database3FilledIn(): array { // same as database3 except two omitted scores are filled in return [ ['Name', 'Gender', 'Age', 'Subject', 'Score'], ['Amy', 'Female', 10, 'Math', 0.63], ['Amy', 'Female', 10, 'English', 0.78], ['Amy', 'Female', 10, 'Science', 0.39], ['Bill', 'Male', 8, 'Math', 0.55], ['Bill', 'Male', 8, 'English', 0.71], ['Bill', 'Male', 8, 'Science', 0.51], ['Sam', 'Male', 9, 'Math', 0.39], ['Sam', 'Male', 9, 'English', 0.52], ['Sam', 'Male', 9, 'Science', 0.48], ['Tom', 'Male', 9, 'Math', 0.78], ['Tom', 'Male', 9, 'English', 0.69], ['Tom', 'Male', 9, 'Science', 0.65], ]; } protected function getSpreadsheet(): Spreadsheet { if ($this->spreadsheet !== null) { return $this->spreadsheet; } $this->spreadsheet = new Spreadsheet(); return $this->spreadsheet; } protected function getSheet(): Worksheet { if ($this->sheet !== null) { return $this->sheet; } $this->sheet = $this->getSpreadsheet()->getActiveSheet(); return $this->sheet; } /** * @param mixed[] $database * @param mixed[][] $criteria */ public function prepareWorksheetWithFormula(string $functionName, array $database, null|int|string $field, array $criteria): void { $sheet = $this->getSheet(); $maxCol = ''; $startCol = 'A'; $maxRow = 0; $startRow = 1; $row = $startRow; foreach ($database as $dataRow) { /** @var mixed[] $dataRow */ $col = $startCol; foreach ($dataRow as $dataCell) { $sheet->getCell("$col$row")->setValue($dataCell); $maxCol = max($col, $maxCol); StringHelper::stringIncrement($col); } $maxRow = $row; ++$row; } $databaseCells = "$startCol$startRow:$maxCol$maxRow"; $maxCol = ''; $startCol = 'P'; $maxRow = 0; $startRow = 1; $row = $startRow; foreach ($criteria as $dataRow) { /** @var mixed[] $dataRow */ $col = $startCol; foreach ($dataRow as $dataCell) { if ($dataCell !== null) { $sheet->getCell("$col$row")->setValueExplicit($dataCell, DataType::TYPE_STRING); } $maxCol = max($col, $maxCol); StringHelper::stringIncrement($col); } $maxRow = $row; ++$row; } $criteriaCells = "$startCol$startRow:$maxCol$maxRow"; $sheet->getCell('N1')->setValue($field); $sheet->getCell(self::RESULT_CELL)->setValue("=$functionName($databaseCells, N1, $criteriaCells)"); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMaxTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMaxTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DMax; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DMaxTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDMax')] public function testDirectCallToDMax(int|string $expectedResult, array $database, string|null|int $field, array $criteria): void { $result = DMax::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDMax')] public function testDMaxAsWorksheetFormula(int|string $expectedResult, array $database, string|null|int $field, array $criteria): void { $this->prepareWorksheetWithFormula('DMAX', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerDMax(): array { return [ [ 96, self::database1(), 'Profit', [ ['Tree', 'Height', 'Height'], ['=Apple', '>10', '<16'], ['=Pear', null, null], ], ], [ 340000, self::database2(), 'Sales', [ ['Quarter', 'Area'], [2, 'North'], ], ], [ 460000, self::database2(), 'Sales', [ ['Sales Rep.', 'Quarter'], ['Carol', '>1'], ], ], 'omitted field name' => [ ExcelError::VALUE(), self::database1(), null, self::database1(), ], 'field column number okay' => [ 18, self::database1(), 2, self::database1(), ], /* Excel seems to return #NAME? when column number is too high or too low. This makes so little sense to me that I'm not going to bother coding that up, content to return #VALUE! as an invalid name would */ 'field column number too high' => [ ExcelError::VALUE(), self::database1(), 99, self::database1(), ], 'field column number too low' => [ ExcelError::VALUE(), self::database1(), 0, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DProductTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DProductTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DProduct; use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers as DateTimeHelper; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DProductTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDProduct')] public function testDirectCallToDProduct(float|string $expectedResult, array $database, ?string $field, array $criteria): void { $result = DProduct::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDProduct')] public function testDProductAsWorksheetFormula(float|string $expectedResult, array $database, ?string $field, array $criteria): void { $this->prepareWorksheetWithFormula('DPRODUCT', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** @return array<array{mixed, mixed, mixed, mixed}> */ private static function database5(): array { return [ ['Name', 'Date', 'Test', 'Score'], ['Gary', DateTimeHelper::getDateValue('01-Jan-2017'), 'Test1', 4], ['Gary', DateTimeHelper::getDateValue('01-Jan-2017'), 'Test2', 4], ['Gary', DateTimeHelper::getDateValue('01-Jan-2017'), 'Test3', 3], ['Gary', DateTimeHelper::getDateValue('05-Jan-2017'), 'Test1', 3], ['Gary', DateTimeHelper::getDateValue('05-Jan-2017'), 'Test2', 4], ['Gary', DateTimeHelper::getDateValue('05-Jan-2017'), 'Test3', 3], ['Kev', DateTimeHelper::getDateValue('02-Jan-2017'), 'Test1', 2], ['Kev', DateTimeHelper::getDateValue('02-Jan-2017'), 'Test2', 3], ['Kev', DateTimeHelper::getDateValue('02-Jan-2017'), 'Test3', 5], ['Kev', DateTimeHelper::getDateValue('05-Jan-2017'), 'Test1', 3], ['Kev', DateTimeHelper::getDateValue('05-Jan-2017'), 'Test2', 2], ['Kev', DateTimeHelper::getDateValue('05-Jan-2017'), 'Test3', 5], ]; } public static function providerDProduct(): array { return [ [ 800.0, self::database1(), 'Yield', [ ['Tree', 'Height', 'Height'], ['=Apple', '>10', '<16'], ['=Pear', null, null], ], ], [ 36.0, self::database5(), 'Score', [ ['Name', 'Date'], ['Gary', '05-Jan-2017'], ], ], [ 8.0, self::database5(), 'Score', [ ['Test', 'Date'], ['Test1', '<05-Jan-2017'], ], ], 'omitted field name' => [ ExcelError::VALUE(), self::database1(), null, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarPTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarPTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DVarP; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DVarPTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDVarP')] public function testDirectCallToDVarP(float|string $expectedResult, array $database, ?string $field, array $criteria): void { $result = DVarP::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDVarP')] public function testDVarPAsWorksheetFormula(float|string $expectedResult, array $database, ?string $field, array $criteria): void { $this->prepareWorksheetWithFormula('DVARP', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerDVarP(): array { return [ [ 7.04, self::database1(), 'Yield', [ ['Tree'], ['=Apple'], ['=Pear'], ], ], [ 0.025622222222, self::database3FilledIn(), 'Score', [ ['Subject', 'Gender'], ['Math', 'Male'], ], ], [ 0.011622222222, self::database3FilledIn(), 'Score', [ ['Subject', 'Age'], ['Science', '>8'], ], ], 'Omitted field name' => [ ExcelError::VALUE(), self::database1(), null, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevPTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevPTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database; use PhpOffice\PhpSpreadsheet\Calculation\Database\DStDevP; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; class DStDevPTest extends SetupTeardownDatabases { /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDStDevP')] public function testDirectCallToDStDevP(float|int|string $expectedResult, array $database, ?string $field, array $criteria): void { $result = DStDevP::evaluate($database, $field, $criteria); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } /** * @param mixed[] $database * @param mixed[][] $criteria */ #[DataProvider('providerDStDevP')] public function testDStDevPAsWorksheetFormula(float|int|string $expectedResult, array $database, ?string $field, array $criteria): void { $this->prepareWorksheetWithFormula('DSTDEVP', $database, $field, $criteria); $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerDStDevP(): array { return [ [ 2.653299832284, self::database1(), 'Yield', [ ['Tree'], ['=Apple'], ['=Pear'], ], ], [ 0.085244745684, self::database3FilledIn(), 'Score', [ ['Subject', 'Gender'], ['English', 'Male'], ], ], [ 0.160623784042, self::database3FilledIn(), 'Score', [ ['Subject', 'Age'], ['Math', '>8'], ], ], [ 0.01, self::database3(), 'Score', [ ['Subject', 'Gender'], ['English', 'Male'], ], ], [ 0, self::database3(), 'Score', [ ['Subject', 'Age'], ['Math', '>8'], ], ], 'omitted field name' => [ ExcelError::VALUE(), self::database1(), null, self::database1(), ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/GeStepTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/GeStepTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\Compare; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class GeStepTest extends AllSetupTeardown { #[DataProvider('providerGESTEP')] public function testDirectCallToGESTEP(int|string $expectedResult, bool|float|int|string $arg1, null|bool|float|int|string $arg2 = null): void { $result = ($arg2 === null) ? Compare::geStep($arg1) : Compare::geStep($arg1, $arg2); self::assertSame($expectedResult, $result); } #[DataProvider('providerGESTEP')] public function testGESTEPAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=GESTEP({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerGESTEP')] public function testGESTEPInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=GESTEP({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerGESTEP(): array { return require 'tests/data/Calculation/Engineering/GESTEP.php'; } #[DataProvider('providerUnhappyGESTEP')] public function testGESTEPUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=GESTEP({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyGESTEP(): array { return [ ['Formula Error: Wrong number of arguments for GESTEP() function'], ]; } #[DataProvider('providerGeStepArray')] public function testGeStepArray(array $expectedResult, string $a, string $b): void { $calculation = Calculation::getInstance(); $formula = "=GESTEP({$a}, {$b})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerGeStepArray(): array { return [ 'row/column vector' => [ [ [1, 1, 1, 1, 1], [0, 1, 1, 1, 1], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 0, 0, 0], ], '{-1.2, 2.5, 0.0, 0.25, -0.5}', '{-1.2; -0.5; 0.0; 0.25; 2.5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2DecTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2DecTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertOctal; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class Oct2DecTest extends TestCase { private string $compatibilityMode; protected function setUp(): void { $this->compatibilityMode = Functions::getCompatibilityMode(); } protected function tearDown(): void { Functions::setCompatibilityMode($this->compatibilityMode); } #[DataProvider('providerOCT2DEC')] public function testDirectCallToOCT2DEC(mixed $expectedResult, bool|string $value): void { $result = ConvertOctal::toDecimal($value); self::assertSame($expectedResult, $result); } #[DataProvider('providerOCT2DEC')] public function testOCT2DECAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=OCT2DEC({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerOCT2DEC')] public function testOCT2DECInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=OCT2DEC({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerOCT2DEC(): array { return require 'tests/data/Calculation/Engineering/OCT2DEC.php'; } #[DataProvider('providerUnhappyOCT2DEC')] public function testOCT2DECUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=OCT2DEC({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyOCT2DEC(): array { return [ ['Formula Error: Wrong number of arguments for OCT2DEC() function'], ]; } #[DataProvider('providerOCT2DECOds')] public function testOCT2DECOds(mixed $expectedResult, bool|string $value): void { Functions::setCompatibilityMode( Functions::COMPATIBILITY_OPENOFFICE ); $result = ConvertOctal::toDecimal($value); self::assertSame($expectedResult, $result); } public static function providerOCT2DECOds(): array { return require 'tests/data/Calculation/Engineering/OCT2DECOpenOffice.php'; } public function testOCT2DECFrac(): void { $calculation = Calculation::getInstance(); $formula = '=OCT2DEC(10.1)'; Functions::setCompatibilityMode( Functions::COMPATIBILITY_GNUMERIC ); /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame(8, $result, 'Gnumeric'); Functions::setCompatibilityMode( Functions::COMPATIBILITY_OPENOFFICE ); /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'OpenOffice'); Functions::setCompatibilityMode( Functions::COMPATIBILITY_EXCEL ); /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'Excel'); } /** @param mixed[] $expectedResult */ #[DataProvider('providerOct2DecArray')] public function testOct2DecArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=OCT2DEC({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerOct2DecArray(): array { return [ 'row/column vector' => [ [[4, 7, 63, 153, 204, 341]], '{"4", "7", "77", "231", "314", "525"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCscTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCscTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImCscTest extends ComplexAssert { #[DataProvider('providerIMCSC')] public function testDirectCallToIMCSC(float|string $expectedResult, string $arg): void { $result = ComplexFunctions::IMCSC($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCSC')] public function testIMCSCAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMCSC({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCSC')] public function testIMCSCInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCSC({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMCSC(): array { return require 'tests/data/Calculation/Engineering/IMCSC.php'; } #[DataProvider('providerUnhappyIMCSC')] public function testIMCSCUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCSC({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMCSC(): array { return [ ['Formula Error: Wrong number of arguments for IMCSC() function'], ]; } /** @param string[][] $expectedResult */ #[DataProvider('providerImCscArray')] public function testImCscArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMCSC({$complex})"; /** @var array<string, array<string, string>> */ $result = $calculation->calculateFormula($formula); // Avoid testing for excess precision foreach ($expectedResult as &$array) { foreach ($array as &$string) { $string = preg_replace('/(\d{8})\d+/', '$1', $string); } } foreach ($result as &$array2) { foreach ($array2 as &$string2) { $string2 = preg_replace('/(\d{8})\d+/', '$1', $string2); } } self::assertEquals($expectedResult, $result); } public static function providerImCscArray(): array { return [ 'row/column vector' => [ [ ['-0.13829327777622+0.087608481088326i', '0.1652836698551i', '0.13829327777622+0.087608481088326i'], ['-0.62151801717043+0.30393100162843i', '0.85091812823932i', '0.62151801717043+0.30393100162843i'], ['-0.62151801717043-0.30393100162843i', '-0.85091812823932i', '0.62151801717043-0.30393100162843i'], ['-0.13829327777622-0.087608481088326i', '-0.1652836698551i', '0.13829327777622-0.087608481088326i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/AllSetupTeardown.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/AllSetupTeardown.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PHPUnit\Framework\TestCase; class AllSetupTeardown extends TestCase { private string $compatibilityMode; private ?Spreadsheet $spreadsheet = null; private ?Worksheet $sheet = null; protected function setUp(): void { $this->compatibilityMode = Functions::getCompatibilityMode(); } protected function tearDown(): void { Functions::setCompatibilityMode($this->compatibilityMode); $this->sheet = null; if ($this->spreadsheet !== null) { $this->spreadsheet->disconnectWorksheets(); $this->spreadsheet = null; } } protected static function setExcel(): void { Functions::setCompatibilityMode( Functions::COMPATIBILITY_EXCEL ); } protected static function setOpenOffice(): void { Functions::setCompatibilityMode( Functions::COMPATIBILITY_OPENOFFICE ); } protected static function setGnumeric(): void { Functions::setCompatibilityMode( Functions::COMPATIBILITY_GNUMERIC ); } protected function mightHaveException(mixed $expectedResult): void { if ($expectedResult === 'exception') { $this->expectException(CalcException::class); } } protected function getSpreadsheet(): Spreadsheet { if ($this->spreadsheet !== null) { return $this->spreadsheet; } $this->spreadsheet = new Spreadsheet(); return $this->spreadsheet; } protected function getSheet(): Worksheet { if ($this->sheet !== null) { return $this->sheet; } $this->sheet = $this->getSpreadsheet()->getActiveSheet(); return $this->sheet; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitRShiftTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitRShiftTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\BitWise; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class BitRShiftTest extends AllSetupTeardown { #[DataProvider('providerBITRSHIFT')] public function testDirectCallToBITRSHIFT(float|int|string $expectedResult, null|bool|int|float|string $arg1, null|bool|int|float|string $arg2): void { $result = BitWise::BITRSHIFT($arg1, $arg2); self::assertSame($expectedResult, $result); } #[DataProvider('providerBITRSHIFT')] public function testBITRSHIFTAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BITRSHIFT({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerBITRSHIFT')] public function testBITRSHIFTInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BITRSHIFT({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerBITRSHIFT(): array { return require 'tests/data/Calculation/Engineering/BITRSHIFT.php'; } #[DataProvider('providerUnhappyBITRSHIFT')] public function testBITRSHIFTUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BITRSHIFT({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyBITRSHIFT(): array { return [ ['Formula Error: Wrong number of arguments for BITRSHIFT() function'], ['Formula Error: Wrong number of arguments for BITRSHIFT() function', 1234], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerBitRShiftArray')] public function testBitRShiftArray(array $expectedResult, string $number, string $bits): void { $calculation = Calculation::getInstance(); $formula = "=BITRSHIFT({$number}, {$bits})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerBitRShiftArray(): array { return [ 'row/column vector' => [ [ [31, 15, 7, 3, 1], [32, 16, 8, 4, 2], [37, 18, 9, 4, 2], ], '{63; 64; 75}', '{1, 2, 3, 4, 5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSqrtTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSqrtTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImSqrtTest extends ComplexAssert { #[DataProvider('providerIMSQRT')] public function testDirectCallToIMSQRT(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMSQRT($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSQRT')] public function testIMSQRTAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMSQRT({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSQRT')] public function testIMSQRTInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSQRT({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMSQRT(): array { return require 'tests/data/Calculation/Engineering/IMSQRT.php'; } #[DataProvider('providerUnhappyIMSQRT')] public function testIMSQRTUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSQRT({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMSQRT(): array { return [ ['Formula Error: Wrong number of arguments for IMSQRT() function'], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerImSqrtArray')] public function testImSqrtArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMSQRT({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImSqrtArray(): array { return [ 'row/column vector' => [ [ ['0.9199408686343-1.3587829855366i', '1.1180339887499-1.1180339887499i', '1.3587829855366-0.9199408686343i'], ['0.45508986056223-1.0986841134678i', '0.70710678118655-0.70710678118655i', '1.0986841134678-0.45508986056223i'], ['0.45508986056223+1.0986841134678i', '0.70710678118655+0.70710678118655i', '1.0986841134678+0.45508986056223i'], ['0.9199408686343+1.3587829855366i', '1.1180339887499+1.1180339887499i', '1.3587829855366+0.9199408686343i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitAndTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitAndTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\BitWise; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class BitAndTest extends AllSetupTeardown { #[DataProvider('providerBITAND')] public function testDirectCallToBITAND(float|int|string $expectedResult, null|bool|int|float|string $arg1, null|bool|int|float|string $arg2): void { $result = BitWise::BITAND($arg1, $arg2); self::assertSame($expectedResult, $result); } #[DataProvider('providerBITAND')] public function testBITANDAsFormula(float|int|string $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BITAND({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerBITAND')] public function testBITANDInWorksheet(float|int|string $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BITAND({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerBITAND(): array { return require 'tests/data/Calculation/Engineering/BITAND.php'; } #[DataProvider('providerUnhappyBITAND')] public function testBITANDUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BITAND({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyBITAND(): array { return [ ['Formula Error: Wrong number of arguments for BITAND() function'], ['Formula Error: Wrong number of arguments for BITAND() function', 1234], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerBitAndArray')] public function testBitAndArray(array $expectedResult, string $number1, string $number2): void { $calculation = Calculation::getInstance(); $formula = "=BITAND({$number1}, {$number2})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerBitAndArray(): array { return [ 'row/column vector' => [ [ [3, 0, 1], [4, 0, 0], [5, 0, 1], ], '{7, 8, 9}', '{3; 4; 5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\Erf; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class ErfTest extends AllSetupTeardown { const ERF_PRECISION = 1E-14; #[DataProvider('providerERF')] public function testDirectCallToERF(mixed $expectedResult, mixed ...$args): void { $result = Erf::erf(...$args); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } #[DataProvider('providerERF')] public function testERFAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=ERF({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } #[DataProvider('providerERF')] public function testERFInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=ERF({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } public static function providerERF(): array { return require 'tests/data/Calculation/Engineering/ERF.php'; } #[DataProvider('providerUnhappyERF')] public function testERFUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=ERF({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyERF(): array { return [ ['Formula Error: Wrong number of arguments for ERF() function'], ]; } #[DataProvider('providerErfArray')] public function testErfArray(array $expectedResult, string $lower, string $upper = 'NULL'): void { $calculation = Calculation::getInstance(); $formula = "=ERF({$lower}, {$upper})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } public static function providerErfArray(): array { return [ 'row vector' => [ [ [-0.9103139782296353, -0.5204998778130465, 0.0, 0.2763263901682369, 0.999593047982555], ], '{-1.2, -0.5, 0.0, 0.25, 2.5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSinTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSinTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImSinTest extends ComplexAssert { #[DataProvider('providerIMSIN')] public function testDirectCallToIMSIN(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMSIN($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSIN')] public function testIMSINAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMSIN({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSIN')] public function testIMSINInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSIN({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMSIN(): array { return require 'tests/data/Calculation/Engineering/IMSIN.php'; } #[DataProvider('providerUnhappyIMSIN')] public function testIMSINUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSIN({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMSIN(): array { return [ ['Formula Error: Wrong number of arguments for IMSIN() function'], ]; } #[DataProvider('providerImSinArray')] public function testImSinArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMSIN({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImSinArray(): array { return [ 'row/column vector' => [ [ ['-5.1601436675797-3.2689394320795i', '-6.0502044810398i', '5.1601436675797-3.2689394320795i'], ['-1.298457581416-0.63496391478474i', '-1.1752011936438i', '1.298457581416-0.63496391478474i'], ['-1.298457581416+0.63496391478474i', '1.1752011936438i', '1.298457581416+0.63496391478474i'], ['-5.1601436675797+3.2689394320795i', '6.0502044810398i', '5.1601436675797+3.2689394320795i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ConvertUoMTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ConvertUoMTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertUOM; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class ConvertUoMTest extends AllSetupTeardown { const UOM_PRECISION = 1E-12; public function testGetConversionGroups(): void { $result = ConvertUOM::getConversionCategories(); self::assertContains('Weight and Mass', $result); } public function testGetConversionGroupUnits(): void { $result = ConvertUOM::getConversionCategoryUnits(); self::assertArrayHasKey('Speed', $result); self::assertContains('mph', $result['Speed']); } public function testGetConversionGroupUnitDetails(): void { $result = ConvertUOM::getConversionCategoryUnitDetails(); self::assertArrayHasKey('Information', $result); self::assertContains(['unit' => 'byte', 'description' => 'Byte'], $result['Information']); } public function testGetConversionMultipliers(): void { $result = ConvertUOM::getConversionMultipliers(); self::assertArrayHasKey('k', $result); self::assertSame(['multiplier' => 1000.0, 'name' => 'kilo'], $result['k']); } public function testGetBinaryConversionMultipliers(): void { $result = ConvertUOM::getBinaryConversionMultipliers(); self::assertArrayHasKey('ki', $result); self::assertSame(['multiplier' => 1024, 'name' => 'kibi'], $result['ki']); } #[DataProvider('providerCONVERTUOM')] public function testDirectCallToCONVERTUOM(float|int|string $expectedResult, float|int|string $value, string $from, string $to): void { $result = ConvertUOM::convert($value, $from, $to); self::assertEqualsWithDelta($expectedResult, $result, self::UOM_PRECISION); } #[DataProvider('providerCONVERTUOM')] public function testCONVERTUOMAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=CONVERT({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::UOM_PRECISION); } #[DataProvider('providerCONVERTUOM')] public function testCONVERTUOMInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=CONVERT({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::UOM_PRECISION); } /** @return mixed[] */ public static function providerCONVERTUOM(): array { /** @var mixed[] */ $return = require 'tests/data/Calculation/Engineering/CONVERTUOM.php'; return $return; } #[DataProvider('providerUnhappyCONVERTUOM')] public function testCONVERTUOMUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=CONVERT({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyCONVERTUOM(): array { return [ ['Formula Error: Wrong number of arguments for CONVERT() function'], ['Formula Error: Wrong number of arguments for CONVERT() function', 12.34], ['Formula Error: Wrong number of arguments for CONVERT() function', 12.34, 'kg'], ]; } /** @param float[][] $expectedResult */ #[DataProvider('providerConvertUoMArray')] public function testConvertUoMArray(array $expectedResult, string $value, string $fromUoM, string $toUoM): void { $calculation = Calculation::getInstance(); $formula = "=CONVERT({$value}, {$fromUoM}, {$toUoM})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::UOM_PRECISION); } /** @return mixed[] */ public static function providerConvertUoMArray(): array { return [ 'Weight/Mass' => [ [ [71.42857142857142, 0.15747304441777], [453.5923699999991, 1.0], ], '1000', '{"lbm", "g"}', '{"stone"; "kg"}', ], 'Distance' => [ [ [2025371.8285214372, 1093.6132983377101], [1851.9999999999984, 1.0], ], '1000', '{"Nmi", "m"}', '{"yd"; "km"}', ], 'Volume' => [ [ [2.976190476190475, 0.00628981077043211], [473.1764729999994, 1.0], ], '1000', '{"pt", "ml"}', '{"barrel"; "l"}', ], 'Area' => [ [ [999.9960000040016, 0.247104393046628], [404.6856422400005, 0.1], ], '1000', '{"uk_acre", "m2"}', '{"us_acre"; "ha"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2BinTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2BinTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertHex; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class Hex2BinTest extends AllSetupTeardown { #[DataProvider('providerHEX2BIN')] public function testDirectCallToHEX2BIN(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $result = ($digits === null) ? ConvertHex::toBinary($value) : ConvertHex::toBinary($value, $digits); self::assertSame($expectedResult, $result); } #[DataProvider('providerHEX2BIN')] public function testHEX2BINAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=HEX2BIN({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerHEX2BIN')] public function testHEX2BINInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=HEX2BIN({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerHEX2BIN(): array { return require 'tests/data/Calculation/Engineering/HEX2BIN.php'; } #[DataProvider('providerUnhappyHEX2BIN')] public function testHEX2BINUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=HEX2BIN({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyHEX2BIN(): array { return [ ['Formula Error: Wrong number of arguments for HEX2BIN() function'], ]; } #[DataProvider('providerHEX2BINOds')] public function testHEX2BINOds(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $this->setOpenOffice(); $result = ($digits === null) ? ConvertHex::toBinary($value) : ConvertHex::toBinary($value, $digits); self::assertSame($expectedResult, $result); } public static function providerHEX2BINOds(): array { return require 'tests/data/Calculation/Engineering/HEX2BINOpenOffice.php'; } public function testHEX2BINFrac(): void { $calculation = Calculation::getInstance(); $formula = '=HEX2BIN(10.1)'; $this->setGnumeric(); $result = $calculation->calculateFormula($formula); self::assertSame('10000', $result, 'Gnumeric'); $this->setOpenOffice(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'OpenOffice'); $this->setExcel(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'Excel'); } #[DataProvider('providerHex2BinArray')] public function testHex2BinArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=HEX2BIN({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerHex2BinArray(): array { return [ 'row/column vector' => [ [['100', '111', '111111', '10011001', '11001100', '101010101']], '{"4", "7", "3F", "99", "CC", "155"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImLog10Test.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImLog10Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImLog10Test extends ComplexAssert { #[DataProvider('providerIMLOG10')] public function testDirectCallToIMLOG10(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMLOG10($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMLOG10')] public function testIMLOG10AsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMLOG10({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMLOG10')] public function testIMLOG10InWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMLOG10({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMLOG10(): array { return require 'tests/data/Calculation/Engineering/IMLOG10.php'; } #[DataProvider('providerUnhappyIMLOG10')] public function testIMLOG10UnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMLOG10({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMLOG10(): array { return [ ['Formula Error: Wrong number of arguments for IMLOG10() function'], ]; } #[DataProvider('providerImLog10Array')] public function testImLog10Array(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMLOG10({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImLog10Array(): array { return [ 'row/column vector' => [ [ ['0.4301690032855-0.84743999682982i', '0.39794000867204-0.68218817692092i', '0.4301690032855-0.51693635701202i'], ['0.15051499783199-1.0232822653814i', '-0.68218817692092i', '0.15051499783199-0.34109408846046i'], ['0.15051499783199+1.0232822653814i', '0.68218817692092i', '0.15051499783199+0.34109408846046i'], ['0.4301690032855+0.84743999682982i', '0.39794000867204+0.68218817692092i', '0.4301690032855+0.51693635701202i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCotTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCotTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImCotTest extends ComplexAssert { #[DataProvider('providerIMCOT')] public function testDirectCallToIMCOT(float|string $expectedResult, string $arg): void { $result = ComplexFunctions::IMCOT($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCOT')] public function testIMCOTAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMCOT({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCOT')] public function testIMCOTInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCOT({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMCOT(): array { return require 'tests/data/Calculation/Engineering/IMCOT.php'; } #[DataProvider('providerUnhappyIMCOT')] public function testIMCOTUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCOT({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMCOT(): array { return [ ['Formula Error: Wrong number of arguments for IMCOT() function'], ]; } #[DataProvider('providerImCotArray')] public function testImCotArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMCOT({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImCotArray(): array { return [ 'row/column vector' => [ [ ['-0.012184711291981+0.99433328540776i', '1.0135673098126i', '0.012184711291981+0.99433328540776i'], ['-0.2176215618544+0.86801414289593i', '1.3130352854993i', '0.2176215618544+0.86801414289593i'], ['-0.2176215618544-0.86801414289593i', '-1.3130352854993i', '0.2176215618544-0.86801414289593i'], ['-0.012184711291981-0.99433328540776i', '-1.0135673098126i', '0.012184711291981-0.99433328540776i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselJTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselJTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\BesselJ; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class BesselJTest extends TestCase { const BESSEL_PRECISION = 1E-8; #[DataProvider('providerBESSELJ')] public function testDirectCallToBESSELJ(mixed $expectedResult, mixed ...$args): void { $result = BesselJ::besselJ(...$args); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); } #[DataProvider('providerBESSELJ')] public function testBESSELJAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BESSELJ({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); } #[DataProvider('providerBESSELJ')] public function testBESSELJInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BESSELJ({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); $spreadsheet->disconnectWorksheets(); } public static function providerBESSELJ(): array { return require 'tests/data/Calculation/Engineering/BESSELJ.php'; } #[DataProvider('providerUnhappyBESSELJ')] public function testBESSELJUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BESSELJ({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyBESSELJ(): array { return [ ['Formula Error: Wrong number of arguments for BESSELJ() function'], ['Formula Error: Wrong number of arguments for BESSELJ() function', 2023], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerBesselJArray')] public function testBesselJArray(array $expectedResult, string $value, string $ord): void { $calculation = Calculation::getInstance(); $formula = "=BESSELJ({$value}, {$ord})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); } public static function providerBesselJArray(): array { return [ 'row/column vector' => [ [ [0.6711327417644983, 0.9384698074235406, 1.00000000283141, 0.9844359313618615, -0.04838377582675685], [-0.4982890574931824, -0.24226845767957006, 0.0, 0.12402597733693042, 0.49709410250442176], [0.15934901834766313, 0.03060402345868265, 0.0, 0.007771889285962677, 0.44605905783029426], ], '{-1.2, -0.5, 0.0, 0.25, 2.5}', '{0; 1; 2}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2DecTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2DecTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertHex; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class Hex2DecTest extends TestCase { private string $compatibilityMode; protected function setUp(): void { $this->compatibilityMode = Functions::getCompatibilityMode(); } protected function tearDown(): void { Functions::setCompatibilityMode($this->compatibilityMode); } #[DataProvider('providerHEX2DEC')] public function testDirectCallToHEX2DEC(mixed $expectedResult, bool|float|int|string $value): void { $result = ConvertHex::toDecimal($value); self::assertSame($expectedResult, $result); } #[DataProvider('providerHEX2DEC')] public function testHEX2DECAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=HEX2DEC({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerHEX2DEC')] public function testHEX2DECInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=HEX2DEC({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerHEX2DEC(): array { return require 'tests/data/Calculation/Engineering/HEX2DEC.php'; } #[DataProvider('providerUnhappyHEX2DEC')] public function testHEX2DECUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=HEX2DEC({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyHEX2DEC(): array { return [ ['Formula Error: Wrong number of arguments for HEX2DEC() function'], ]; } #[DataProvider('providerHEX2DECOds')] public function testHEX2DECOds(mixed $expectedResult, bool|float|int|string $value): void { Functions::setCompatibilityMode( Functions::COMPATIBILITY_OPENOFFICE ); $result = ConvertHex::toDecimal($value); self::assertSame($expectedResult, $result); } public static function providerHEX2DECOds(): array { return require 'tests/data/Calculation/Engineering/HEX2DECOpenOffice.php'; } public function testHEX2DECFrac(): void { $calculation = Calculation::getInstance(); $formula = '=HEX2DEC(10.1)'; Functions::setCompatibilityMode( Functions::COMPATIBILITY_GNUMERIC ); /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame(16, $result, 'Gnumeric'); Functions::setCompatibilityMode( Functions::COMPATIBILITY_OPENOFFICE ); /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'OpenOffice'); Functions::setCompatibilityMode( Functions::COMPATIBILITY_EXCEL ); /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'Excel'); } #[DataProvider('providerHex2DecArray')] public function testHex2DecArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=HEX2DEC({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerHex2DecArray(): array { return [ 'row/column vector' => [ [[4, 7, 63, 153, 204, 341]], '{"4", "7", "3F", "99", "CC", "155"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImAbsTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImAbsTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class ImAbsTest extends AllSetupTeardown { const COMPLEX_PRECISION = 1E-12; #[DataProvider('providerIMABS')] public function testDirectCallToIMABS(float|int|string $expectedResult, string $arg): void { $result = ComplexFunctions::IMABS($arg); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } #[DataProvider('providerIMABS')] public function testIMABSAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMABS({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } #[DataProvider('providerIMABS')] public function testIMABSInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMABS({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } public static function providerIMABS(): array { return require 'tests/data/Calculation/Engineering/IMABS.php'; } #[DataProvider('providerUnhappyIMABS')] public function testIMABSUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMABS({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyIMABS(): array { return [ ['Formula Error: Wrong number of arguments for IMABS() function'], ]; } #[DataProvider('providerImAbsArray')] public function testImAbsArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMABS({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImAbsArray(): array { return [ 'row/column vector' => [ [ [2.692582403567252, 2.5, 2.692582403567252], [1.4142135623730951, 1.0, 1.4142135623730951], [1.4142135623730951, 1.0, 1.4142135623730951], [2.692582403567252, 2.5, 2.692582403567252], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2OctTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2OctTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertBinary; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class Bin2OctTest extends AllSetupTeardown { #[DataProvider('providerBIN2OCT')] public function testDirectCallToBIN2OCT(mixed $expectedResult, bool|float|int|string $value, null|float|int|string $digits = null): void { $result = ($digits === null) ? ConvertBinary::toOctal($value) : ConvertBinary::toOctal($value, $digits); self::assertSame($expectedResult, $result); } #[DataProvider('providerBIN2OCT')] public function testBIN2OCTAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BIN2OCT({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerBIN2OCT')] public function testBIN2OCTInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BIN2OCT({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerBIN2OCT(): array { return require 'tests/data/Calculation/Engineering/BIN2OCT.php'; } #[DataProvider('providerUnhappyBIN2OCT')] public function testBIN2OCTUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BIN2OCT({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyBIN2OCT(): array { return [ ['Formula Error: Wrong number of arguments for BIN2OCT() function'], ]; } #[DataProvider('providerBIN2OCTOds')] public function testBIN2OCTOds(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $this->setOpenOffice(); $result = ($digits === null) ? ConvertBinary::toOctal($value) : ConvertBinary::toOctal($value, $digits); self::assertSame($expectedResult, $result); } public static function providerBIN2OCTOds(): array { return require 'tests/data/Calculation/Engineering/BIN2OCTOpenOffice.php'; } public function testBIN2OCTFractional(): void { $calculation = Calculation::getInstance(); $formula = '=BIN2OCT(101.1)'; $this->setGnumeric(); $result = $calculation->calculateFormula($formula); self::assertSame('5', $result, 'Gnumeric'); $this->setOpenOffice(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'OpenOffice'); $this->setExcel(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'Excel'); } /** @param mixed[] $expectedResult */ #[DataProvider('providerBin2OctArray')] public function testBin2OctArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=BIN2OCT({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerBin2OctArray(): array { return [ 'row/column vector' => [ [['4', '7', '77', '231', '314', '525']], '{"100", "111", "111111", "10011001", "11001100", "101010101"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSubTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSubTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexOperations; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImSubTest extends ComplexAssert { #[DataProvider('providerIMSUB')] public function testDirectCallToIMSUB(string $expectedResult, string $arg1, string $arg2): void { $result = ComplexOperations::IMSUB($arg1, $arg2); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSUB')] public function testIMSUBAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMSUB({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSUB')] public function testIMSUBInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSUB({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMSUB(): array { return require 'tests/data/Calculation/Engineering/IMSUB.php'; } #[DataProvider('providerUnhappyIMSUB')] public function testIMSUBUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSUB({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMSUB(): array { return [ ['Formula Error: Wrong number of arguments for IMSUB() function'], ['Formula Error: Wrong number of arguments for IMSUB() function', '1.23+4.56i'], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerImSubArray')] public function testImSubArray(array $expectedResult, string $subidend, string $subisor): void { $calculation = Calculation::getInstance(); $formula = "=IMSUB({$subidend}, {$subisor})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImSubArray(): array { return [ 'matrix' => [ [ ['1-7.5i', '-2-2.5i', '-1-4.5i'], ['1-6i', '-2-i', '-1-3i'], ['1-4i', '-2+i', '-1-i'], ['1-2.5i', '-2+2.5i', '-1+0.5i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', '{"-2+5i", 2, "2+2i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImRealTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImRealTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\Complex; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class ImRealTest extends AllSetupTeardown { const COMPLEX_PRECISION = 1E-12; #[DataProvider('providerIMREAL')] public function testDirectCallToIMREAL(float|int|string $expectedResult, float|int|string $arg): void { $result = Complex::IMREAL((string) $arg); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } #[DataProvider('providerIMREAL')] public function testIMREALAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMREAL({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } #[DataProvider('providerIMREAL')] public function testIMREALInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMREAL({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } public static function providerIMREAL(): array { return require 'tests/data/Calculation/Engineering/IMREAL.php'; } #[DataProvider('providerUnhappyIMREAL')] public function testIMREALUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMREAL({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyIMREAL(): array { return [ ['Formula Error: Wrong number of arguments for IMREAL() function'], ]; } #[DataProvider('providerImRealArray')] public function testImRealArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMREAL({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImRealArray(): array { return [ 'row/column vector' => [ [ [-1.0, 0.0, 1.0], [-1.0, 0.0, 1.0], [-1.0, 0.0, 1.0], [-1.0, 0.0, 1.0], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2BinTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2BinTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertDecimal; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class Dec2BinTest extends AllSetupTeardown { #[DataProvider('providerDEC2BIN')] public function testDirectCallToDEC2BIN(mixed $expectedResult, bool|float|int|string $value, null|float|int|string $digits = null): void { $result = ($digits === null) ? ConvertDecimal::toBinary($value) : ConvertDecimal::toBinary($value, $digits); self::assertSame($expectedResult, $result); } #[DataProvider('providerDEC2BIN')] public function testDEC2BINAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=DEC2BIN({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerDEC2BIN')] public function testDEC2BINInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=DEC2BIN({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerDEC2BIN(): array { return require 'tests/data/Calculation/Engineering/DEC2BIN.php'; } #[DataProvider('providerUnhappyDEC2BIN')] public function testDEC2BINUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=DEC2BIN({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyDEC2BIN(): array { return [ ['Formula Error: Wrong number of arguments for DEC2BIN() function'], ]; } #[DataProvider('providerDEC2BINOds')] public function testDEC2BINOds(mixed $expectedResult, bool|float|int|string $value, null|float|int|string $digits = null): void { $this->setOpenOffice(); $result = ($digits === null) ? ConvertDecimal::toBinary($value) : ConvertDecimal::toBinary($value, $digits); self::assertSame($expectedResult, $result); } public static function providerDEC2BINOds(): array { return require 'tests/data/Calculation/Engineering/DEC2BINOpenOffice.php'; } public function testDEC2BINFrac(): void { $calculation = Calculation::getInstance(); $formula = '=DEC2BIN(5.1)'; $this->setGnumeric(); $result = $calculation->calculateFormula($formula); self::assertSame('101', $result, 'Gnumeric'); $this->setOpenOffice(); $result = $calculation->calculateFormula($formula); self::assertSame('101', $result, 'OpenOffice'); $this->setExcel(); $result = $calculation->calculateFormula($formula); self::assertSame('101', $result, 'Excel'); } /** @param mixed[] $expectedResult */ #[DataProvider('providerDec2BinArray')] public function testDec2BinArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=DEC2BIN({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerDec2BinArray(): array { return [ 'row/column vector' => [ [['100', '111', '111111', '10011001', '11001100', '101010101']], '{4, 7, 63, 153, 204, 341}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImArgumentTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImArgumentTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class ImArgumentTest extends AllSetupTeardown { const COMPLEX_PRECISION = 1E-12; #[DataProvider('providerIMARGUMENT')] public function testDirectCallToIMARGUMENT(float|int|string $expectedResult, string $arg): void { $result = ComplexFunctions::IMARGUMENT($arg); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } #[DataProvider('providerIMARGUMENT')] public function testIMARGUMENTAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMARGUMENT({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } #[DataProvider('providerIMARGUMENT')] public function testIMARGUMENTInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMARGUMENT({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } public static function providerIMARGUMENT(): array { return require 'tests/data/Calculation/Engineering/IMARGUMENT.php'; } #[DataProvider('providerUnhappyIMARGUMENT')] public function testIMARGUMENTUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMARGUMENT({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyIMARGUMENT(): array { return [ ['Formula Error: Wrong number of arguments for IMARGUMENT() function'], ]; } public static function providerImArgumentArray(): array { return [ 'row/column vector' => [ [ [-1.9513027039072615, -1.5707963267948966, -1.1902899496825317], [-2.356194490192345, -1.5707963267948966, -0.7853981633974483], [2.356194490192345, 1.5707963267948966, 0.7853981633974483], [1.9513027039072615, 1.5707963267948966, 1.1902899496825317], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSechTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSechTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImSechTest extends ComplexAssert { #[DataProvider('providerIMSECH')] public function testDirectCallToIMSECH(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMSECH($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSECH')] public function testIMSECHAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMSECH({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSECH')] public function testIMSECHInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSECH({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMSECH(): array { return require 'tests/data/Calculation/Engineering/IMSECH.php'; } #[DataProvider('providerUnhappyIMSECH')] public function testIMSECHUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSECH({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMSECH(): array { return [ ['Formula Error: Wrong number of arguments for IMSECH() function'], ]; } #[DataProvider('providerImSecHArray')] public function testImSecHArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMSECH({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImSecHArray(): array { return [ 'row/column vector' => [ [ ['-0.61110856415523-0.3476766607105i', '-1.2482156514688', '-0.61110856415523+0.3476766607105i'], ['0.49833703055519-0.59108384172105i', '1.8508157176809', '0.49833703055519+0.59108384172105i'], ['0.49833703055519+0.59108384172105i', '1.8508157176809', '0.49833703055519-0.59108384172105i'], ['-0.61110856415523+0.3476766607105i', '-1.2482156514688', '-0.61110856415523-0.3476766607105i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImDivTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImDivTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexOperations; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImDivTest extends ComplexAssert { #[DataProvider('providerIMDIV')] public function testDirectCallToIMDIV(string $expectedResult, string $dividend, string $divisor): void { $result = ComplexOperations::IMDIV($dividend, $divisor); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMDIV')] public function testIMDIVAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMDIV({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMDIV')] public function testIMDIVInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMDIV({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMDIV(): array { return require 'tests/data/Calculation/Engineering/IMDIV.php'; } #[DataProvider('providerUnhappyIMDIV')] public function testIMDIVUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMDIV({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMDIV(): array { return [ ['Formula Error: Wrong number of arguments for IMDIV() function'], ['Formula Error: Wrong number of arguments for IMDIV() function', '1.23+4.56i'], ]; } #[DataProvider('providerImDivArray')] public function testImDivArray(array $expectedResult, string $dividend, string $divisor): void { $calculation = Calculation::getInstance(); $formula = "=IMDIV({$dividend}, {$divisor})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImDivArray(): array { return [ 'matrix' => [ [ ['-0.36206896551724+0.3448275862069i', '-1.25i', '-0.375-0.875i'], ['-0.10344827586207+0.24137931034483i', '-0.5i', '-0.5i'], ['0.24137931034483+0.10344827586207i', '0.5i', '0.5'], ['0.5', '1.25i', '0.875+0.375i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', '{"-2+5i", 2, "2+2i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitXorTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitXorTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\BitWise; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class BitXorTest extends AllSetupTeardown { #[DataProvider('providerBITXOR')] public function testDirectCallToBITXOR(float|int|string $expectedResult, null|bool|int|float|string $arg1, null|bool|int|float|string $arg2): void { $result = BitWise::BITXOR($arg1, $arg2); self::assertSame($expectedResult, $result); } #[DataProvider('providerBITXOR')] public function testBITXORAsFormula(float|int|string $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BITXOR({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerBITXOR')] public function testBITXORInWorksheet(float|int|string $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BITXOR({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerBITXOR(): array { return require 'tests/data/Calculation/Engineering/BITXOR.php'; } #[DataProvider('providerUnhappyBITXOR')] public function testBITXORUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BITXOR({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyBITXOR(): array { return [ ['Formula Error: Wrong number of arguments for BITXOR() function'], ['Formula Error: Wrong number of arguments for BITXOR() function', 1234], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerBitXorArray')] public function testBitXorArray(array $expectedResult, string $number1, string $number2): void { $calculation = Calculation::getInstance(); $formula = "=BITXOR({$number1}, {$number2})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerBitXorArray(): array { return [ 'row/column vector' => [ [ [4, 11, 10], [3, 12, 13], [2, 13, 12], ], '{7, 8, 9}', '{3; 4; 5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitLShiftTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitLShiftTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\BitWise; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class BitLShiftTest extends AllSetupTeardown { #[DataProvider('providerBITLSHIFT')] public function testDirectCallToBITLSHIFT(float|int|string $expectedResult, null|bool|int|float|string $arg1, null|bool|int|float|string $arg2): void { $result = BitWise::BITLSHIFT($arg1, $arg2); self::assertSame($expectedResult, $result); } #[DataProvider('providerBITLSHIFT')] public function testBITLSHIFTAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BITLSHIFT({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerBITLSHIFT')] public function testBITLSHIFTInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BITLSHIFT({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerBITLSHIFT(): array { return require 'tests/data/Calculation/Engineering/BITLSHIFT.php'; } #[DataProvider('providerUnhappyBITLSHIFT')] public function testBITLSHIFTUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BITLSHIFT({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyBITLSHIFT(): array { return [ ['Formula Error: Wrong number of arguments for BITLSHIFT() function'], ['Formula Error: Wrong number of arguments for BITLSHIFT() function', 1234], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerBitLShiftArray')] public function testBitLShiftArray(array $expectedResult, string $number, string $bits): void { $calculation = Calculation::getInstance(); $formula = "=BITLSHIFT({$number}, {$bits})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerBitLShiftArray(): array { return [ 'row/column vector' => [ [ [14, 28, 56, 112, 224], [16, 32, 64, 128, 256], [18, 36, 72, 144, 288], ], '{7; 8; 9}', '{1, 2, 3, 4, 5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfPreciseTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfPreciseTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\Erf; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class ErfPreciseTest extends AllSetupTeardown { const ERF_PRECISION = 1E-14; #[DataProvider('providerERFPRECISE')] public function testDirectCallToERFPRECISE(mixed $expectedResult, mixed ...$args): void { $result = Erf::ERFPRECISE(...$args); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } #[DataProvider('providerERFPRECISE')] public function testERFPRECISEAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=ERF.PRECISE({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } #[DataProvider('providerERFPRECISE')] public function testERFPRECISEInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=ERF.PRECISE({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } public static function providerERFPRECISE(): array { return require 'tests/data/Calculation/Engineering/ERFPRECISE.php'; } #[DataProvider('providerErfPreciseArray')] public function testErfPreciseArray(array $expectedResult, string $limit): void { $calculation = Calculation::getInstance(); $formula = "=ERF.PRECISE({$limit})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } public static function providerErfPreciseArray(): array { return [ 'row vector' => [ [ [-0.9103139782296353, -0.5204998778130465, 0.0, 0.2763263901682369, 0.999593047982555], ], '{-1.2, -0.5, 0.0, 0.25, 2.5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImLnTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImLnTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImLnTest extends ComplexAssert { #[DataProvider('providerIMLN')] public function testDirectCallToIMLN(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMLN($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMLN')] public function testIMLNAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMLN({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMLN')] public function testIMLNInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMLN({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMLN(): array { return require 'tests/data/Calculation/Engineering/IMLN.php'; } #[DataProvider('providerUnhappyIMLN')] public function testIMLNUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMLN({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMLN(): array { return [ ['Formula Error: Wrong number of arguments for IMLN() function'], ]; } #[DataProvider('providerImLnArray')] public function testImLnArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMLN({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImLnArray(): array { return [ 'row/column vector' => [ [ ['0.99050073443329-1.9513027039073i', '0.91629073187416-1.5707963267949i', '0.99050073443329-1.1902899496825i'], ['0.34657359027997-2.3561944901923i', '-1.5707963267949i', '0.34657359027997-0.78539816339745i'], ['0.34657359027997+2.3561944901923i', '1.5707963267949i', '0.34657359027997+0.78539816339745i'], ['0.99050073443329+1.9513027039073i', '0.91629073187416+1.5707963267949i', '0.99050073443329+1.1902899496825i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2OctTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2OctTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertDecimal; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class Dec2OctTest extends AllSetupTeardown { #[DataProvider('providerDEC2OCT')] public function testDirectCallToDEC2OCT(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $result = ($digits === null) ? ConvertDecimal::toOctal($value) : ConvertDecimal::toOctal($value, $digits); self::assertSame($expectedResult, $result); } #[DataProvider('providerDEC2OCT')] public function testDEC2OCTAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=DEC2OCT({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerDEC2OCT')] public function testDEC2OCTInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=DEC2OCT({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerDEC2OCT(): array { return require 'tests/data/Calculation/Engineering/DEC2OCT.php'; } #[DataProvider('providerUnhappyDEC2OCT')] public function testDEC2OCTUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=DEC2OCT({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyDEC2OCT(): array { return [ ['Formula Error: Wrong number of arguments for DEC2OCT() function'], ]; } #[DataProvider('providerDEC2OCTOds')] public function testDEC2OCTOds(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $this->setOpenOffice(); $result = ($digits === null) ? ConvertDecimal::toOctal($value) : ConvertDecimal::toOctal($value, $digits); self::assertSame($expectedResult, $result); } public static function providerDEC2OCTOds(): array { return require 'tests/data/Calculation/Engineering/DEC2OCTOpenOffice.php'; } public function testDEC2OCTFrac(): void { $calculation = Calculation::getInstance(); $formula = '=DEC2OCT(17.1)'; $this->setGnumeric(); $result = $calculation->calculateFormula($formula); self::assertSame('21', $result, 'Gnumeric'); $this->setOpenOffice(); $result = $calculation->calculateFormula($formula); self::assertSame('21', $result, 'OpenOffice'); $this->setExcel(); $result = $calculation->calculateFormula($formula); self::assertSame('21', $result, 'Excel'); } /** @param mixed[] $expectedResult */ #[DataProvider('providerDec2OctArray')] public function testDec2OctArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=DEC2OCT({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerDec2OctArray(): array { return [ 'row/column vector' => [ [['4', '7', '77', '231', '314', '525']], '{4, 7, 63, 153, 204, 341}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImaginaryTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImaginaryTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\Complex; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class ImaginaryTest extends AllSetupTeardown { const COMPLEX_PRECISION = 1E-12; #[DataProvider('providerIMAGINARY')] public function testDirectCallToIMAGINARY(float|int|string $expectedResult, float|int|string $arg): void { $result = Complex::IMAGINARY((string) $arg); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } #[DataProvider('providerIMAGINARY')] public function testIMAGINARYAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMAGINARY({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } #[DataProvider('providerIMAGINARY')] public function testIMAGINARYInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMAGINARY({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::COMPLEX_PRECISION); } public static function providerIMAGINARY(): array { return require 'tests/data/Calculation/Engineering/IMAGINARY.php'; } #[DataProvider('providerUnhappyIMAGINARY')] public function testIMAGINARYUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMAGINARY({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyIMAGINARY(): array { return [ ['Formula Error: Wrong number of arguments for IMAGINARY() function'], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerImaginaryArray')] public function testImaginaryArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMAGINARY({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImaginaryArray(): array { return [ 'row/column vector' => [ [ [-2.5, -2.5, -2.5], [-1.0, -1.0, -1.0], [1.0, 1.0, 1.0], [2.5, 2.5, 2.5], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2DecTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2DecTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertBinary; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class Bin2DecTest extends TestCase { private string $compatibilityMode; protected function setUp(): void { $this->compatibilityMode = Functions::getCompatibilityMode(); } protected function tearDown(): void { Functions::setCompatibilityMode($this->compatibilityMode); } #[DataProvider('providerBIN2DEC')] public function testDirectCallToBIN2DEC(float|int|string $expectedResult, bool|int|string $arg1): void { $result = ConvertBinary::toDecimal($arg1); self::assertSame($expectedResult, $result); } #[DataProvider('providerBIN2DEC')] public function testBIN2DECAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BIN2DEC({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerBIN2DEC')] public function testBIN2DECInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BIN2DEC({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerBIN2DEC(): array { return require 'tests/data/Calculation/Engineering/BIN2DEC.php'; } #[DataProvider('providerUnhappyBIN2DEC')] public function testBIN2DECUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BIN2DEC({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyBIN2DEC(): array { return [ ['Formula Error: Wrong number of arguments for BIN2DEC() function'], ]; } #[DataProvider('providerBIN2DECOds')] public function testBIN2DECOds(float|int|string $expectedResult, bool $arg1): void { Functions::setCompatibilityMode( Functions::COMPATIBILITY_OPENOFFICE ); $result = ConvertBinary::toDecimal($arg1); self::assertSame($expectedResult, $result); } public static function providerBIN2DECOds(): array { return require 'tests/data/Calculation/Engineering/BIN2DECOpenOffice.php'; } public function testBIN2DECFractional(): void { $calculation = Calculation::getInstance(); $formula = '=BIN2DEC(101.1)'; Functions::setCompatibilityMode( Functions::COMPATIBILITY_GNUMERIC ); /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame(5, $result, 'Gnumeric'); Functions::setCompatibilityMode( Functions::COMPATIBILITY_OPENOFFICE ); /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'OpenOffice'); Functions::setCompatibilityMode( Functions::COMPATIBILITY_EXCEL ); /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'Excel'); } /** @param mixed[] $expectedResult */ #[DataProvider('providerBin2DecArray')] public function testBin2DecArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=BIN2DEC({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerBin2DecArray(): array { return [ 'row/column vector' => [ [[4, 7, 63, 153, 204, 341]], '{"100", "111", "111111", "10011001", "11001100", "101010101"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselITest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselITest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\BesselI; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class BesselITest extends TestCase { const BESSEL_PRECISION = 1E-9; #[DataProvider('providerBESSELI')] public function testDirectCallToBESSELI(mixed $expectedResult, mixed ...$args): void { $result = BesselI::besselI(...$args); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); } #[DataProvider('providerBESSELI')] public function testBESSELIAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BESSELI({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); } #[DataProvider('providerBESSELI')] public function testBESSELIInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BESSELI({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); $spreadsheet->disconnectWorksheets(); } public static function providerBESSELI(): array { return require 'tests/data/Calculation/Engineering/BESSELI.php'; } #[DataProvider('providerUnhappyBESSELI')] public function testBESSELIUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BESSELI({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyBESSELI(): array { return [ ['Formula Error: Wrong number of arguments for BESSELI() function'], ['Formula Error: Wrong number of arguments for BESSELI() function', 2023], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerBesselIArray')] public function testBesselIArray(array $expectedResult, string $value, string $ord): void { $calculation = Calculation::getInstance(); $formula = "=BESSELI({$value}, {$ord})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); } public static function providerBesselIArray(): array { return [ 'row/column vector' => [ [ [1.393725572000487, 1.0634833439946074, 1.0, 1.0156861326120836, 3.2898391723912908], [-0.7146779363262508, -0.25789430328903556, 0.0, 0.12597910862299733, 2.516716242025361], [0.20259567978255663, 0.031906148375295325, 0.0, 0.007853269593280343, 1.276466158815611], ], '{-1.2, -0.5, 0.0, 0.25, 2.5}', '{0; 1; 2}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfCTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ErfCTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ErfC; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class ErfCTest extends AllSetupTeardown { const ERF_PRECISION = 1E-14; #[DataProvider('providerERFC')] public function testDirectCallToERFC(mixed $expectedResult, mixed ...$args): void { $result = ErfC::ERFC(...$args); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } #[DataProvider('providerERFC')] public function testERFCAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=ERFC({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } #[DataProvider('providerERFC')] public function testERFCInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=ERFC({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } public static function providerERFC(): array { return require 'tests/data/Calculation/Engineering/ERFC.php'; } #[DataProvider('providerUnhappyERFC')] public function testERFCUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=ERFC({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyERFC(): array { return [ ['Formula Error: Wrong number of arguments for ERFC() function'], ]; } #[DataProvider('providerErfCArray')] public function testErfCArray(array $expectedResult, string $lower): void { $calculation = Calculation::getInstance(); $formula = "=ERFC({$lower})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION); } public static function providerErfCArray(): array { return [ 'row vector' => [ [ [1.9103139782296354, 1.5204998778130465, 1.0, 0.7236736098317631, 0.0004069520174449588], ], '{-1.2, -0.5, 0.0, 0.25, 2.5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselYTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselYTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\BesselY; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class BesselYTest extends TestCase { const BESSEL_PRECISION = 1E-12; #[DataProvider('providerBESSELY')] public function testDirectCallToBESSELY(mixed $expectedResult, mixed ...$args): void { $result = BesselY::besselY(...$args); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); } #[DataProvider('providerBESSELY')] public function testBESSELYAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BESSELY({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); } #[DataProvider('providerBESSELY')] public function testBESSELYInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BESSELY({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); $spreadsheet->disconnectWorksheets(); } public static function providerBESSELY(): array { return require 'tests/data/Calculation/Engineering/BESSELY.php'; } #[DataProvider('providerUnhappyBESSELY')] public function testBESSELYUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BESSELY({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyBESSELY(): array { return [ ['Formula Error: Wrong number of arguments for BESSELY() function'], ['Formula Error: Wrong number of arguments for BESSELY() function', 2023], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerBesselYArray')] public function testBesselYArray(array $expectedResult, string $value, string $ord): void { $calculation = Calculation::getInstance(); $formula = "=BESSELY({$value}, {$ord})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); } public static function providerBesselYArray(): array { return [ 'row/column vector' => [ [ [-3.005455650891885, -0.9315730314941618, -0.44451873376270784, 0.25821685699105446, 0.4980703584466886], [-63.67859624529592, -2.7041052277866418, -1.4714723918672943, -0.5843640364184131, 0.14591813750831284], [-12732.713793408293, -20.701268790798974, -5.441370833706469, -1.1931993152605154, -0.3813358484400383], ], '{0.01, 0.25, 0.5, 1.25, 2.5}', '{0; 1; 2}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSecTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSecTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImSecTest extends ComplexAssert { #[DataProvider('providerIMSEC')] public function testDirectCallToIMSEC(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMSEC($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSEC')] public function testIMSECAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMSEC({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSEC')] public function testIMSECInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSEC({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMSEC(): array { return require 'tests/data/Calculation/Engineering/IMSEC.php'; } #[DataProvider('providerUnhappyIMSEC')] public function testIMSECUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSEC({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMSEC(): array { return [ ['Formula Error: Wrong number of arguments for IMSEC() function'], ]; } #[DataProvider('providerImSecArray')] public function testImSecArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMSEC({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImSecArray(): array { return [ 'row/column vector' => [ [ ['0.089798602872122+0.13798100670997i', '0.16307123192998', '0.089798602872122-0.13798100670997i'], ['0.49833703055519+0.59108384172105i', '0.64805427366389', '0.49833703055519-0.59108384172105i'], ['0.49833703055519-0.59108384172105i', '0.64805427366389', '0.49833703055519+0.59108384172105i'], ['0.089798602872122-0.13798100670997i', '0.16307123192998', '0.089798602872122+0.13798100670997i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImLog2Test.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImLog2Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImLog2Test extends ComplexAssert { protected float $complexPrecision = 1E-8; #[DataProvider('providerIMLOG2')] public function testDirectCallToIMLOG2(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMLOG2($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMLOG2')] public function testIMLOG2AsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMLOG2({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMLOG2')] public function testIMLOG2InWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMLOG2({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMLOG2(): array { return require 'tests/data/Calculation/Engineering/IMLOG2.php'; } #[DataProvider('providerUnhappyIMLOG2')] public function testIMLOG2UnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMLOG2({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMLOG2(): array { return [ ['Formula Error: Wrong number of arguments for IMLOG2() function'], ]; } #[DataProvider('providerImLog2Array')] public function testImLog2Array(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMLOG2({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImLog2Array(): array { return [ 'row/column vector' => [ [ ['1.4289904975638-2.8151347342002i', '1.3219280948874-2.2661800709136i', '1.4289904975638-1.717225407627i'], ['0.5-3.3992701063704i', '-2.2661800709136i', '0.5-1.1330900354568i'], ['0.5+3.3992701063704i', '2.2661800709136i', '0.5+1.1330900354568i'], ['1.4289904975638+2.8151347342002i', '1.3219280948874+2.2661800709136i', '1.4289904975638+1.717225407627i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCosTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCosTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImCosTest extends ComplexAssert { #[DataProvider('providerIMCOS')] public function testDirectCallToIMCOS(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMCOS($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCOS')] public function testIMCOSAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMCOS({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCOS')] public function testIMCOSInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCOS({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMCOS(): array { return require 'tests/data/Calculation/Engineering/IMCOS.php'; } #[DataProvider('providerUnhappyIMCOS')] public function testIMCOSUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCOS({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMCOS(): array { return [ ['Formula Error: Wrong number of arguments for IMCOS() function'], ]; } #[DataProvider('providerImCosArray')] public function testImCosArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMCOS({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImCosArray(): array { return [ 'row/column vector' => [ [ ['3.3132901461132-5.0910715229497i', 6.1322894796637, '3.3132901461132+5.0910715229497i'], ['0.83373002513115-0.98889770576287i', 1.5430806348152, '0.83373002513115+0.98889770576287i'], ['0.83373002513115+0.98889770576287i', 1.5430806348152, '0.83373002513115-0.98889770576287i'], ['3.3132901461132+5.0910715229497i', 6.1322894796637, '3.3132901461132-5.0910715229497i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2HexTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Bin2HexTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertBinary; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class Bin2HexTest extends AllSetupTeardown { #[DataProvider('providerBIN2HEX')] public function testDirectCallToBIN2HEX(mixed $expectedResult, bool|float|int|string $value, null|float|int|string $digits = null): void { $result = ($digits === null) ? ConvertBinary::toHex($value) : ConvertBinary::toHex($value, $digits); self::assertSame($expectedResult, $result); } #[DataProvider('providerBIN2HEX')] public function testBIN2HEXAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BIN2HEX({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerBIN2HEX')] public function testBIN2HEXInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BIN2HEX({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerBIN2HEX(): array { return require 'tests/data/Calculation/Engineering/BIN2HEX.php'; } #[DataProvider('providerUnhappyBIN2HEX')] public function testBIN2HEXUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BIN2HEX({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyBIN2HEX(): array { return [ ['Formula Error: Wrong number of arguments for BIN2HEX() function'], ]; } #[DataProvider('providerBIN2HEXOds')] public function testBIN2HEXOds(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $this->setOpenOffice(); $result = ($digits === null) ? ConvertBinary::toHex($value) : ConvertBinary::toHex($value, $digits); self::assertSame($expectedResult, $result); } public static function providerBIN2HEXOds(): array { return require 'tests/data/Calculation/Engineering/BIN2HEXOpenOffice.php'; } public function testBIN2HEXFractional(): void { $calculation = Calculation::getInstance(); $formula = '=BIN2HEX(101.1)'; $this->setGnumeric(); $result = $calculation->calculateFormula($formula); self::assertSame('5', $result, 'Gnumeric'); $this->setOpenOffice(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'OpenOffice'); $this->setExcel(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'Excel'); } /** @param mixed[] $expectedResult */ #[DataProvider('providerBin2HexArray')] public function testBin2HexArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=BIN2HEX({$value})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerBin2HexArray(): array { return [ 'row/column vector' => [ [['4', '7', '3F', '99', 'CC', '155']], '{"100", "111", "111111", "10011001", "11001100", "101010101"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ComplexTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ComplexTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\Complex; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class ComplexTest extends TestCase { #[DataProvider('providerCOMPLEX')] public function testDirectCallToCOMPLEX(mixed $expectedResult, mixed ...$args): void { $result = Complex::complex(...$args); self::assertSame($expectedResult, $result); } #[DataProvider('providerCOMPLEX')] public function testCOMPLEXAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=COMPLEX({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerCOMPLEX')] public function testCOMPLEXInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=COMPLEX({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerCOMPLEX(): array { return require 'tests/data/Calculation/Engineering/COMPLEX.php'; } /** @param mixed[] $expectedResult */ #[DataProvider('providerComplexArray')] public function testComplexArray(array $expectedResult, string $real, string $imaginary): void { $calculation = Calculation::getInstance(); $formula = "=COMPLEX({$real}, {$imaginary})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerComplexArray(): array { return [ 'row/column vector' => [ [ ['-2.5-2.5i', '-1-2.5i', '-2.5i', '1-2.5i', '2.5-2.5i'], ['-2.5-i', '-1-i', '-i', '1-i', '2.5-i'], ['-2.5', '-1', '0.0', '1', '2.5'], ['-2.5+i', '-1+i', 'i', '1+i', '2.5+i'], ['-2.5+2.5i', '-1+2.5i', '2.5i', '1+2.5i', '2.5+2.5i'], ], '{-2.5, -1, 0, 1, 2.5}', '{-2.5; -1; 0; 1; 2.5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImConjugateTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImConjugateTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImConjugateTest extends ComplexAssert { #[DataProvider('providerIMCONJUGATE')] public function testDirectCallToIMCONJUGATE(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMCONJUGATE($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCONJUGATE')] public function testIMCONJUGATEAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMCONJUGATE({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCONJUGATE')] public function testIMCONJUGATEInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCONJUGATE({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMCONJUGATE(): array { return require 'tests/data/Calculation/Engineering/IMCONJUGATE.php'; } #[DataProvider('providerUnhappyIMCONJUGATE')] public function testIMCONJUGATEUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCONJUGATE({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMCONJUGATE(): array { return [ ['Formula Error: Wrong number of arguments for IMCONJUGATE() function'], ]; } #[DataProvider('providerImConjugateArray')] public function testImConjugateArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMCONJUGATE({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImConjugateArray(): array { return [ 'row/column vector' => [ [ ['-1+2.5i', '2.5i', '1+2.5i'], ['-1+i', 'i', '1+i'], ['-1-i', '-i', '1-i'], ['-1-2.5i', '-2.5i', '1-2.5i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSumTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSumTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexOperations; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImSumTest extends ComplexAssert { /** * @param string ...$args variadic arguments */ #[DataProvider('providerIMSUM')] public function testDirectCallToIMSUM(mixed $expectedResult, ...$args): void { $result = ComplexOperations::IMSUM(...$args); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSUM')] public function testIMSUMAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMSUM({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSUM')] public function testIMSUMInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSUM({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMSUM(): array { return require 'tests/data/Calculation/Engineering/IMSUM.php'; } #[DataProvider('providerUnhappyIMSUM')] public function testIMSUMUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSUM({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMSUM(): array { return [ ['Formula Error: Wrong number of arguments for IMSUM() function'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2BinTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2BinTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertOctal; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class Oct2BinTest extends AllSetupTeardown { #[DataProvider('providerOCT2BIN')] public function testDirectCallToOCT2BIN(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $result = ($digits === null) ? ConvertOctal::toBinary($value) : ConvertOctal::toBinary($value, $digits); self::assertSame($expectedResult, $result); } #[DataProvider('providerOCT2BIN')] public function testOCT2BINAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=OCT2BIN({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerOCT2BIN')] public function testOCT2BINInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=OCT2BIN({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerOCT2BIN(): array { return require 'tests/data/Calculation/Engineering/OCT2BIN.php'; } #[DataProvider('providerUnhappyOCT2BIN')] public function testOCT2BINUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=OCT2BIN({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyOCT2BIN(): array { return [ ['Formula Error: Wrong number of arguments for OCT2BIN() function'], ]; } #[DataProvider('providerOCT2BINOds')] public function testOCT2BINOds(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $this->setOpenOffice(); $result = ($digits === null) ? ConvertOctal::toBinary($value) : ConvertOctal::toBinary($value, $digits); self::assertSame($expectedResult, $result); } public static function providerOCT2BINOds(): array { return require 'tests/data/Calculation/Engineering/OCT2BINOpenOffice.php'; } public function testOCT2BINFrac(): void { $calculation = Calculation::getInstance(); $formula = '=OCT2BIN(10.1)'; $this->setGnumeric(); $result = $calculation->calculateFormula($formula); self::assertSame('1000', $result, 'Gnumeric'); $this->setOpenOffice(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'OpenOffice'); $this->setExcel(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'Excel'); } /** @param mixed[] $expectedResult */ #[DataProvider('providerOct2BinArray')] public function testOct2BinArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=OCT2BIN({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerOct2BinArray(): array { return [ 'row/column vector' => [ [['100', '111', '111111', '10011001', '11001100', '101010101']], '{"4", "7", "77", "231", "314", "525"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCschTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCschTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImCschTest extends ComplexAssert { #[DataProvider('providerIMCSCH')] public function testDirectCallToIMCSCH(float|string $expectedResult, string $arg): void { $result = ComplexFunctions::IMCSCH($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCSCH')] public function testIMCSCHAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMCSCH({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCSCH')] public function testIMCSCHInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCSCH({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMCSCH(): array { return require 'tests/data/Calculation/Engineering/IMCSCH.php'; } #[DataProvider('providerUnhappyIMCSCH')] public function testIMCSCHUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCSCH({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMCSCH(): array { return [ ['Formula Error: Wrong number of arguments for IMCSCH() function'], ]; } #[DataProvider('providerImCschArray')] public function testImCschArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMCSCH({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImCschArray(): array { return [ 'row/column vector' => [ [ ['0.54132290619+0.53096557762117i', '1.6709215455587i', '-0.54132290619+0.53096557762117i'], ['-0.30393100162843+0.62151801717043i', '1.1883951057781i', '0.30393100162843+0.62151801717043i'], ['-0.30393100162843-0.62151801717043i', '-1.1883951057781i', '0.30393100162843-0.62151801717043i'], ['0.54132290619-0.53096557762117i', '-1.6709215455587i', '-0.54132290619-0.53096557762117i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/DeltaTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/DeltaTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\Compare; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class DeltaTest extends AllSetupTeardown { #[DataProvider('providerDELTA')] public function testDirectCallToDELTA(mixed $expectedResult, bool|float|int|string $arg1, null|bool|float|int|string $arg2 = null): void { $result = ($arg2 === null) ? Compare::delta($arg1) : Compare::delta($arg1, $arg2); self::assertSame($expectedResult, $result); } #[DataProvider('providerDELTA')] public function testDELTAAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=DELTA({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerDELTA')] public function testDELTAInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=DELTA({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerDELTA(): array { return require 'tests/data/Calculation/Engineering/DELTA.php'; } #[DataProvider('providerUnhappyDELTA')] public function testDELTAUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=DELTA({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyDELTA(): array { return [ ['Formula Error: Wrong number of arguments for DELTA() function'], ]; } #[DataProvider('providerDeltaArray')] public function testDeltaArray(array $expectedResult, string $a, string $b): void { $calculation = Calculation::getInstance(); $formula = "=DELTA({$a}, {$b})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerDeltaArray(): array { return [ 'row/column vector' => [ [ [1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1], ], '{-1.2, -0.5, 0.0, 0.25, 2.5}', '{-1.2; -0.5; 0.0; 0.25; 2.5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselKTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BesselKTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\BesselK; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class BesselKTest extends TestCase { const BESSEL_PRECISION = 1E-12; #[DataProvider('providerBESSELK')] public function testDirectCallToBESSELK(mixed $expectedResult, mixed ...$args): void { $result = BesselK::besselK(...$args); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); } #[DataProvider('providerBESSELK')] public function testBESSELKAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BESSELK({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); } #[DataProvider('providerBESSELK')] public function testBESSELKInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BESSELK({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, self::BESSEL_PRECISION); $spreadsheet->disconnectWorksheets(); } public static function providerBESSELK(): array { return require 'tests/data/Calculation/Engineering/BESSELK.php'; } #[DataProvider('providerUnhappyBESSELK')] public function testBESSELKUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BESSELK({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyBESSELK(): array { return [ ['Formula Error: Wrong number of arguments for BESSELK() function'], ['Formula Error: Wrong number of arguments for BESSELK() function', 2023], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerBesselKArray')] public function testBesselKArray(array $expectedResult, string $value, string $ord): void { $calculation = Calculation::getInstance(); $formula = "=BESSELK({$value}, {$ord})"; $result = $calculation->calculateFormula($formula); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); } public static function providerBesselKArray(): array { return [ 'row/column vector' => [ [ [4.721244734980139, 1.5415067364690132, 0.9244190350213235, 0.2976030874538336, 0.06234755419101918], [99.97389411857176, 3.747025980669556, 1.6564411280110791, 0.4021240820149834, 0.07389081565026694], [19999.500068449335, 31.517714581825462, 7.5501835470656395, 0.9410016186778072, 0.12146020671123273], ], '{0.01, 0.25, 0.5, 1.25, 2.5}', '{0; 1; 2}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2OctTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Hex2OctTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertHex; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class Hex2OctTest extends AllSetupTeardown { #[DataProvider('providerHEX2OCT')] public function testDirectCallToHEX2OCT(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $result = ($digits === null) ? ConvertHex::toOctal($value) : ConvertHex::toOctal($value, $digits); self::assertSame($expectedResult, $result); } #[DataProvider('providerHEX2OCT')] public function testHEX2OCTAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=HEX2OCT({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerHEX2OCT')] public function testHEX2OCTInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=HEX2OCT({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerHEX2OCT(): array { return require 'tests/data/Calculation/Engineering/HEX2OCT.php'; } #[DataProvider('providerUnhappyHEX2OCT')] public function testHEX2OCTUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=HEX2OCT({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyHEX2OCT(): array { return [ ['Formula Error: Wrong number of arguments for HEX2OCT() function'], ]; } #[DataProvider('providerHEX2OCTOds')] public function testHEX2OCTOds(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $this->setOpenOffice(); $result = ($digits === null) ? ConvertHex::toOctal($value) : ConvertHex::toOctal($value, $digits); self::assertSame($expectedResult, $result); } public static function providerHEX2OCTOds(): array { return require 'tests/data/Calculation/Engineering/HEX2OCTOpenOffice.php'; } public function testHEX2OCTFrac(): void { $calculation = Calculation::getInstance(); $formula = '=HEX2OCT(10.1)'; $this->setGnumeric(); $result = $calculation->calculateFormula($formula); self::assertSame('20', $result, 'Gnumeric'); $this->setOpenOffice(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'OpenOffice'); $this->setExcel(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'Excel'); } #[DataProvider('providerHex2OctArray')] public function testHex2OctArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=HEX2OCT({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerHex2OctArray(): array { return [ 'row/column vector' => [ [['4', '7', '77', '231', '314', '525']], '{"4", "7", "3F", "99", "CC", "155"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImTanTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImTanTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImTanTest extends ComplexAssert { #[DataProvider('providerIMTAN')] public function testDirectCallToIMTAN(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMTAN($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMTAN')] public function testIMTANAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMTAN({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMTAN')] public function testIMTANInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMTAN({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMTAN(): array { return require 'tests/data/Calculation/Engineering/IMTAN.php'; } #[DataProvider('providerUnhappyIMTAN')] public function testIMTANUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMTAN({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMTAN(): array { return [ ['Formula Error: Wrong number of arguments for IMTAN() function'], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerImTanArray')] public function testImTanArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMTAN({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImTanArray(): array { return [ 'row/column vector' => [ [ ['-0.012322138255828-1.0055480118951i', '-0.98661429815143i', '0.012322138255828-1.0055480118951i'], ['-0.27175258531951-1.0839233273387i', '-0.76159415595576i', '0.27175258531951-1.0839233273387i'], ['-0.27175258531951+1.0839233273387i', '0.76159415595576i', '0.27175258531951+1.0839233273387i'], ['-0.012322138255828+1.0055480118951i', '0.98661429815143i', '0.012322138255828+1.0055480118951i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2HexTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Oct2HexTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertOctal; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class Oct2HexTest extends AllSetupTeardown { #[DataProvider('providerOCT2HEX')] public function testDirectCallToOCT2HEX(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $result = ($digits === null) ? ConvertOctal::toHex($value) : ConvertOctal::toHex($value, $digits); self::assertSame($expectedResult, $result); } #[DataProvider('providerOCT2HEX')] public function testOCT2HEXAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=OCT2HEX({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerOCT2HEX')] public function testOCT2HEXInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=OCT2HEX({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerOCT2HEX(): array { return require 'tests/data/Calculation/Engineering/OCT2HEX.php'; } #[DataProvider('providerUnhappyOCT2HEX')] public function testOCT2HEXUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=OCT2HEX({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyOCT2HEX(): array { return [ ['Formula Error: Wrong number of arguments for OCT2HEX() function'], ]; } #[DataProvider('providerOCT2HEXOds')] public function testOCT2HEXOds(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void { $this->setOpenOffice(); $result = ($digits === null) ? ConvertOctal::toHex($value) : ConvertOctal::toHex($value, $digits); self::assertSame($expectedResult, $result); } public static function providerOCT2HEXOds(): array { return require 'tests/data/Calculation/Engineering/OCT2HEXOpenOffice.php'; } public function testOCT2HEXFrac(): void { $calculation = Calculation::getInstance(); $formula = '=OCT2HEX(20.1)'; $this->setGnumeric(); $result = $calculation->calculateFormula($formula); self::assertSame('10', $result, 'Gnumeric'); $this->setOpenOffice(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'OpenOffice'); $this->setExcel(); $result = $calculation->calculateFormula($formula); self::assertSame(ExcelError::NAN(), $result, 'Excel'); } /** @param mixed[] $expectedResult */ #[DataProvider('providerOct2HexArray')] public function testOct2HexArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=OCT2HEX({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerOct2HexArray(): array { return [ 'row/column vector' => [ [['4', '7', '3F', '99', 'CC', '155']], '{"4", "7", "77", "231", "314", "525"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImProductTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImProductTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexOperations; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImProductTest extends ComplexAssert { /** * @param string ...$args variadic arguments */ #[DataProvider('providerIMPRODUCT')] public function testDirectCallToIMPRODUCT(mixed $expectedResult, ...$args): void { $result = ComplexOperations::IMPRODUCT(...$args); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMPRODUCT')] public function testIMPRODUCTAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMPRODUCT({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMPRODUCT')] public function testIMPRODUCTInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMPRODUCT({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMPRODUCT(): array { return require 'tests/data/Calculation/Engineering/IMPRODUCT.php'; } #[DataProvider('providerUnhappyIMPRODUCT')] public function testIMPRODUCTUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMPRODUCT({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMPRODUCT(): array { return [ ['Formula Error: Wrong number of arguments for IMPRODUCT() function'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImPowerTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImPowerTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImPowerTest extends ComplexAssert { #[DataProvider('providerIMPOWER')] public function testDirectCallToIMPOWER(float|int|string $expectedResult, string $arg1, float|int|string $arg2): void { $result = ComplexFunctions::IMPOWER($arg1, $arg2); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMPOWER')] public function testIMPOWERAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMPOWER({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMPOWER')] public function testIMPOWERInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMPOWER({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMPOWER(): array { return require 'tests/data/Calculation/Engineering/IMPOWER.php'; } #[DataProvider('providerUnhappyIMPOWER')] public function testIMPOWERUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMPOWER({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMPOWER(): array { return [ ['Formula Error: Wrong number of arguments for IMPOWER() function'], ]; } #[DataProvider('providerImPowerArray')] public function testImPowerArray(array $expectedResult, string $complex, string $real): void { $calculation = Calculation::getInstance(); $formula = "=IMPOWER({$complex}, {$real})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImPowerArray(): array { return [ 'matrix' => [ [ ['-5.25+5i', '-2.8702659355016E-15+15.625i', '2.5625+52.5i'], ['-3.6739403974421E-16+2i', '-1.836970198721E-16+i', '-4-4.8985871965894E-16i'], ['-3.6739403974421E-16-2i', '-1.836970198721E-16-i', '-4+4.8985871965894E-16i'], ['-5.25-5i', '-2.8702659355016E-15-15.625i', '2.5625-52.5i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', '{2, 3, 4}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitOrTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/BitOrTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\BitWise; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class BitOrTest extends AllSetupTeardown { #[DataProvider('providerBITOR')] public function testDirectCallToBITOR(float|int|string $expectedResult, null|bool|int|float|string $arg1, null|bool|int|float|string $arg2): void { $result = BitWise::BITOR($arg1, $arg2); self::assertSame($expectedResult, $result); } #[DataProvider('providerBITOR')] public function testBITORAsFormula(float|int|string $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=BITOR({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerBITOR')] public function testBITORInWorksheet(float|int|string $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BITOR({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerBITOR(): array { return require 'tests/data/Calculation/Engineering/BITOR.php'; } #[DataProvider('providerUnhappyBITOR')] public function testBITORUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=BITOR({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyBITOR(): array { return [ ['Formula Error: Wrong number of arguments for BITOR() function'], ['Formula Error: Wrong number of arguments for BITOR() function', 1234], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerBitOrArray')] public function testBitOrArray(array $expectedResult, string $number1, string $number2): void { $calculation = Calculation::getInstance(); $formula = "=BITOR({$number1}, {$number2})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerBitOrArray(): array { return [ 'row/column vector' => [ [ [7, 11, 11], [7, 12, 13], [7, 13, 13], ], '{7, 8, 9}', '{3; 4; 5}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImExpTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImExpTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImExpTest extends ComplexAssert { protected float $complexPrecision = (PHP_INT_SIZE > 4) ? 1E-12 : 1E-9; #[DataProvider('providerIMEXP')] public function testDirectCallToIMEXP(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMEXP($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMEXP')] public function testIMEXPAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMEXP({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMEXP')] public function testIMEXPInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMEXP({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMEXP(): array { return require 'tests/data/Calculation/Engineering/IMEXP.php'; } #[DataProvider('providerUnhappyIMEXP')] public function testIMEXPUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMEXP({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMEXP(): array { return [ ['Formula Error: Wrong number of arguments for IMEXP() function'], ]; } #[DataProvider('providerImExpArray')] public function testImExpArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMEXP({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImExpArray(): array { return [ 'row/column vector' => [ [ ['-0.29472426558547-0.22016559792964i', '-0.80114361554693-0.59847214410396i', '-2.1777341321272-1.6268159541567i'], ['0.19876611034641-0.30955987565311i', '0.54030230586814-0.8414709848079i', '1.4686939399159-2.2873552871788i'], ['0.19876611034641+0.30955987565311i', '0.54030230586814+0.8414709848079i', '1.4686939399159+2.2873552871788i'], ['-0.29472426558547+0.22016559792964i', '-0.80114361554693+0.59847214410396i', '-2.1777341321272+1.6268159541567i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2HexTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/Dec2HexTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ConvertDecimal; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PHPUnit\Framework\Attributes\DataProvider; class Dec2HexTest extends AllSetupTeardown { #[DataProvider('providerDEC2HEX')] public function testDirectCallToDEC2HEX(mixed $expectedResult, bool|float|int|string $value, null|float|int|string $digits = null): void { $result = ($digits === null) ? ConvertDecimal::toHex($value) : ConvertDecimal::toHex($value, $digits); self::assertSame($expectedResult, $result); } #[DataProvider('providerDEC2HEX')] public function testDEC2HEXAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=DEC2HEX({$arguments})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } #[DataProvider('providerDEC2HEX')] public function testDEC2HEXInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=DEC2HEX({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); } public static function providerDEC2HEX(): array { return require 'tests/data/Calculation/Engineering/DEC2HEX.php'; } #[DataProvider('providerUnhappyDEC2HEX')] public function testDEC2HEXUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $worksheet = $this->getSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=DEC2HEX({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); } public static function providerUnhappyDEC2HEX(): array { return [ ['Formula Error: Wrong number of arguments for DEC2HEX() function'], ]; } #[DataProvider('providerDEC2HEXOds')] public function testDEC2HEXOds(mixed $expectedResult, bool|float|int|string $value, null|float|int|string $digits = null): void { $this->setOpenOffice(); $result = ($digits === null) ? ConvertDecimal::toHex($value) : ConvertDecimal::toHex($value, $digits); self::assertSame($expectedResult, $result); } public static function providerDEC2HEXOds(): array { return require 'tests/data/Calculation/Engineering/DEC2HEXOpenOffice.php'; } public function testDEC2HEXFrac(): void { $calculation = Calculation::getInstance(); $formula = '=DEC2HEX(17.1)'; $this->setGnumeric(); $result = $calculation->calculateFormula($formula); self::assertSame('11', $result, 'Gnumeric'); $this->setOpenOffice(); $result = $calculation->calculateFormula($formula); self::assertSame('11', $result, 'OpenOffice'); $this->setExcel(); $result = $calculation->calculateFormula($formula); self::assertSame('11', $result, 'Excel'); } public function test32bitHex(): void { self::assertEquals('A2DE246000', ConvertDecimal::hex32bit(-400000000000, 'DE246000', true)); self::assertEquals('7FFFFFFFFF', ConvertDecimal::hex32bit(549755813887, 'FFFFFFFF', true)); self::assertEquals('FFFFFFFFFF', ConvertDecimal::hex32bit(-1, 'FFFFFFFF', true)); } /** @param mixed[] $expectedResult */ #[DataProvider('providerDec2HexArray')] public function testDec2HexArray(array $expectedResult, string $value): void { $calculation = Calculation::getInstance(); $formula = "=DEC2HEX({$value})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerDec2HexArray(): array { return [ 'row/column vector' => [ [['4', '7', '3F', '99', 'CC', '155']], '{4, 7, 63, 153, 204, 341}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCoshTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCoshTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImCoshTest extends ComplexAssert { #[DataProvider('providerIMCOSH')] public function testDirectCallToIMCOSH(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMCOSH($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCOSH')] public function testIMCOSHAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMCOSH({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMCOSH')] public function testIMCOSHInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCOSH({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMCOSH(): array { return require 'tests/data/Calculation/Engineering/IMCOSH.php'; } #[DataProvider('providerUnhappyIMCOSH')] public function testIMCOSHUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMCOSH({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMCOSH(): array { return [ ['Formula Error: Wrong number of arguments for IMCOSH() function'], ]; } #[DataProvider('providerImCoshArray')] public function testImCoshArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMCOSH({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImCoshArray(): array { return [ 'row/column vector' => [ [ ['-1.2362291988563+0.70332517811353i', -0.80114361554693, '-1.2362291988563-0.70332517811353i'], ['0.83373002513115+0.98889770576287i', 0.54030230586814, '0.83373002513115-0.98889770576287i'], ['0.83373002513115-0.98889770576287i', 0.54030230586814, '0.83373002513115+0.98889770576287i'], ['-1.2362291988563-0.70332517811353i', -0.80114361554693, '-1.2362291988563+0.70332517811353i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSinhTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImSinhTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments; use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert; use PHPUnit\Framework\Attributes\DataProvider; class ImSinhTest extends ComplexAssert { #[DataProvider('providerIMSINH')] public function testDirectCallToIMSINH(string $expectedResult, string $arg): void { $result = ComplexFunctions::IMSINH($arg); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSINH')] public function testIMSINHAsFormula(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $calculation = Calculation::getInstance(); $formula = "=IMSINH({$arguments})"; /** @var float|int|string */ $result = $calculation->calculateFormula($formula); $this->assertComplexEquals($expectedResult, $result); } #[DataProvider('providerIMSINH')] public function testIMSINHInWorksheet(mixed $expectedResult, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSINH({$argumentCells})"; $result = $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $this->assertComplexEquals($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerIMSINH(): array { return require 'tests/data/Calculation/Engineering/IMSINH.php'; } #[DataProvider('providerUnhappyIMSINH')] public function testIMSINHUnhappyPath(string $expectedException, mixed ...$args): void { $arguments = new FormulaArguments(...$args); $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $argumentCells = $arguments->populateWorksheet($worksheet); $formula = "=IMSINH({$argumentCells})"; $this->expectException(CalculationException::class); $this->expectExceptionMessage($expectedException); $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); $spreadsheet->disconnectWorksheets(); } public static function providerUnhappyIMSINH(): array { return [ ['Formula Error: Wrong number of arguments for IMSINH() function'], ]; } #[DataProvider('providerImSinHArray')] public function testImSinHArray(array $expectedResult, string $complex): void { $calculation = Calculation::getInstance(); $formula = "=IMSINH({$complex})"; $result = $calculation->calculateFormula($formula); self::assertEquals($expectedResult, $result); } public static function providerImSinHArray(): array { return [ 'row/column vector' => [ [ ['0.94150493327087-0.92349077604317i', '-0.59847214410396i', '-0.94150493327087-0.92349077604317i'], ['-0.63496391478474-1.298457581416i', '-0.8414709848079i', '0.63496391478474-1.298457581416i'], ['-0.63496391478474+1.298457581416i', '0.8414709848079i', '0.63496391478474+1.298457581416i'], ['0.94150493327087+0.92349077604317i', '0.59847214410396i', '-0.94150493327087+0.92349077604317i'], ], '{"-1-2.5i", "-2.5i", "1-2.5i"; "-1-i", "-i", "1-i"; "-1+i", "i", "1+1"; "-1+2.5i", "+2.5i", "1+2.5i"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/NaTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/NaTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\TestCase; class NaTest extends TestCase { public function testNA(): void { $result = ExcelError::NA(); self::assertEquals('#N/A', $result); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsErrTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsErrTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IsErrTest extends TestCase { public function testIsErrNoArgument(): void { $result = ErrorValue::isErr(); self::assertFalse($result); } #[DataProvider('providerIsErr')] public function testIsErr(bool $expectedResult, mixed $value): void { $result = ErrorValue::isErr($value); self::assertEquals($expectedResult, $result); } public static function providerIsErr(): array { return require 'tests/data/Calculation/Information/IS_ERR.php'; } #[DataProvider('providerIsErrArray')] public function testIsErrArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ISERR({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerIsErrArray(): array { return [ 'vector' => [ [[true, true, false, false, false, false]], '{5/0, "#REF!", "#N/A", 1.2, TRUE, "PHP"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsTextTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsTextTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IsTextTest extends TestCase { public function testIsTextNoArgument(): void { $result = Value::isText(); self::assertFalse($result); } #[DataProvider('providerIsText')] public function testIsText(bool $expectedResult, mixed $value): void { $result = Value::isText($value); self::assertEquals($expectedResult, $result); } public static function providerIsText(): array { return require 'tests/data/Calculation/Information/IS_TEXT.php'; } #[DataProvider('providerIsTextArray')] public function testIsTextArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ISTEXT({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerIsTextArray(): array { return [ 'vector' => [ [[false, true, true, false, false]], '{-2, "PHP", "123.456", false, 2.34}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsLogicalTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsLogicalTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IsLogicalTest extends TestCase { public function testIsLogicalNoArgument(): void { $result = Value::isLogical(); self::assertFalse($result); } #[DataProvider('providerIsLogical')] public function testIsLogical(bool $expectedResult, mixed $value): void { $result = Value::isLogical($value); self::assertEquals($expectedResult, $result); } public static function providerIsLogical(): array { return require 'tests/data/Calculation/Information/IS_LOGICAL.php'; } #[DataProvider('providerIsLogicalArray')] public function testIsLogicalArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ISLOGICAL({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerIsLogicalArray(): array { return [ 'vector' => [ [[true, false, false, false, true, false]], '{true, -1, null, 1, false, "FALSE"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsNaTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsNaTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IsNaTest extends TestCase { public function testIsNaNoArgument(): void { $result = ErrorValue::isNa(); self::assertFalse($result); } #[DataProvider('providerIsNa')] public function testIsNa(bool $expectedResult, mixed $value): void { $result = ErrorValue::isNa($value); self::assertEquals($expectedResult, $result); } public static function providerIsNa(): array { return require 'tests/data/Calculation/Information/IS_NA.php'; } #[DataProvider('providerIsNaArray')] public function testIsNaArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ISNA({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerIsNaArray(): array { return [ 'vector' => [ [[false, false, true, false, false, false]], '{5/0, "#REF!", "#N/A", 1.2, TRUE, "PHP"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/NTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/NTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PHPUnit\Framework\TestCase; class NTest extends TestCase { public function testNNoArgument(): void { $result = Value::asNumber(); self::assertSame(0, $result); } #[\PHPUnit\Framework\Attributes\DataProvider('providerN')] public function testN(mixed $expectedResult, mixed $value): void { $result = Value::asNumber($value); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } public static function providerN(): array { return require 'tests/data/Calculation/Information/N.php'; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsNonTextTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsNonTextTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IsNonTextTest extends TestCase { public function testIsNonTextNoArgument(): void { $result = Value::isNonText(); self::assertTrue($result); } #[DataProvider('providerIsNonText')] public function testIsNonText(bool $expectedResult, mixed $value): void { $result = Value::isNonText($value); self::assertEquals($expectedResult, $result); } public static function providerIsNonText(): array { return require 'tests/data/Calculation/Information/IS_NONTEXT.php'; } #[DataProvider('providerIsNonTextArray')] public function testIsNonTextArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ISNONTEXT({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerIsNonTextArray(): array { return [ 'vector' => [ [[true, false, false, true, true]], '{-2, "PHP", "123.456", false, 2.34}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/TypeTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/TypeTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PHPUnit\Framework\TestCase; class TypeTest extends TestCase { public function testTypeNoArgument(): void { $result = Value::type(); self::assertSame(1, $result); } #[\PHPUnit\Framework\Attributes\DataProvider('providerTYPE')] public function testTYPE(int $expectedResult, mixed $value): void { $result = Value::type($value); self::assertSame($expectedResult, $result); } public static function providerTYPE(): array { return require 'tests/data/Calculation/Information/TYPE.php'; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/NameTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/NameTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\TestCase; class NameTest extends TestCase { public function testNAME(): void { $result = ExcelError::NAME(); self::assertEquals('#NAME?', $result); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsNumberTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsNumberTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IsNumberTest extends TestCase { public function testIsNumberNoArgument(): void { $result = Value::isNumber(); self::assertFalse($result); } #[DataProvider('providerIsNumber')] public function testIsNumber(bool $expectedResult, mixed $value): void { $result = Value::isNumber($value); self::assertEquals($expectedResult, $result); } public static function providerIsNumber(): array { return require 'tests/data/Calculation/Information/IS_NUMBER.php'; } #[DataProvider('providerIsNumberArray')] public function testIsNumberArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ISNUMBER({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerIsNumberArray(): array { return [ 'vector' => [ [[true, false, false, false, true]], '{-2, "PHP", "123.456", false, 2.34}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/ErrorTypeTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/ErrorTypeTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class ErrorTypeTest extends TestCase { public function testErrorTypeNoArgument(): void { $result = ExcelError::type(); self::assertSame(ExcelError::NA(), $result); } #[DataProvider('providerErrorType')] public function testErrorType(int|string $expectedResult, mixed $value): void { $result = ExcelError::type($value); self::assertSame($expectedResult, $result); } public static function providerErrorType(): array { return require 'tests/data/Calculation/Information/ERROR_TYPE.php'; } #[DataProvider('providerErrorTypeArray')] public function testErrorTypeArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ERROR.TYPE({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerErrorTypeArray(): array { return [ 'vector' => [ [[2, 4, 7, ExcelError::NA(), ExcelError::NA(), ExcelError::NA(), 5]], '{5/0, "#REF!", "#N/A", 1.2, TRUE, "PHP", "#NAME?"}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsRefTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsRefTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\NamedRange; use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef\AllSetupTeardown; use PHPUnit\Framework\Attributes\DataProvider; class IsRefTest extends AllSetupTeardown { #[DataProvider('providerIsRef')] public function testIsRef(mixed $expected, string $ref): void { if ($expected === 'incomplete') { self::markTestIncomplete('Calculation is too complicated'); } $sheet = $this->getSheet(); $sheet->getParentOrThrow()->addDefinedName(new NamedRange('NAMED_RANGE', $sheet, 'C1')); $sheet->getCell('A1')->setValue("=ISREF($ref)"); self::assertSame($expected, $sheet->getCell('A1')->getCalculatedValue()); } public static function providerIsRef(): array { return [ 'cell reference' => [true, 'B1'], 'invalid cell reference' => [false, 'ZZZ1'], 'cell range' => [true, 'B1:B2'], 'complex cell range' => [true, 'B1:D4 C1:C5'], 'text string' => [false, '"PHP"'], 'math expression' => [false, 'B1*B2'], 'unquoted sheet name' => [true, 'Worksheet2!B1'], 'quoted sheet name' => [true, "'Worksheet2'!B1:B2"], 'quoted sheet name with apostrophe' => [true, "'Work''sheet2'!B1:B2"], 'named range' => [true, 'NAMED_RANGE'], 'unknown named range' => [false, 'xNAMED_RANGE'], 'indirect to a cell reference' => [true, 'INDIRECT("A1")'], 'indirect to a worksheet/cell reference' => [true, 'INDIRECT("\'Worksheet\'!A1")'], 'indirect to invalid worksheet/cell reference' => [false, 'INDIRECT("\'Invalid Worksheet\'!A1")'], 'returned cell reference' => ['incomplete', 'CHOOSE(2, A1, B1, C1)'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/NanTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/NanTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\TestCase; class NanTest extends TestCase { public function testNAN(): void { $result = ExcelError::NAN(); self::assertEquals('#NUM!', $result); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsOddTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsOddTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IsOddTest extends TestCase { public function testIsOddNoArgument(): void { $result = Value::isOdd(); self::assertSame(ExcelError::NAME(), $result); } #[DataProvider('providerIsOdd')] public function testIsOdd(bool|string $expectedResult, mixed $value): void { $result = Value::isOdd($value); self::assertEquals($expectedResult, $result); } public static function providerIsOdd(): array { return require 'tests/data/Calculation/Information/IS_ODD.php'; } #[DataProvider('providerIsOddArray')] public function testIsOddArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ISODD({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerIsOddArray(): array { return [ 'vector' => [ [[false, true, false, true, false]], '{-2, -1, 0, 1, 2}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/Div0Test.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/Div0Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\TestCase; class Div0Test extends TestCase { public function testDIV0(): void { $result = ExcelError::DIV0(); self::assertEquals('#DIV/0!', $result); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsFormulaTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsFormulaTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\NamedRange as NamedRange; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class IsFormulaTest extends TestCase { public function testIsFormula(): void { $spreadsheet = new Spreadsheet(); $calculation = Calculation::getInstance($spreadsheet); $calculation->setInstanceArrayReturnType( Calculation::RETURN_ARRAY_AS_VALUE ); $sheet1 = $spreadsheet->getActiveSheet(); $sheet1->setTitle('SheetOne'); // no space in sheet title $sheet2 = $spreadsheet->createSheet(); $sheet2->setTitle('Sheet Two'); // space in sheet title $values = [ [null, false], [-1, false], [0, false], [1, false], ['', false], [false, false], [true, false], ['=-1', true], ['="ABC"', true], ['=SUM(1,2,3)', true], ]; $row = 0; foreach ($values as $valArray) { ++$row; if ($valArray[0] !== null) { $sheet1->getCell("A$row")->setValue($valArray[0]); } $sheet1->getCell("B$row")->setValue("=ISFORMULA(A$row)"); self::assertSame($valArray[1], $sheet1->getCell("B$row")->getCalculatedValue(), "sheet1 error in B$row"); } $row = 0; foreach ($values as $valArray) { ++$row; if ($valArray[0] !== null) { $sheet2->getCell("A$row")->setValue($valArray[0]); } $sheet2->getCell("B$row")->setValue("=ISFORMULA(A$row)"); self::assertSame($valArray[1], $sheet2->getCell("B$row")->getCalculatedValue(), "sheet2 error in B$row"); } $sheet1->getCell('C1')->setValue(0); $sheet1->getCell('C2')->setValue('=0'); $sheet2->getCell('C3')->setValue(0); $sheet2->getCell('C4')->setValue('=0'); $sheet1->getCell('D1')->setValue('=ISFORMULA(SheetOne!C1)'); $sheet1->getCell('D2')->setValue('=ISFORMULA(SheetOne!C2)'); $sheet1->getCell('E1')->setValue('=ISFORMULA(\'SheetOne\'!C1)'); $sheet1->getCell('E2')->setValue('=ISFORMULA(\'SheetOne\'!C2)'); $sheet1->getCell('F1')->setValue('=ISFORMULA(\'Sheet Two\'!C3)'); $sheet1->getCell('F2')->setValue('=ISFORMULA(\'Sheet Two\'!C4)'); self::assertFalse($sheet1->getCell('D1')->getCalculatedValue()); self::assertTrue($sheet1->getCell('D2')->getCalculatedValue()); self::assertFalse($sheet1->getCell('E1')->getCalculatedValue()); self::assertTrue($sheet1->getCell('E2')->getCalculatedValue()); self::assertFalse($sheet1->getCell('F1')->getCalculatedValue()); self::assertTrue($sheet1->getCell('F2')->getCalculatedValue()); $spreadsheet->addNamedRange(new NamedRange('range1f', $sheet1, '$C$1')); $spreadsheet->addNamedRange(new NamedRange('range1t', $sheet1, '$C$2')); $spreadsheet->addNamedRange(new NamedRange('range2f', $sheet2, '$C$3')); $spreadsheet->addNamedRange(new NamedRange('range2t', $sheet2, '$C$4')); $spreadsheet->addNamedRange(new NamedRange('range2ft', $sheet2, '$C$3:$C$4')); $sheet1->getCell('G1')->setValue('=ISFORMULA(ABCDEFG)'); $sheet1->getCell('G3')->setValue('=ISFORMULA(range1f)'); $sheet1->getCell('G4')->setValue('=ISFORMULA(range1t)'); $sheet1->getCell('G5')->setValue('=ISFORMULA(range2f)'); $sheet1->getCell('G6')->setValue('=ISFORMULA(range2t)'); $sheet1->getCell('G7')->setValue('=ISFORMULA(range2ft)'); self::assertTrue( $sheet1->getCell('G1')->getCalculatedValue() ); self::assertFalse($sheet1->getCell('G3')->getCalculatedValue()); self::assertTrue($sheet1->getCell('G4')->getCalculatedValue()); self::assertFalse($sheet1->getCell('G5')->getCalculatedValue()); self::assertTrue($sheet1->getCell('G6')->getCalculatedValue()); self::assertFalse($sheet1->getCell('G7')->getCalculatedValue()); $sheet1->getCell('H1')->setValue('=ISFORMULA(C1:C2)'); $sheet1->getCell('H3')->setValue('=ISFORMULA(C2:C3)'); self::assertFalse($sheet1->getCell('H1')->getCalculatedValue()); self::assertTrue($sheet1->getCell('H3')->getCalculatedValue()); $spreadsheet->disconnectWorksheets(); } public function testIsFormulaArray(): void { $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue('=5/2'); $sheet->getCell('A2')->setValueExplicit('=5/2', DataType::TYPE_STRING); $sheet->getCell('A3')->setValue('=5/0'); $sheet->getCell('A4')->setValue(2.5); $sheet->getCell('A5')->setValue('=NA()'); $sheet->getCell('A6')->setValue(true); $sheet->getCell('A7')->setValue('=5/0'); $sheet->getCell('A7')->getStyle()->setQuotePrefix(true); $calculation = Calculation::getInstance($spreadsheet); $formula = '=ISFORMULA(A1:A7)'; $result = $calculation->calculateFormula($formula, 'C1', $sheet->getCell('C1')); self::assertSame([true, false, true, false, true, false, false], $result); $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/InfoTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/InfoTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class InfoTest extends TestCase { #[\PHPUnit\Framework\Attributes\DataProvider('providerINFO')] public function testINFO(mixed $expectedResult, string $typeText): void { $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue('=INFO("' . $typeText . '")'); $result = $sheet->getCell('A1')->getCalculatedValue(); self::assertSame($expectedResult, $result); $spreadsheet->disconnectWorksheets(); } public static function providerINFO(): array { return require 'tests/data/Calculation/Information/INFO.php'; } public function testINFONumfileWithThreeSheets(): void { $spreadsheet = new Spreadsheet(); $spreadsheet->createSheet(); $spreadsheet->createSheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue('=INFO("numfile")'); $result = $sheet->getCell('A1')->getCalculatedValue(); self::assertSame(3, $result); $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsBlankTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsBlankTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IsBlankTest extends TestCase { public function testIsBlankNoArgument(): void { $result = Value::isBlank(); self::assertTrue($result); } #[DataProvider('providerIsBlank')] public function testIsBlank(bool $expectedResult, mixed $value): void { $result = Value::isBlank($value); self::assertEquals($expectedResult, $result); } public static function providerIsBlank(): array { return require 'tests/data/Calculation/Information/IS_BLANK.php'; } #[DataProvider('providerIsBlankArray')] public function testIsBlankArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ISBLANK({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerIsBlankArray(): array { return [ 'vector' => [ [[false, true, false]], '{12, NULL, ""}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/ValueTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/ValueTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\TestCase; class ValueTest extends TestCase { public function testVALUE(): void { $result = ExcelError::VALUE(); self::assertEquals('#VALUE!', $result); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/NullTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/NullTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\TestCase; class NullTest extends TestCase { public function testNULL(): void { $result = ExcelError::null(); self::assertEquals('#NULL!', $result); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/RefTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/RefTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PHPUnit\Framework\TestCase; class RefTest extends TestCase { public function testREF(): void { $result = ExcelError::REF(); self::assertEquals('#REF!', $result); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsEvenTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsEvenTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; use PhpOffice\PhpSpreadsheet\Calculation\Information\Value; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IsEvenTest extends TestCase { public function testIsEvenNoArgument(): void { $result = Value::isEven(); self::assertSame(ExcelError::NAME(), $result); } #[DataProvider('providerIsEven')] public function testIsEven(bool|string $expectedResult, mixed $value): void { $result = Value::isEven($value); self::assertEquals($expectedResult, $result); } public static function providerIsEven(): array { return require 'tests/data/Calculation/Information/IS_EVEN.php'; } #[DataProvider('providerIsEvenArray')] public function testIsEvenArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ISEVEN({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerIsEvenArray(): array { return [ 'vector' => [ [[true, false, true, false, true]], '{-2, -1, 0, 1, 2}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsErrorTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/Information/IsErrorTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Information; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IsErrorTest extends TestCase { public function testIsErrorNoArgument(): void { $result = ErrorValue::isError(); self::assertFalse($result); } #[DataProvider('providerIsError')] public function testIsError(bool $expectedResult, mixed $value): void { $result = ErrorValue::isError($value); self::assertEquals($expectedResult, $result); } public static function providerIsError(): array { return require 'tests/data/Calculation/Information/IS_ERROR.php'; } #[DataProvider('providerIsErrorArray')] public function testIsErrorArray(array $expectedResult, string $values): void { $calculation = Calculation::getInstance(); $formula = "=ISERROR({$values})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerIsErrorArray(): array { return [ 'vector' => [ [[true, true, true, false, false, false, false]], '{5/0, "#REF!", "#N/A", 1.2, TRUE, "PHP", null}', ], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ErrorPropagationTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ErrorPropagationTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; class ErrorPropagationTest extends AllSetupTeardown { public function testErrorPropagation(): void { $sheet = $this->getSheet(); $sheet->getCell('A1')->setValue('=ABS("X")'); self::assertSame('#VALUE!', $sheet->getCell('A1')->getCalculatedValue()); $sheet->getCell('A2')->setValue('=SQRT(-1)'); self::assertSame('#NUM!', $sheet->getCell('A2')->getCalculatedValue()); $sheet->getCell('A3')->setValue('=3/0'); self::assertSame('#DIV/0!', $sheet->getCell('A3')->getCalculatedValue()); $sheet->getCell('A4')->setValue('=XXXX()'); self::assertSame('#NAME?', $sheet->getCell('A4')->getCalculatedValue()); $sheet->getCell('A5')->setValue('=ABS("X")'); self::assertSame('#VALUE!', $sheet->getCell('A5')->getCalculatedValue()); $sheet->getCell('B1')->setValue('=UPPER(A1)'); self::assertSame('#VALUE!', $sheet->getCell('A1')->getCalculatedValue()); $sheet->getCell('B2')->setValue('=LOWER(A2)'); self::assertSame('#NUM!', $sheet->getCell('A2')->getCalculatedValue()); $sheet->getCell('B3')->setValue('=PROPER(A3)'); self::assertSame('#DIV/0!', $sheet->getCell('A3')->getCalculatedValue()); $sheet->getCell('C2')->setValue('=CHAR(A2)'); self::assertSame('#NUM!', $sheet->getCell('C2')->getCalculatedValue()); $sheet->getCell('C3')->setValue('=CODE(A3)'); self::assertSame('#DIV/0!', $sheet->getCell('C3')->getCalculatedValue()); $sheet->getCell('D1')->setValue('=CONCATENATE(A1,A1)'); self::assertSame('#VALUE!', $sheet->getCell('D1')->getCalculatedValue()); $sheet->getCell('D2')->setValue('=TEXTJOIN(",",TRUE,A2,A3)'); self::assertSame('#NUM!', $sheet->getCell('D2')->getCalculatedValue()); $sheet->getCell('D3')->setValue('=REPT(A3,3)'); self::assertSame('#DIV/0!', $sheet->getCell('D3')->getCalculatedValue()); $sheet->getCell('D4')->setValue('=CONCAT(A4,A4)'); self::assertSame('#NAME?', $sheet->getCell('D4')->getCalculatedValue()); $sheet->getCell('D5')->setValue('="X"&A4'); self::assertSame('#NAME?', $sheet->getCell('D5')->getCalculatedValue()); $sheet->getCell('D6')->setValue('=A2&"X"'); self::assertSame('#NUM!', $sheet->getCell('D6')->getCalculatedValue()); $sheet->getCell('E1')->setValue('=LEFT(A1)'); self::assertSame('#VALUE!', $sheet->getCell('E1')->getCalculatedValue()); $sheet->getCell('E2')->setValue('=RIGHT(A2)'); self::assertSame('#NUM!', $sheet->getCell('E2')->getCalculatedValue()); $sheet->getCell('E3')->setValue('=MID(A3,2,2)'); self::assertSame('#DIV/0!', $sheet->getCell('E3')->getCalculatedValue()); $sheet->getCell('E4')->setValue('=TEXTBEFORE(A4,"M")'); self::assertSame('#NAME?', $sheet->getCell('E4')->getCalculatedValue()); $sheet->getCell('E5')->setValue('=TEXTAFTER(A5,"U")'); self::assertSame('#VALUE!', $sheet->getCell('E5')->getCalculatedValue()); $sheet->getCell('F1')->setValue('=VALUETOTEXT(A1)'); self::assertSame('#VALUE!', $sheet->getCell('F1')->getCalculatedValue()); $sheet->getCell('F2')->setValue('=DOLLAR(A2)'); self::assertSame('#NUM!', $sheet->getCell('F2')->getCalculatedValue()); $sheet->getCell('F3')->setValue('=FIXED(A3)'); self::assertSame('#DIV/0!', $sheet->getCell('E3')->getCalculatedValue()); $sheet->getCell('F4')->setValue('=TEXT(A4,"M")'); self::assertSame('#NAME?', $sheet->getCell('F4')->getCalculatedValue()); $sheet->getCell('F5')->setValue('=VALUE(A2)'); self::assertSame('#NUM!', $sheet->getCell('F5')->getCalculatedValue()); $sheet->getCell('F6')->setValue('=NUMBERVALUE(A3)'); self::assertSame('#DIV/0!', $sheet->getCell('F6')->getCalculatedValue()); $sheet->getCell('G1')->setValue('=REPLACE("oldtext",2,2,A1)'); self::assertSame('#VALUE!', $sheet->getCell('G1')->getCalculatedValue()); $sheet->getCell('G2')->setValue('=SUBSTITUTE(A2,"U","V")'); self::assertSame('#NUM!', $sheet->getCell('G2')->getCalculatedValue()); $sheet->getCell('H1')->setValue('=FIND(A1, "U")'); self::assertSame('#VALUE!', $sheet->getCell('H1')->getCalculatedValue()); $sheet->getCell('H2')->setValue('=SEARCH(A2,"U")'); self::assertSame('#NUM!', $sheet->getCell('H2')->getCalculatedValue()); $sheet->getCell('I1')->setValue('=LEN(A1)'); self::assertSame('#VALUE!', $sheet->getCell('I1')->getCalculatedValue()); $sheet->getCell('I2')->setValue('=EXACT(A2,A2)'); self::assertSame('#NUM!', $sheet->getCell('I2')->getCalculatedValue()); $sheet->getCell('I3')->setValue('=T(A3)'); self::assertSame('#DIV/0!', $sheet->getCell('I3')->getCalculatedValue()); $sheet->getCell('I4')->setValue('=TEXTSPLIT(A4,"M")'); self::assertSame('#NAME?', $sheet->getCell('I4')->getCalculatedValue()); $sheet->getCell('J1')->setValue('=TRIM(A1)'); self::assertSame('#VALUE!', $sheet->getCell('J1')->getCalculatedValue()); $sheet->getCell('J2')->setValue('=CLEAN(A2)'); self::assertSame('#NUM!', $sheet->getCell('J2')->getCalculatedValue()); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Settings; use PHPUnit\Framework\Attributes\DataProvider; class MidTest extends AllSetupTeardown { /** * @param mixed $str string from which to extract * @param mixed $start position at which to start * @param mixed $cnt number of characters to extract */ #[DataProvider('providerMID')] public function testMID(mixed $expectedResult, mixed $str = 'omitted', mixed $start = 'omitted', mixed $cnt = 'omitted'): void { $this->mightHaveException($expectedResult); $sheet = $this->getSheet(); if ($str === 'omitted') { $sheet->getCell('B1')->setValue('=MID()'); } elseif ($start === 'omitted') { $this->setCell('A1', $str); $sheet->getCell('B1')->setValue('=MID(A1)'); } elseif ($cnt === 'omitted') { $this->setCell('A1', $str); $this->setCell('A2', $start); $sheet->getCell('B1')->setValue('=MID(A1, A2)'); } else { $this->setCell('A1', $str); $this->setCell('A2', $start); $this->setCell('A3', $cnt); $sheet->getCell('B1')->setValue('=MID(A1, A2, A3)'); } $result = $sheet->getCell('B1')->getCalculatedValue(); self::assertEquals($expectedResult, $result); } public static function providerMID(): array { return require 'tests/data/Calculation/TextData/MID.php'; } #[DataProvider('providerLocaleMID')] public function testMiddleWithLocaleBoolean(string $expectedResult, string $locale, mixed $value, mixed $offset, mixed $characters): void { $newLocale = Settings::setLocale($locale); if ($newLocale === false) { self::markTestSkipped('Unable to set locale for locale-specific test'); } $sheet = $this->getSheet(); $this->setCell('A1', $value); $this->setCell('A2', $offset); $this->setCell('A3', $characters); $sheet->getCell('B1')->setValue('=MID(A1, A2, A3)'); $result = $sheet->getCell('B1')->getCalculatedValue(); self::assertEquals($expectedResult, $result); } public static function providerLocaleMID(): array { return [ ['RA', 'fr_FR', true, 2, 2], ['AA', 'nl_NL', true, 2, 2], ['OS', 'fi', true, 2, 2], ['СТИН', 'bg', true, 2, 4], ['AU', 'fr_FR', false, 2, 2], ['NWA', 'nl_NL', false, 2, 3], ['PÄTO', 'fi', false, 2, 4], ['ОЖ', 'bg', false, 2, 2], ]; } #[DataProvider('providerCalculationTypeMIDTrue')] public function testCalculationTypeTrue(string $type, string $resultB1, string $resultB2, string $resultB3): void { Functions::setCompatibilityMode($type); $sheet = $this->getSheet(); $this->setCell('A1', true); $this->setCell('A2', 'hello'); $this->setCell('B1', '=MID(A1, 3, 1)'); $this->setCell('B2', '=MID(A2, A1, 1)'); $this->setCell('B3', '=MID(A2, 2, A1)'); self::assertEquals($resultB1, $sheet->getCell('B1')->getCalculatedValue()); self::assertEquals($resultB2, $sheet->getCell('B2')->getCalculatedValue()); self::assertEquals($resultB3, $sheet->getCell('B3')->getCalculatedValue()); } public static function providerCalculationTypeMIDTrue(): array { return [ 'Excel MID(true,3,1), MID("hello",true, 1), MID("hello", 2, true)' => [ Functions::COMPATIBILITY_EXCEL, 'U', 'h', 'e', ], 'Gnumeric MID(true,3,1), MID("hello",true, 1), MID("hello", 2, true)' => [ Functions::COMPATIBILITY_GNUMERIC, 'U', 'h', 'e', ], 'OpenOffice MID(true,3,1), MID("hello",true, 1), MID("hello", 2, true)' => [ Functions::COMPATIBILITY_OPENOFFICE, '', '#VALUE!', '#VALUE!', ], ]; } #[DataProvider('providerCalculationTypeMIDFalse')] public function testCalculationTypeFalse(string $type, string $resultB1, string $resultB2, string $resultB3): void { Functions::setCompatibilityMode($type); $sheet = $this->getSheet(); $this->setCell('A1', false); $this->setCell('A2', 'Hello'); $this->setCell('B1', '=MID(A1, 3, 1)'); $this->setCell('B2', '=MID(A2, A1, 1)'); $this->setCell('B3', '=MID(A2, 2, A1)'); self::assertEquals($resultB1, $sheet->getCell('B1')->getCalculatedValue()); self::assertEquals($resultB2, $sheet->getCell('B2')->getCalculatedValue()); self::assertEquals($resultB3, $sheet->getCell('B3')->getCalculatedValue()); } public static function providerCalculationTypeMIDFalse(): array { return [ 'Excel MID(false,3,1), MID("hello", false, 1), MID("hello", 2, false)' => [ Functions::COMPATIBILITY_EXCEL, 'L', '#VALUE!', '', ], 'Gnumeric MID(false,3,1), MID("hello", false, 1), MID("hello", 2, false)' => [ Functions::COMPATIBILITY_GNUMERIC, 'L', '#VALUE!', '', ], 'OpenOffice MID(false,3,1), MID("hello", false, 1), MID("hello", 2, false)' => [ Functions::COMPATIBILITY_OPENOFFICE, '', '#VALUE!', '#VALUE!', ], ]; } #[DataProvider('providerCalculationTypeMIDNull')] public function testCalculationTypeNull(string $type, string $resultB1, string $resultB2, string $resultB3): void { Functions::setCompatibilityMode($type); $sheet = $this->getSheet(); $this->setCell('A2', 'Hello'); $this->setCell('B1', '=MID(A1, 3, 1)'); $this->setCell('B2', '=MID(A2, A1, 1)'); $this->setCell('B3', '=MID(A2, 2, A1)'); self::assertEquals($resultB1, $sheet->getCell('B1')->getCalculatedValue()); self::assertEquals($resultB2, $sheet->getCell('B2')->getCalculatedValue()); self::assertEquals($resultB3, $sheet->getCell('B3')->getCalculatedValue()); } public static function providerCalculationTypeMIDNull(): array { return [ 'Excel MID(null,3,1), MID("hello", null, 1), MID("hello", 2, null)' => [ Functions::COMPATIBILITY_EXCEL, '', '#VALUE!', '', ], 'Gnumeric MID(null,3,1), MID("hello", null, 1), MID("hello", 2, null)' => [ Functions::COMPATIBILITY_GNUMERIC, '', '#VALUE!', '', ], 'OpenOffice MID(null,3,1), MID("hello", null, 1), MID("hello", 2, null)' => [ Functions::COMPATIBILITY_OPENOFFICE, '', '#VALUE!', '', ], ]; } /** @param mixed[] $expectedResult */ #[DataProvider('providerMidArray')] public function testMidArray(array $expectedResult, string $argument1, string $argument2, string $argument3): void { $calculation = Calculation::getInstance(); $formula = "=MID({$argument1}, {$argument2}, {$argument3})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerMidArray(): array { return [ 'row vector #1' => [[['lo Wor', 'Spread']], '{"Hello World", "PhpSpreadsheet"}', '4', '6'], 'column vector #1' => [[[' Wor'], ['read']], '{"Hello World"; "PhpSpreadsheet"}', '6', '4'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PHPUnit\Framework\Attributes\DataProvider; class LenTest extends AllSetupTeardown { #[DataProvider('providerLEN')] public function testLEN(mixed $expectedResult, mixed $str = 'omitted'): void { $this->mightHaveException($expectedResult); $sheet = $this->getSheet(); if ($str === 'omitted') { $sheet->getCell('B1')->setValue('=LEN()'); } else { $this->setCell('A1', $str); $sheet->getCell('B1')->setValue('=LEN(A1)'); } $result = $sheet->getCell('B1')->getCalculatedValue(); self::assertEquals($expectedResult, $result); } public static function providerLEN(): array { return require 'tests/data/Calculation/TextData/LEN.php'; } /** @param mixed[] $expectedResult */ #[DataProvider('providerLenArray')] public function testLenArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); $formula = "=LEN({$array})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerLenArray(): array { return [ 'row vector' => [[[3, 11, 14]], '{"PHP", "Hello World", "PhpSpreadsheet"}'], 'column vector' => [[[3], [11], [14]], '{"PHP"; "Hello World"; "PhpSpreadsheet"}'], 'matrix' => [[[3, 9], [11, 14]], '{"PHP", "ElePHPant"; "Hello World", "PhpSpreadsheet"}'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PHPUnit\Framework\Attributes\DataProvider; class TrimTest extends AllSetupTeardown { #[DataProvider('providerTRIM')] public function testTRIM(mixed $expectedResult, mixed $character = 'omitted'): void { $this->mightHaveException($expectedResult); $sheet = $this->getSheet(); if ($character === 'omitted') { $sheet->getCell('B1')->setValue('=TRIM()'); } else { $this->setCell('A1', $character); $sheet->getCell('B1')->setValue('=TRIM(A1)'); } $result = $sheet->getCell('B1')->getCalculatedValue(); self::assertEquals($expectedResult, $result); } public static function providerTRIM(): array { return require 'tests/data/Calculation/TextData/TRIM.php'; } /** @param mixed[] $expectedResult */ #[DataProvider('providerTrimArray')] public function testTrimArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); $formula = "=TRIM({$array})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerTrimArray(): array { return [ 'row vector' => [[['PHP', 'MS Excel', 'Open/Libre Office']], '{" PHP ", " MS Excel ", " Open/Libre Office "}'], 'column vector' => [[['PHP'], ['MS Excel'], ['Open/Libre Office']], '{" PHP "; " MS Excel "; " Open/Libre Office "}'], 'matrix' => [[['PHP', 'MS Excel'], ['PhpSpreadsheet', 'Open/Libre Office']], '{" PHP ", " MS Excel "; " PhpSpreadsheet ", " Open/Libre Office "}'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PHPUnit\Framework\Attributes\DataProvider; class FixedTest extends AllSetupTeardown { #[DataProvider('providerFIXED')] public function testFIXED(mixed $expectedResult, mixed $number = 'omitted', mixed $decimals = 'omitted', mixed $noCommas = 'omitted'): void { $this->mightHaveException($expectedResult); $sheet = $this->getSheet(); if ($number === 'omitted') { $sheet->getCell('B1')->setValue('=FIXED()'); } elseif ($decimals === 'omitted') { $this->setCell('A1', $number); $sheet->getCell('B1')->setValue('=FIXED(A1)'); } elseif ($noCommas === 'omitted') { $this->setCell('A1', $number); $this->setCell('A2', $decimals); $sheet->getCell('B1')->setValue('=FIXED(A1, A2)'); } else { $this->setCell('A1', $number); $this->setCell('A2', $decimals); $this->setCell('A3', $noCommas); $sheet->getCell('B1')->setValue('=FIXED(A1, A2, A3)'); } $result = $sheet->getCell('B1')->getCalculatedValue(); self::assertEquals($expectedResult, $result); } public static function providerFIXED(): array { return require 'tests/data/Calculation/TextData/FIXED.php'; } /** @param mixed[] $expectedResult */ #[DataProvider('providerFixedArray')] public function testFixedArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); $formula = "=FIXED({$argument1}, {$argument2})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerFixedArray(): array { return [ 'row vector #1' => [[['-123.32', '123.46', '12,345.68']], '{-123.321, 123.456, 12345.6789}', '2'], 'column vector #1' => [[['-123.32'], ['123.46'], ['12,345.68']], '{-123.321; 123.456; 12345.6789}', '2'], 'matrix #1' => [[['-123.46', '12,345.68'], ['-123.456', '12,345.679']], '{-123.456, 12345.6789}', '{2; 3}'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UnicodeTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UnicodeTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PHPUnit\Framework\Attributes\DataProvider; class UnicodeTest extends AllSetupTeardown { #[DataProvider('providerCODE')] public function testCODE(mixed $expectedResult, mixed $character = 'omitted'): void { // If expected is array, 1st is for CODE, 2nd for UNICODE, // 3rd is for Mac CODE if different from Windows. if (is_array($expectedResult)) { $expectedResult = $expectedResult[1]; } $this->mightHaveException($expectedResult); $sheet = $this->getSheet(); if ($character === 'omitted') { $sheet->getCell('B1')->setValue('=UNICODE()'); } else { $this->setCell('A1', $character); $sheet->getCell('B1')->setValue('=UNICODE(A1)'); } $result = $sheet->getCell('B1')->getCalculatedValue(); self::assertEquals($expectedResult, $result); } public static function providerCODE(): array { return require 'tests/data/Calculation/TextData/CODE.php'; } /** @param mixed[] $expectedResult */ #[DataProvider('providerCodeArray')] public function testCodeArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); $formula = "=UNICODE({$array})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerCodeArray(): array { return [ 'row vector' => [[[80, 72, 80]], '{"P", "H", "P"}'], 'column vector' => [[[80], [72], [80]], '{"P"; "H"; "P"}'], 'matrix' => [[[89, 111], [108, 111]], '{"Y", "o"; "l", "o"}'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/AllSetupTeardown.php
tests/PhpSpreadsheetTests/Calculation/Functions/TextData/AllSetupTeardown.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PHPUnit\Framework\TestCase; class AllSetupTeardown extends TestCase { private string $compatibilityMode; private string $locale; private ?Spreadsheet $spreadsheet = null; private ?Worksheet $sheet = null; protected function setUp(): void { $this->locale = Settings::getLocale(); $this->compatibilityMode = Functions::getCompatibilityMode(); } protected function tearDown(): void { Functions::setCompatibilityMode($this->compatibilityMode); Settings::setLocale($this->locale); $this->sheet = null; if ($this->spreadsheet !== null) { $this->spreadsheet->disconnectWorksheets(); $this->spreadsheet = null; } } protected static function setOpenOffice(): void { Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE); } protected static function setGnumeric(): void { Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC); } protected function mightHaveException(mixed $expectedResult): void { if ($expectedResult === 'exception') { $this->expectException(CalcException::class); } } protected function setCell(string $cell, mixed $value): void { if ($value !== null) { if (is_string($value) && is_numeric($value)) { $this->getSheet()->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING); } else { $this->getSheet()->getCell($cell)->setValue($value); } } } protected function getSpreadsheet(): Spreadsheet { if ($this->spreadsheet !== null) { return $this->spreadsheet; } $this->spreadsheet = new Spreadsheet(); return $this->spreadsheet; } protected function getSheet(): Worksheet { if ($this->sheet !== null) { return $this->sheet; } $this->sheet = $this->getSpreadsheet()->getActiveSheet(); return $this->sheet; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ArrayToTextTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ArrayToTextTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\Attributes\DataProvider; class ArrayToTextTest extends AllSetupTeardown { /** @param mixed[] $testData */ #[DataProvider('providerARRAYTOTEXT')] public function testArrayToText(string $expectedResult, array $testData, int $mode): void { $worksheet = $this->getSheet(); $worksheet->fromArray($testData, null, 'A1', true); $worksheet->getCell('H1')->setValue("=ARRAYTOTEXT(A1:C5, {$mode})"); $result = $worksheet->getCell('H1')->getCalculatedValue(); $b1SimpleCast = '12345.6789'; $b1AccurateCast = StringHelper::convertToString(12345.6789); $expectedResult = str_replace($b1SimpleCast, $b1AccurateCast, $expectedResult); self::assertSame($expectedResult, $result); } public static function providerARRAYTOTEXT(): array { return require 'tests/data/Calculation/TextData/ARRAYTOTEXT.php'; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReptTest.php
tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReptTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PHPUnit\Framework\Attributes\DataProvider; class ReptTest extends AllSetupTeardown { #[DataProvider('providerREPT')] public function testReptThroughEngine(mixed $expectedResult, mixed $val = 'omitted', mixed $rpt = 'omitted'): void { $this->mightHaveException($expectedResult); $sheet = $this->getSheet(); if ($val === 'omitted') { $sheet->getCell('B1')->setValue('=REPT()'); } elseif ($rpt === 'omitted') { $this->setCell('A1', $val); $sheet->getCell('B1')->setValue('=REPT(A1)'); } else { $this->setCell('A1', $val); $this->setCell('A2', $rpt); $sheet->getCell('B1')->setValue('=REPT(A1, A2)'); } $result = $sheet->getCell('B1')->getCalculatedValue(); self::assertEquals($expectedResult, $result); } public static function providerREPT(): array { return require 'tests/data/Calculation/TextData/REPT.php'; } /** @param mixed[] $expectedResult */ #[DataProvider('providerReptArray')] public function testReptArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); $formula = "=REPT({$argument1}, {$argument2})"; $result = $calculation->calculateFormula($formula); self::assertSame($expectedResult, $result); } public static function providerReptArray(): array { return [ 'row vector #1' => [[['PHPPHPPHP', 'HAHAHA', 'HOHOHO']], '{"PHP", "HA", "HO"}', '3'], 'column vector #1' => [[['PHPPHPPHP'], ['HAHAHA'], ['HOHOHO']], '{"PHP"; "HA"; "HO"}', '3'], 'matrix #1' => [[['PHPPHP', '❤️🐘💚❤️🐘💚'], ['HAHA', 'HOHO']], '{"PHP", "❤️🐘💚"; "HA", "HO"}', '2'], 'row vector #2' => [[[' PHP PHP PHP ', ' PHP PHP ']], '" PHP "', '{3, 2}'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false