-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
DCountATest.php
108 lines (101 loc) · 3.12 KB
/
DCountATest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
use PhpOffice\PhpSpreadsheet\Calculation\Database;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class DCountATest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerDCountA
*
* @param mixed $expectedResult
* @param mixed $database
* @param mixed $field
* @param mixed $criteria
*/
public function testDCountA($expectedResult, $database, $field, $criteria): void
{
$result = Database::DCOUNTA($database, $field, $criteria);
self::assertSame($expectedResult, $result);
}
protected function database1()
{
return [
['Tree', 'Height', 'Age', 'Yield', 'Profit'],
['Apple', 18, 20, 14, 105],
['Pear', 12, 12, 10, 96],
['Cherry', 13, 14, 9, 105],
['Apple', 14, 15, 10, 75],
['Pear', 9, 8, 8, 76.8],
['Apple', 8, 9, 6, 45],
];
}
protected function database2()
{
return [
['Name', 'Gender', 'Age', 'Subject', 'Score'],
['Amy', 'Female', 8, 'Math', 0.63],
['Amy', 'Female', 8, 'English', 0.78],
['Amy', 'Female', 8, 'Science', 0.39],
['Bill', 'Male', 8, 'Math', 0.55],
['Bill', 'Male', 8, 'English', 0.71],
['Bill', 'Male', 8, 'Science', 'awaiting'],
['Sue', 'Female', 9, 'Math', null],
['Sue', 'Female', 9, 'English', 0.52],
['Sue', 'Female', 9, 'Science', 0.48],
['Tom', 'Male', 9, 'Math', 0.78],
['Tom', 'Male', 9, 'English', 0.69],
['Tom', 'Male', 9, 'Science', 0.65],
];
}
public function providerDCountA()
{
return [
[
1,
$this->database1(),
'Profit',
[
['Tree', 'Height', 'Height'],
['=Apple', '>10', '<16'],
],
],
[
2,
$this->database2(),
'Score',
[
['Subject', 'Gender'],
['Science', 'Male'],
],
],
/*
* Null value in datacolumn behaviour for DCOUNTA... will include not include a null value in the count
* if it is an actual cell value; but it will be included if it is a literal... this test case is
* currently passing literals
[
1,
$this->database2(),
'Score',
[
['Subject', 'Gender'],
['Math', 'Female'],
],
],
*/
[
3,
$this->database2(),
'Score',
[
['Subject', 'Score'],
['English', '>60%'],
],
],
];
}
}