PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/MathTrigTest.php

604 lines
16 KiB
PHP
Raw Normal View History

2012-07-31 20:56:11 +00:00
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
2012-07-31 20:56:11 +00:00
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Worksheet\RowDimension;
use PhpOffice\PhpSpreadsheet\Worksheet\ColumnDimension;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PHPUnit\Framework\TestCase;
class MathTrigTest extends TestCase
2012-07-31 20:56:11 +00:00
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerATAN2
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testATAN2($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::ATAN2(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerATAN2()
{
return require 'data/Calculation/MathTrig/ATAN2.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerCEILING
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testCEILING($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::CEILING(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerCEILING()
{
return require 'data/Calculation/MathTrig/CEILING.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerCOMBIN
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testCOMBIN($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::COMBIN(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerCOMBIN()
{
return require 'data/Calculation/MathTrig/COMBIN.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerEVEN
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testEVEN($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::EVEN(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerEVEN()
{
return require 'data/Calculation/MathTrig/EVEN.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerODD
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testODD($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::ODD(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerODD()
{
return require 'data/Calculation/MathTrig/ODD.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerFACT
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testFACT($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::FACT(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerFACT()
{
return require 'data/Calculation/MathTrig/FACT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerFACTDOUBLE
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testFACTDOUBLE($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::FACTDOUBLE(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerFACTDOUBLE()
{
return require 'data/Calculation/MathTrig/FACTDOUBLE.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerFLOOR
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testFLOOR($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::FLOOR(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerFLOOR()
{
return require 'data/Calculation/MathTrig/FLOOR.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerGCD
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testGCD($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::GCD(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerGCD()
{
return require 'data/Calculation/MathTrig/GCD.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerLCM
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testLCM($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::LCM(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerLCM()
{
return require 'data/Calculation/MathTrig/LCM.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerINT
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testINT($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::INT(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerINT()
{
return require 'data/Calculation/MathTrig/INT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerSIGN
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testSIGN($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::SIGN(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerSIGN()
{
return require 'data/Calculation/MathTrig/SIGN.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerPOWER
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testPOWER($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::POWER(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerPOWER()
{
return require 'data/Calculation/MathTrig/POWER.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerLOG
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testLOG($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::logBase(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerLOG()
{
return require 'data/Calculation/MathTrig/LOG.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMOD
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMOD($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::MOD(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMOD()
{
return require 'data/Calculation/MathTrig/MOD.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMDETERM
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMDETERM($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::MDETERM(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMDETERM()
{
return require 'data/Calculation/MathTrig/MDETERM.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMINVERSE
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMINVERSE($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$this->markTestIncomplete('TODO: This test should be fixed');
$result = MathTrig::MINVERSE(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMINVERSE()
{
return require 'data/Calculation/MathTrig/MINVERSE.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMMULT
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMMULT($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$this->markTestIncomplete('TODO: This test should be fixed');
$result = MathTrig::MMULT(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMMULT()
{
return require 'data/Calculation/MathTrig/MMULT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMULTINOMIAL
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMULTINOMIAL($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::MULTINOMIAL(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMULTINOMIAL()
{
return require 'data/Calculation/MathTrig/MULTINOMIAL.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerMROUND
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testMROUND($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE);
$result = MathTrig::MROUND(...$args);
Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerMROUND()
{
return require 'data/Calculation/MathTrig/MROUND.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerPRODUCT
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testPRODUCT($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::PRODUCT(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerPRODUCT()
{
return require 'data/Calculation/MathTrig/PRODUCT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerQUOTIENT
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testQUOTIENT($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::QUOTIENT(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerQUOTIENT()
{
return require 'data/Calculation/MathTrig/QUOTIENT.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerROUNDUP
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testROUNDUP($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::ROUNDUP(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerROUNDUP()
{
return require 'data/Calculation/MathTrig/ROUNDUP.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerROUNDDOWN
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testROUNDDOWN($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::ROUNDDOWN(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerROUNDDOWN()
{
return require 'data/Calculation/MathTrig/ROUNDDOWN.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerSERIESSUM
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testSERIESSUM($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::SERIESSUM(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerSERIESSUM()
{
return require 'data/Calculation/MathTrig/SERIESSUM.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerSUMSQ
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testSUMSQ($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::SUMSQ(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerSUMSQ()
{
return require 'data/Calculation/MathTrig/SUMSQ.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerTRUNC
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testTRUNC($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::TRUNC(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerTRUNC()
{
return require 'data/Calculation/MathTrig/TRUNC.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerROMAN
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testROMAN($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::ROMAN(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerROMAN()
{
return require 'data/Calculation/MathTrig/ROMAN.php';
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
/**
* @dataProvider providerSQRTPI
*
* @param mixed $expectedResult
2012-07-31 20:56:11 +00:00
*/
public function testSQRTPI($expectedResult, ...$args)
2015-05-17 13:00:02 +00:00
{
$result = MathTrig::SQRTPI(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
2015-05-17 13:00:02 +00:00
}
2012-07-31 20:56:11 +00:00
public function providerSQRTPI()
{
return require 'data/Calculation/MathTrig/SQRTPI.php';
}
/**
* @dataProvider providerSUMIF
*
* @param mixed $expectedResult
*/
public function testSUMIF($expectedResult, ...$args)
{
$result = MathTrig::SUMIF(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerSUMIF()
{
return require 'data/Calculation/MathTrig/SUMIF.php';
2015-05-17 13:00:02 +00:00
}
/**
* @dataProvider providerSUBTOTAL
*
* @param mixed $expectedResult
*/
public function testSUBTOTAL($expectedResult, ...$args)
{
$cell = $this->getMockBuilder(Cell::class)
->setMethods(['getValue'])
->disableOriginalConstructor()
->getMock();
$cell->method('getValue')
->willReturn(null);
$worksheet = $this->getMockBuilder(Worksheet::class)
->setMethods(['cellExists', 'getCell'])
->disableOriginalConstructor()
->getMock();
$worksheet->method('cellExists')
->willReturn(true);
$worksheet->method('getCell')
->willReturn($cell);
$cellReference = $this->getMockBuilder(Cell::class)
->setMethods(['getWorksheet'])
->disableOriginalConstructor()
->getMock();
$cellReference->method('getWorksheet')
->willReturn($worksheet);
array_push($args, $cellReference);
$result = MathTrig::SUBTOTAL(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerSUBTOTAL()
{
return require 'data/Calculation/MathTrig/SUBTOTAL.php';
}
protected static function rowVisibility() {
yield from [1 => false, 2 => true, 3 => false, 4 => true, 5 => false, 6 => false, 7 => false, 8 => true, 9 => false, 10 => true, 11 =>true];
}
/**
* @dataProvider providerSUBTOTALHIDDEN
*
* @param mixed $expectedResult
*/
public function testSUBTOTALHIDDEN($expectedResult, ...$args)
{
$generator = \PhpOffice\PhpSpreadsheetTests\Calculation\MathTrigTest::rowVisibility();
$rowDimension = $this->getMockBuilder(RowDimension::class)
->setMethods(['getVisible'])
->disableOriginalConstructor()
->getMock();
$rowDimension->method('getVisible')
->will($this->returnCallback(function() use ($generator) { $result = $generator->current(); $generator->next(); return $result; }));
$columnDimension = $this->getMockBuilder(ColumnDimension::class)
->setMethods(['getVisible'])
->disableOriginalConstructor()
->getMock();
$columnDimension->method('getVisible')
->willReturn(true);
$cell = $this->getMockBuilder(Cell::class)
->setMethods(['getValue'])
->disableOriginalConstructor()
->getMock();
$cell->method('getValue')
->willReturn('');
$worksheet = $this->getMockBuilder(Worksheet::class)
->setMethods(['cellExists', 'getCell', 'getRowDimension', 'getColumnDimension'])
->disableOriginalConstructor()
->getMock();
$worksheet->method('cellExists')
->willReturn(true);
$worksheet->method('getCell')
->willReturn($cell);
$worksheet->method('getRowDimension')
->willReturn($rowDimension);
$worksheet->method('getColumnDimension')
->willReturn($columnDimension);
$cellReference = $this->getMockBuilder(Cell::class)
->setMethods(['getWorksheet'])
->disableOriginalConstructor()
->getMock();
$cellReference->method('getWorksheet')
->willReturn($worksheet);
array_push($args, $cellReference);
$result = MathTrig::SUBTOTAL(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
}
public function providerSUBTOTALHIDDEN()
{
return require 'data/Calculation/MathTrig/SUBTOTALHIDDEN.php';
}
2012-07-31 20:56:11 +00:00
}