Completed
Push — master ( 7b4ba9...836792 )
by Mark
37s queued 33s
created

DStDevTest::providerDStDev()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 36
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Database\DStDev;
6
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
7
8
class DStDevTest extends AllSetupTeardown
9
{
10
    /**
11
     * @dataProvider providerDStDev
12
     *
13
     * @param mixed $expectedResult
14
     * @param mixed $database
15
     * @param mixed $field
16
     * @param mixed $criteria
17
     */
18
    public function testDirectCallToDStDev($expectedResult, $database, $field, $criteria): void
19
    {
20
        $result = DStDev::evaluate($database, $field, $criteria);
21
        self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
22
    }
23
24
    /**
25
     * @dataProvider providerDStDev
26
     *
27
     * @param mixed $expectedResult
28
     * @param mixed $database
29
     * @param mixed $field
30
     * @param mixed $criteria
31
     */
32
    public function testDStDevAsWorksheetFormula($expectedResult, $database, $field, $criteria): void
33
    {
34
        $this->prepareWorksheetWithFormula('DSTDEV', $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 providerDStDev(): array
41
    {
42
        return [
43
            [
44
                2.966479394838,
45
                $this->database1(),
46
                'Yield',
47
                [
48
                    ['Tree'],
49
                    ['=Apple'],
50
                    ['=Pear'],
51
                ],
52
            ],
53
            [
54
                0.104403065089,
55
                $this->database3FilledIn(),
56
                'Score',
57
                [
58
                    ['Subject', 'Gender'],
59
                    ['English', 'Male'],
60
                ],
61
            ],
62
            [
63
                0.196723155729,
64
                $this->database3FilledIn(),
65
                'Score',
66
                [
67
                    ['Subject', 'Age'],
68
                    ['Math', '>8'],
69
                ],
70
            ],
71
            'omitted field name' => [
72
                ExcelError::VALUE(),
73
                $this->database1(),
74
                null,
75
                $this->database1(),
76
            ],
77
        ];
78
    }
79
}
80