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