Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php
T
oleibman 0ce8509a8c Continue MathTrig Breakup - Trig Functions (#1905)
* Continue MathTrig Breakup - Trig Functions

Continuing the process of breaking MathTrip.php up into smaller classes.
This round takes care of the trig and hyperbolic functions, plus a few others.
- COS, COSH, ACOS, ACOSH
- COT, COTH, ACOT, ACOTH
- CSC, CSCH
- SEC, SECH
- SIN, SINH, ASIN, ASINH
- TAN, TANH, ATAN, ATANH, ATAN2
- EVEN
- ODD
- SIGN

There are no bug fixes in this PR, except that boolean arguments are now
accepted for all these functions, as they are for Excel.
Taking a cue from what has been done in Engineering, the parameter validation
now happens in a routine which issues Exceptions for invalid values;
this simplifies the code in the functions themselves.

Consistent with earlier changes of this nature, the versions in the
MathTrig class remain, with a doc block indicating deprecation,
and a stub call to the new routines.

I think several more iterations will be needed to break up MathTrig completely.
2021-03-13 12:06:30 +01:00

37 lines
1.0 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class SignTest extends TestCase
{
/**
* @dataProvider providerSIGN
*
* @param mixed $expectedResult
* @param $value
*/
public function testSIGN($expectedResult, $value): void
{
if ($expectedResult === 'exception') {
$this->expectException(CalcExp::class);
}
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 0);
$sheet->setCellValue('A4', -3.8);
$sheet->getCell('A1')->setValue("=SIGN($value)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public function providerSIGN()
{
return require 'tests/data/Calculation/MathTrig/SIGN.php';
}
}