Passed
Pull Request — master (#3234)
by Mark
13:39
created

DMaxTest::testDirectCallToDMax()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 4
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Database\DMax;
6
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
7
8
class DMaxTest extends AllSetupTeardown
9
{
10
    /**
11
     * @dataProvider providerDMax
12
     *
13
     * @param mixed $expectedResult
14
     * @param mixed $database
15
     * @param mixed $field
16
     * @param mixed $criteria
17
     */
18
    public function testDirectCallToDMax($expectedResult, $database, $field, $criteria): void
19
    {
20
        $result = DMax::evaluate($database, $field, $criteria);
21
        self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
22
    }
23
24
    /**
25
     * @dataProvider providerDMax
26
     *
27
     * @param mixed $expectedResult
28
     * @param mixed $database
29
     * @param mixed $field
30
     * @param mixed $criteria
31
     */
32
    public function testDMaxAsWorksheetFormula($expectedResult, $database, $field, $criteria): void
33
    {
34
        $this->prepareWorksheetWithFormula('DMAX', $database, $field, $criteria);
35
36
        $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue();
37
        self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
38
    }
39
40
    public function providerDMax(): array
41
    {
42
        return [
43
            [
44
                96,
45
                $this->database1(),
46
                'Profit',
47
                [
48
                    ['Tree', 'Height', 'Height'],
49
                    ['=Apple', '>10', '<16'],
50
                    ['=Pear', null, null],
51
                ],
52
            ],
53
            [
54
                340000,
55
                $this->database2(),
56
                'Sales',
57
                [
58
                    ['Quarter', 'Area'],
59
                    [2, 'North'],
60
                ],
61
            ],
62
            [
63
                460000,
64
                $this->database2(),
65
                'Sales',
66
                [
67
                    ['Sales Rep.', 'Quarter'],
68
                    ['Carol', '>1'],
69
                ],
70
            ],
71
            'omitted field name' => [
72
                ExcelError::VALUE(),
73
                $this->database1(),
74
                null,
75
                $this->database1(),
76
            ],
77
            'field column number okay' => [
78
                18,
79
                $this->database1(),
80
                2,
81
                $this->database1(),
82
            ],
83
            /* Excel seems to return #NAME? when column number
84
               is too high or too low. This makes so little sense
85
               to me that I'm not going to bother coding that up,
86
               content to return #VALUE! as an invalid name would */
87
            'field column number too high' => [
88
                ExcelError::VALUE(),
89
                $this->database1(),
90
                99,
91
                $this->database1(),
92
            ],
93
            'field column number too low' => [
94
                ExcelError::VALUE(),
95
                $this->database1(),
96
                0,
97
                $this->database1(),
98
            ],
99
        ];
100
    }
101
}
102