Files
oleibman 70b4ecd4d3 Use calculateFormula Rather Than _calculateFormulaValue in Tests
They aren't quite interchangeable. Both are used in the test suite, with no indication of why one or the other. I think we'd be best off being consistent. Based on the names, I think `_calculateFormulaValue` was intended as a private, or at least internal, method, so favor `calculateFormula`. I do not intend to rename or re-categorize `_calculateFormulaValue`, just remove its usage when it isn't clearly warranted.
2025-11-13 20:48:46 -08:00

50 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class DegreesTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerDEGREES')]
public function testDegrees(mixed $expectedResult, mixed $number = 'omitted'): void
{
$sheet = $this->getSheet();
$this->mightHaveException($expectedResult);
$this->setCell('A1', $number);
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=DEGREES()');
} else {
$sheet->getCell('B1')->setValue('=DEGREES(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}
public static function providerDegrees(): array
{
return require 'tests/data/Calculation/MathTrig/DEGREES.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerDegreesArray')]
public function testDegreesArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=DEGREES({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}
public static function providerDegreesArray(): array
{
return [
'row vector' => [[[143.23944878270600, 7.16197243913529, -183.34649444186300]], '{2.5, 0.125, -3.2}'],
'column vector' => [[[143.23944878270600], [7.16197243913529], [-183.34649444186300]], '{2.5; 0.125; -3.2}'],
'matrix' => [[[143.23944878270600, 7.16197243913529], [429.71834634811700, -183.34649444186300]], '{2.5, 0.125; 7.5, -3.2}'],
];
}
}