-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
DSumTest.php
114 lines (107 loc) · 3.05 KB
/
DSumTest.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
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
use PhpOffice\PhpSpreadsheet\Calculation\Database;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class DSumTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerDSum
*
* @param mixed $expectedResult
* @param mixed $database
* @param mixed $field
* @param mixed $criteria
*/
public function testDSum($expectedResult, $database, $field, $criteria): void
{
$result = Database::DSUM($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, 77],
['Apple', 8, 9, 6, 45],
];
}
protected function database2()
{
return [
['Quarter', 'Area', 'Sales Rep.', 'Sales'],
[1, 'North', 'Jeff', 223000],
[1, 'North', 'Chris', 125000],
[1, 'South', 'Carol', 456000],
[1, 'South', 'Tina', 289000],
[2, 'North', 'Jeff', 322000],
[2, 'North', 'Chris', 340000],
[2, 'South', 'Carol', 198000],
[2, 'South', 'Tina', 222000],
[3, 'North', 'Jeff', 310000],
[3, 'North', 'Chris', 250000],
[3, 'South', 'Carol', 460000],
[3, 'South', 'Tina', 395000],
[4, 'North', 'Jeff', 261000],
[4, 'North', 'Chris', 389000],
[4, 'South', 'Carol', 305000],
[4, 'South', 'Tina', 188000],
];
}
public function providerDSum()
{
return [
[
225,
$this->database1(),
'Profit',
[
['Tree'],
['=Apple'],
],
],
[
248,
$this->database1(),
'Profit',
[
['Tree', 'Height', 'Height'],
['=Apple', '>10', '<16'],
['=Pear', null, null],
],
],
[
1210000,
$this->database2(),
'Sales',
[
['Quarter', 'Area'],
['>2', 'North'],
],
],
[
710000,
$this->database2(),
'Sales',
[
['Quarter', 'Sales Rep.'],
['3', 'C*'],
],
],
[
null,
$this->database1(),
null,
$this->database1(),
],
];
}
}