1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Financial; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class FinancialTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function setUp() |
12
|
|
|
{ |
13
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @dataProvider providerACCRINT |
18
|
|
|
* |
19
|
|
|
* @param mixed $expectedResult |
20
|
|
|
*/ |
21
|
|
|
public function testACCRINT($expectedResult, ...$args) |
22
|
|
|
{ |
23
|
|
|
$result = Financial::ACCRINT(...$args); |
|
|
|
|
24
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function providerACCRINT() |
28
|
|
|
{ |
29
|
|
|
return require 'data/Calculation/Financial/ACCRINT.php'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @dataProvider providerACCRINTM |
34
|
|
|
* |
35
|
|
|
* @param mixed $expectedResult |
36
|
|
|
*/ |
37
|
|
|
public function testACCRINTM($expectedResult, ...$args) |
38
|
|
|
{ |
39
|
|
|
$result = Financial::ACCRINTM(...$args); |
|
|
|
|
40
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function providerACCRINTM() |
44
|
|
|
{ |
45
|
|
|
return require 'data/Calculation/Financial/ACCRINTM.php'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @dataProvider providerAMORDEGRC |
50
|
|
|
* |
51
|
|
|
* @param mixed $expectedResult |
52
|
|
|
*/ |
53
|
|
|
public function testAMORDEGRC($expectedResult, ...$args) |
54
|
|
|
{ |
55
|
|
|
$result = Financial::AMORDEGRC(...$args); |
|
|
|
|
56
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function providerAMORDEGRC() |
60
|
|
|
{ |
61
|
|
|
return require 'data/Calculation/Financial/AMORDEGRC.php'; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @dataProvider providerAMORLINC |
66
|
|
|
* |
67
|
|
|
* @param mixed $expectedResult |
68
|
|
|
*/ |
69
|
|
|
public function testAMORLINC($expectedResult, ...$args) |
70
|
|
|
{ |
71
|
|
|
$result = Financial::AMORLINC(...$args); |
|
|
|
|
72
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function providerAMORLINC() |
76
|
|
|
{ |
77
|
|
|
return require 'data/Calculation/Financial/AMORLINC.php'; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @dataProvider providerCOUPDAYBS |
82
|
|
|
* |
83
|
|
|
* @param mixed $expectedResult |
84
|
|
|
*/ |
85
|
|
|
public function testCOUPDAYBS($expectedResult, ...$args) |
86
|
|
|
{ |
87
|
|
|
$result = Financial::COUPDAYBS(...$args); |
|
|
|
|
88
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function providerCOUPDAYBS() |
92
|
|
|
{ |
93
|
|
|
return require 'data/Calculation/Financial/COUPDAYBS.php'; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @dataProvider providerCOUPDAYS |
98
|
|
|
* |
99
|
|
|
* @param mixed $expectedResult |
100
|
|
|
*/ |
101
|
|
|
public function testCOUPDAYS($expectedResult, ...$args) |
102
|
|
|
{ |
103
|
|
|
$result = Financial::COUPDAYS(...$args); |
|
|
|
|
104
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function providerCOUPDAYS() |
108
|
|
|
{ |
109
|
|
|
return require 'data/Calculation/Financial/COUPDAYS.php'; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @dataProvider providerCOUPDAYSNC |
114
|
|
|
* |
115
|
|
|
* @param mixed $expectedResult |
116
|
|
|
*/ |
117
|
|
|
public function testCOUPDAYSNC($expectedResult, ...$args) |
118
|
|
|
{ |
119
|
|
|
$result = Financial::COUPDAYSNC(...$args); |
|
|
|
|
120
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function providerCOUPDAYSNC() |
124
|
|
|
{ |
125
|
|
|
return require 'data/Calculation/Financial/COUPDAYSNC.php'; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @dataProvider providerCOUPNCD |
130
|
|
|
* |
131
|
|
|
* @param mixed $expectedResult |
132
|
|
|
*/ |
133
|
|
|
public function testCOUPNCD($expectedResult, ...$args) |
134
|
|
|
{ |
135
|
|
|
$result = Financial::COUPNCD(...$args); |
|
|
|
|
136
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function providerCOUPNCD() |
140
|
|
|
{ |
141
|
|
|
return require 'data/Calculation/Financial/COUPNCD.php'; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @dataProvider providerCOUPNUM |
146
|
|
|
* |
147
|
|
|
* @param mixed $expectedResult |
148
|
|
|
*/ |
149
|
|
|
public function testCOUPNUM($expectedResult, ...$args) |
150
|
|
|
{ |
151
|
|
|
$result = Financial::COUPNUM(...$args); |
|
|
|
|
152
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function providerCOUPNUM() |
156
|
|
|
{ |
157
|
|
|
return require 'data/Calculation/Financial/COUPNUM.php'; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @dataProvider providerCOUPPCD |
162
|
|
|
* |
163
|
|
|
* @param mixed $expectedResult |
164
|
|
|
*/ |
165
|
|
|
public function testCOUPPCD($expectedResult, ...$args) |
166
|
|
|
{ |
167
|
|
|
$result = Financial::COUPPCD(...$args); |
|
|
|
|
168
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function providerCOUPPCD() |
172
|
|
|
{ |
173
|
|
|
return require 'data/Calculation/Financial/COUPPCD.php'; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @dataProvider providerCUMIPMT |
178
|
|
|
* |
179
|
|
|
* @param mixed $expectedResult |
180
|
|
|
*/ |
181
|
|
|
public function testCUMIPMT($expectedResult, ...$args) |
182
|
|
|
{ |
183
|
|
|
$result = Financial::CUMIPMT(...$args); |
|
|
|
|
184
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
public function providerCUMIPMT() |
188
|
|
|
{ |
189
|
|
|
return require 'data/Calculation/Financial/CUMIPMT.php'; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @dataProvider providerCUMPRINC |
194
|
|
|
* |
195
|
|
|
* @param mixed $expectedResult |
196
|
|
|
*/ |
197
|
|
|
public function testCUMPRINC($expectedResult, ...$args) |
198
|
|
|
{ |
199
|
|
|
$result = Financial::CUMPRINC(...$args); |
|
|
|
|
200
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function providerCUMPRINC() |
204
|
|
|
{ |
205
|
|
|
return require 'data/Calculation/Financial/CUMPRINC.php'; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @dataProvider providerDB |
210
|
|
|
* |
211
|
|
|
* @param mixed $expectedResult |
212
|
|
|
*/ |
213
|
|
|
public function testDB($expectedResult, ...$args) |
214
|
|
|
{ |
215
|
|
|
$result = Financial::DB(...$args); |
|
|
|
|
216
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function providerDB() |
220
|
|
|
{ |
221
|
|
|
return require 'data/Calculation/Financial/DB.php'; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @dataProvider providerDDB |
226
|
|
|
* |
227
|
|
|
* @param mixed $expectedResult |
228
|
|
|
*/ |
229
|
|
|
public function testDDB($expectedResult, ...$args) |
230
|
|
|
{ |
231
|
|
|
$result = Financial::DDB(...$args); |
|
|
|
|
232
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
public function providerDDB() |
236
|
|
|
{ |
237
|
|
|
return require 'data/Calculation/Financial/DDB.php'; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @dataProvider providerDISC |
242
|
|
|
* |
243
|
|
|
* @param mixed $expectedResult |
244
|
|
|
*/ |
245
|
|
|
public function testDISC($expectedResult, ...$args) |
246
|
|
|
{ |
247
|
|
|
$result = Financial::DISC(...$args); |
|
|
|
|
248
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
public function providerDISC() |
252
|
|
|
{ |
253
|
|
|
return require 'data/Calculation/Financial/DISC.php'; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @dataProvider providerDOLLARDE |
258
|
|
|
* |
259
|
|
|
* @param mixed $expectedResult |
260
|
|
|
*/ |
261
|
|
|
public function testDOLLARDE($expectedResult, ...$args) |
262
|
|
|
{ |
263
|
|
|
$result = Financial::DOLLARDE(...$args); |
|
|
|
|
264
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
public function providerDOLLARDE() |
268
|
|
|
{ |
269
|
|
|
return require 'data/Calculation/Financial/DOLLARDE.php'; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @dataProvider providerDOLLARFR |
274
|
|
|
* |
275
|
|
|
* @param mixed $expectedResult |
276
|
|
|
*/ |
277
|
|
|
public function testDOLLARFR($expectedResult, ...$args) |
278
|
|
|
{ |
279
|
|
|
$result = Financial::DOLLARFR(...$args); |
|
|
|
|
280
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
public function providerDOLLARFR() |
284
|
|
|
{ |
285
|
|
|
return require 'data/Calculation/Financial/DOLLARFR.php'; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @dataProvider providerEFFECT |
290
|
|
|
* |
291
|
|
|
* @param mixed $expectedResult |
292
|
|
|
*/ |
293
|
|
|
public function testEFFECT($expectedResult, ...$args) |
294
|
|
|
{ |
295
|
|
|
$result = Financial::EFFECT(...$args); |
|
|
|
|
296
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
public function providerEFFECT() |
300
|
|
|
{ |
301
|
|
|
return require 'data/Calculation/Financial/EFFECT.php'; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* @dataProvider providerFV |
306
|
|
|
* |
307
|
|
|
* @param mixed $expectedResult |
308
|
|
|
*/ |
309
|
|
|
public function testFV($expectedResult, ...$args) |
310
|
|
|
{ |
311
|
|
|
$result = Financial::FV(...$args); |
|
|
|
|
312
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
public function providerFV() |
316
|
|
|
{ |
317
|
|
|
return require 'data/Calculation/Financial/FV.php'; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* @dataProvider providerFVSCHEDULE |
322
|
|
|
* |
323
|
|
|
* @param mixed $expectedResult |
324
|
|
|
*/ |
325
|
|
|
public function testFVSCHEDULE($expectedResult, ...$args) |
326
|
|
|
{ |
327
|
|
|
$result = Financial::FVSCHEDULE(...$args); |
|
|
|
|
328
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
public function providerFVSCHEDULE() |
332
|
|
|
{ |
333
|
|
|
return require 'data/Calculation/Financial/FVSCHEDULE.php'; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @dataProvider providerINTRATE |
338
|
|
|
* |
339
|
|
|
* @param mixed $expectedResult |
340
|
|
|
*/ |
341
|
|
|
public function testINTRATE($expectedResult, ...$args) |
342
|
|
|
{ |
343
|
|
|
$result = Financial::INTRATE(...$args); |
|
|
|
|
344
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
public function providerINTRATE() |
348
|
|
|
{ |
349
|
|
|
return require 'data/Calculation/Financial/INTRATE.php'; |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
/** |
353
|
|
|
* @dataProvider providerIPMT |
354
|
|
|
* |
355
|
|
|
* @param mixed $expectedResult |
356
|
|
|
*/ |
357
|
|
|
public function testIPMT($expectedResult, ...$args) |
358
|
|
|
{ |
359
|
|
|
$result = Financial::IPMT(...$args); |
|
|
|
|
360
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
public function providerIPMT() |
364
|
|
|
{ |
365
|
|
|
return require 'data/Calculation/Financial/IPMT.php'; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* @dataProvider providerIRR |
370
|
|
|
* |
371
|
|
|
* @param mixed $expectedResult |
372
|
|
|
*/ |
373
|
|
|
public function testIRR($expectedResult, ...$args) |
374
|
|
|
{ |
375
|
|
|
$result = Financial::IRR(...$args); |
|
|
|
|
376
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
public function providerIRR() |
380
|
|
|
{ |
381
|
|
|
return require 'data/Calculation/Financial/IRR.php'; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @dataProvider providerISPMT |
386
|
|
|
* |
387
|
|
|
* @param mixed $expectedResult |
388
|
|
|
*/ |
389
|
|
|
public function testISPMT($expectedResult, ...$args) |
390
|
|
|
{ |
391
|
|
|
$result = Financial::ISPMT(...$args); |
392
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
public function providerISPMT() |
396
|
|
|
{ |
397
|
|
|
return require 'data/Calculation/Financial/ISPMT.php'; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* @dataProvider providerMIRR |
402
|
|
|
* |
403
|
|
|
* @param mixed $expectedResult |
404
|
|
|
*/ |
405
|
|
|
public function testMIRR($expectedResult, ...$args) |
406
|
|
|
{ |
407
|
|
|
$result = Financial::MIRR(...$args); |
|
|
|
|
408
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
public function providerMIRR() |
412
|
|
|
{ |
413
|
|
|
return require 'data/Calculation/Financial/MIRR.php'; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* @dataProvider providerNOMINAL |
418
|
|
|
* |
419
|
|
|
* @param mixed $expectedResult |
420
|
|
|
*/ |
421
|
|
|
public function testNOMINAL($expectedResult, ...$args) |
422
|
|
|
{ |
423
|
|
|
$result = Financial::NOMINAL(...$args); |
|
|
|
|
424
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
public function providerNOMINAL() |
428
|
|
|
{ |
429
|
|
|
return require 'data/Calculation/Financial/NOMINAL.php'; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* @dataProvider providerNPER |
434
|
|
|
* |
435
|
|
|
* @param mixed $expectedResult |
436
|
|
|
*/ |
437
|
|
|
public function testNPER($expectedResult, ...$args) |
438
|
|
|
{ |
439
|
|
|
$result = Financial::NPER(...$args); |
|
|
|
|
440
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
public function providerNPER() |
444
|
|
|
{ |
445
|
|
|
return require 'data/Calculation/Financial/NPER.php'; |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* @dataProvider providerNPV |
450
|
|
|
* |
451
|
|
|
* @param mixed $expectedResult |
452
|
|
|
*/ |
453
|
|
|
public function testNPV($expectedResult, ...$args) |
454
|
|
|
{ |
455
|
|
|
$result = Financial::NPV(...$args); |
456
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
public function providerNPV() |
460
|
|
|
{ |
461
|
|
|
return require 'data/Calculation/Financial/NPV.php'; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* @dataProvider providerPRICE |
466
|
|
|
* |
467
|
|
|
* @param mixed $expectedResult |
468
|
|
|
*/ |
469
|
|
|
public function testPRICE($expectedResult, ...$args) |
470
|
|
|
{ |
471
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed'); |
472
|
|
|
|
473
|
|
|
$result = Financial::PRICE(...$args); |
474
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
public function providerPRICE() |
478
|
|
|
{ |
479
|
|
|
return require 'data/Calculation/Financial/PRICE.php'; |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* @dataProvider providerRATE |
484
|
|
|
* |
485
|
|
|
* @param mixed $expectedResult |
486
|
|
|
*/ |
487
|
|
|
public function testRATE($expectedResult, ...$args) |
488
|
|
|
{ |
489
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed'); |
490
|
|
|
|
491
|
|
|
$result = Financial::RATE(...$args); |
492
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
public function providerRATE() |
496
|
|
|
{ |
497
|
|
|
return require 'data/Calculation/Financial/RATE.php'; |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* @dataProvider providerXIRR |
502
|
|
|
* |
503
|
|
|
* @param mixed $expectedResult |
504
|
|
|
*/ |
505
|
|
|
public function testXIRR($expectedResult, ...$args) |
506
|
|
|
{ |
507
|
|
|
$this->markTestIncomplete('TODO: This test should be fixed'); |
508
|
|
|
|
509
|
|
|
$result = Financial::XIRR(...$args); |
510
|
|
|
self::assertEquals($expectedResult, $result, null, 1E-8); |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
public function providerXIRR() |
514
|
|
|
{ |
515
|
|
|
return require 'data/Calculation/Financial/XIRR.php'; |
516
|
|
|
} |
517
|
|
|
} |
518
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.