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

DStDevPTest::testDirectCallToDStDevP()   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\DStDevP;
6
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
7
8
class DStDevPTest extends AllSetupTeardown
9
{
10
    /**
11
     * @dataProvider providerDStDevP
12
     *
13
     * @param mixed $expectedResult
14
     * @param mixed $database
15
     * @param mixed $field
16
     * @param mixed $criteria
17
     */
18
    public function testDirectCallToDStDevP($expectedResult, $database, $field, $criteria): void
19
    {
20
        $result = DStDevP::evaluate($database, $field, $criteria);
21
        self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
22
    }
23
24
    /**
25
     * @dataProvider providerDStDevP
26
     *
27
     * @param mixed $expectedResult
28
     * @param mixed $database
29
     * @param mixed $field
30
     * @param mixed $criteria
31
     */
32
    public function testDStDevPAsWorksheetFormula($expectedResult, $database, $field, $criteria): void
33
    {
34
        $this->prepareWorksheetWithFormula('DSTDEVP', $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 providerDStDevP(): array
41
    {
42
        return [
43
            [
44
                2.653299832284,
45
                $this->database1(),
46
                'Yield',
47
                [
48
                    ['Tree'],
49
                    ['=Apple'],
50
                    ['=Pear'],
51
                ],
52
            ],
53
            [
54
                0.085244745684,
55
                $this->database3FilledIn(),
56
                'Score',
57
                [
58
                    ['Subject', 'Gender'],
59
                    ['English', 'Male'],
60
                ],
61
            ],
62
            [
63
                0.160623784042,
64
                $this->database3FilledIn(),
65
                'Score',
66
                [
67
                    ['Subject', 'Age'],
68
                    ['Math', '>8'],
69
                ],
70
            ],
71
            [
72
                0.01,
73
                $this->database3(),
74
                'Score',
75
                [
76
                    ['Subject', 'Gender'],
77
                    ['English', 'Male'],
78
                ],
79
            ],
80
            [
81
                0,
82
                $this->database3(),
83
                'Score',
84
                [
85
                    ['Subject', 'Age'],
86
                    ['Math', '>8'],
87
                ],
88
            ],
89
            'omitted field name' => [
90
                ExcelError::VALUE(),
91
                $this->database1(),
92
                null,
93
                $this->database1(),
94
            ],
95
        ];
96
    }
97
}
98