Passed
Pull Request — master (#4468)
by Owen
10:02
created

FloorTest::testFLOOROpenOffice1Arg()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
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 FloorTest extends AllSetupTeardown
10
{
11
    #[\PHPUnit\Framework\Attributes\DataProvider('providerFLOOR')]
12
    public function testFLOOR(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("=FLOOR($formula)");
21
        $result = $sheet->getCell('A1')->getCalculatedValue();
22
        self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
23
    }
24
25
    public static function providerFLOOR(): array
26
    {
27
        return require 'tests/data/Calculation/MathTrig/FLOOR.php';
28
    }
29
30
    public function testFLOORGnumeric1Arg(): void
31
    {
32
        self::setGnumeric();
33
        $sheet = $this->getSheet();
34
        $sheet->getCell('A1')->setValue('=FLOOR(5.1)');
35
        $result = $sheet->getCell('A1')->getCalculatedValue();
36
        self::assertEqualsWithDelta(5, $result, 1E-12);
37
    }
38
39
    public function testFLOOROpenOffice1Arg(): void
40
    {
41
        self::setOpenOffice();
42
        $sheet = $this->getSheet();
43
        $sheet->getCell('A1')->setValue('=FLOOR(5.1)');
44
        $result = $sheet->getCell('A1')->getCalculatedValue();
45
        self::assertEqualsWithDelta(5, $result, 1E-12);
46
    }
47
48
    public function testFLOORExcel1Arg(): void
49
    {
50
        $this->mightHaveException('exception');
51
        $sheet = $this->getSheet();
52
        $sheet->getCell('A1')->setValue('=FLOOR(5.1)');
53
        $result = $sheet->getCell('A1')->getCalculatedValue();
54
        self::assertEqualsWithDelta(5, $result, 1E-12);
55
    }
56
57
    #[\PHPUnit\Framework\Attributes\DataProvider('providerFloorArray')]
58
    public function testFloorArray(array $expectedResult, string $argument1, string $argument2): void
59
    {
60
        $calculation = Calculation::getInstance();
61
62
        $formula = "=FLOOR({$argument1}, {$argument2})";
63
        $result = $calculation->_calculateFormulaValue($formula);
64
        self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
65
    }
66
67
    public static function providerFloorArray(): array
68
    {
69
        return [
70
            'matrix' => [[[3.14, 3.14], [3.14155, 3.141592]], '3.1415926536', '{0.01, 0.002; 0.00005, 0.000002}'],
71
        ];
72
    }
73
}
74