1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation; |
8
|
|
|
|
9
|
|
|
class CeilingTest extends AllSetupTeardown |
10
|
|
|
{ |
11
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerCEILING')] |
12
|
|
|
public function testCEILING(mixed $expectedResult, string $formula): void |
13
|
|
|
{ |
14
|
|
|
$this->mightHaveException($expectedResult); |
15
|
|
|
$sheet = $this->getSheet(); |
16
|
|
|
$sheet->setCellValue('A2', 1.3); |
17
|
|
|
$sheet->setCellValue('A3', 2.7); |
18
|
|
|
$sheet->setCellValue('A4', -3.8); |
19
|
|
|
$sheet->setCellValue('A5', -5.2); |
20
|
|
|
$sheet->getCell('A1')->setValue("=CEILING($formula)"); |
21
|
|
|
$result = $sheet->getCell('A1')->getCalculatedValue(); |
22
|
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public static function providerCEILING(): array |
26
|
|
|
{ |
27
|
|
|
return require 'tests/data/Calculation/MathTrig/CEILING.php'; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testCEILINGGnumeric1Arg(): void |
31
|
|
|
{ |
32
|
|
|
self::setGnumeric(); |
33
|
|
|
$sheet = $this->getSheet(); |
34
|
|
|
$sheet->getCell('A1')->setValue('=CEILING(5.1)'); |
35
|
|
|
$result = $sheet->getCell('A1')->getCalculatedValue(); |
36
|
|
|
self::assertEqualsWithDelta(6, $result, 1E-12); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testCELINGOpenOffice1Arg(): void |
40
|
|
|
{ |
41
|
|
|
self::setOpenOffice(); |
42
|
|
|
$sheet = $this->getSheet(); |
43
|
|
|
$sheet->getCell('A1')->setValue('=CEILING(5.1)'); |
44
|
|
|
$result = $sheet->getCell('A1')->getCalculatedValue(); |
45
|
|
|
self::assertEqualsWithDelta(6, $result, 1E-12); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testCEILINGExcel1Arg(): void |
49
|
|
|
{ |
50
|
|
|
$this->mightHaveException('exception'); |
51
|
|
|
$sheet = $this->getSheet(); |
52
|
|
|
$sheet->getCell('A1')->setValue('=CEILING(5.1)'); |
53
|
|
|
$result = $sheet->getCell('A1')->getCalculatedValue(); |
54
|
|
|
self::assertEqualsWithDelta(6, $result, 1E-12); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerCeilingArray')] |
58
|
|
|
public function testCeilingArray(array $expectedResult, string $argument1, string $argument2): void |
59
|
|
|
{ |
60
|
|
|
$calculation = Calculation::getInstance(); |
61
|
|
|
|
62
|
|
|
$formula = "=CEILING({$argument1}, {$argument2})"; |
63
|
|
|
$result = $calculation->_calculateFormulaValue($formula); |
64
|
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public static function providerCeilingArray(): array |
68
|
|
|
{ |
69
|
|
|
return [ |
70
|
|
|
'matrix' => [[[3.15, 3.142], [3.1416, 3.141594]], '3.1415926536', '{0.01, 0.002; 0.00005, 0.000002}'], |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|