Passed
Push — master ( 2d1f4e...e6aacf )
by
unknown
26:57 queued 19:21
created

FloorTest::testFLOORGnumericClashingSigns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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