-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
DCountTest.php
136 lines (128 loc) · 3.51 KB
/
DCountTest.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
use PhpOffice\PhpSpreadsheet\Calculation\Database;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class DCountTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerDCount
*
* @param mixed $expectedResult
* @param mixed $database
* @param mixed $field
* @param mixed $criteria
*/
public function testDCount($expectedResult, $database, $field, $criteria): void
{
$result = Database::DCOUNT($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, 'N/A', 10, 75],
['Pear', 9, 8, 8, 77],
['Apple', 12, 11, 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],
];
}
protected function database3()
{
return [
['Status', 'Value'],
[false, 1],
[true, 2],
[true, 4],
[false, 8],
[true, 16],
[false, 32],
[false, 64],
[false, 128],
];
}
public function providerDCount()
{
return [
[
1,
$this->database1(),
'Age',
[
['Tree', 'Height', 'Height'],
['=Apple', '>10', '<16'],
],
],
[
1,
$this->database2(),
'Score',
[
['Subject', 'Gender'],
['Science', 'Male'],
],
],
[
1,
$this->database2(),
'Score',
[
['Subject', 'Gender'],
['Math', 'Female'],
],
],
[
3,
$this->database2(),
null,
[
['Subject', 'Score'],
['English', '>63%'],
],
],
[
3,
$this->database3(),
'Value',
[
['Status'],
[true],
],
],
[
5,
$this->database3(),
'Value',
[
['Status'],
['<>true'],
],
],
];
}
}