Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/views/reports/core/tests/querytable-test.cpp
Show All 18 Lines | |||||
19 | #include "querytable-test.h" | 19 | #include "querytable-test.h" | ||
20 | 20 | | |||
21 | #include <QFile> | 21 | #include <QFile> | ||
22 | #include <QTest> | 22 | #include <QTest> | ||
23 | 23 | | |||
24 | #include <KLocalizedString> | 24 | #include <KLocalizedString> | ||
25 | 25 | | |||
26 | #include "tests/testutilities.h" | 26 | #include "tests/testutilities.h" | ||
27 | #include "cashflowlist.h" | ||||
27 | #include "querytable.h" | 28 | #include "querytable.h" | ||
28 | #include "mymoneyinstitution.h" | 29 | #include "mymoneyinstitution.h" | ||
29 | #include "mymoneyaccount.h" | 30 | #include "mymoneyaccount.h" | ||
30 | #include "mymoneysecurity.h" | 31 | #include "mymoneysecurity.h" | ||
31 | #include "mymoneyprice.h" | 32 | #include "mymoneyprice.h" | ||
32 | #include "mymoneystoragedump.h" | 33 | #include "mymoneystoragedump.h" | ||
33 | #include "mymoneyreport.h" | 34 | #include "mymoneyreport.h" | ||
34 | #include "mymoneysplit.h" | 35 | #include "mymoneysplit.h" | ||
▲ Show 20 Lines • Show All 287 Lines • ▼ Show 20 Line(s) | 223 | #endif | |||
322 | QVERIFY(high > low); | 323 | QVERIFY(high > low); | ||
323 | QVERIFY(high <= high); | 324 | QVERIFY(high <= high); | ||
324 | QVERIFY(high == high); | 325 | QVERIFY(high == high); | ||
325 | } | 326 | } | ||
326 | 327 | | |||
327 | void QueryTableTest::testCashFlowAnalysis() | 328 | void QueryTableTest::testCashFlowAnalysis() | ||
328 | { | 329 | { | ||
329 | // | 330 | // | ||
330 | // Test IRR calculations | 331 | // Test XIRR calculations | ||
331 | // | 332 | // | ||
332 | 333 | | |||
333 | CashFlowList list; | 334 | CashFlowList list; | ||
334 | 335 | | |||
335 | list += CashFlowListItem(QDate(2004, 5, 3), MyMoneyMoney(1000.0)); | 336 | list += CashFlowListItem(QDate(2004, 5, 3), MyMoneyMoney(1000.0)); | ||
336 | list += CashFlowListItem(QDate(2004, 5, 20), MyMoneyMoney(59.0)); | 337 | list += CashFlowListItem(QDate(2004, 5, 20), MyMoneyMoney(59.0)); | ||
337 | list += CashFlowListItem(QDate(2004, 6, 3), MyMoneyMoney(14.0)); | 338 | list += CashFlowListItem(QDate(2004, 6, 3), MyMoneyMoney(14.0)); | ||
338 | list += CashFlowListItem(QDate(2004, 6, 24), MyMoneyMoney(92.0)); | 339 | list += CashFlowListItem(QDate(2004, 6, 24), MyMoneyMoney(92.0)); | ||
339 | list += CashFlowListItem(QDate(2004, 7, 6), MyMoneyMoney(63.0)); | 340 | list += CashFlowListItem(QDate(2004, 7, 6), MyMoneyMoney(63.0)); | ||
340 | list += CashFlowListItem(QDate(2004, 7, 25), MyMoneyMoney(15.0)); | 341 | list += CashFlowListItem(QDate(2004, 7, 25), MyMoneyMoney(15.0)); | ||
341 | list += CashFlowListItem(QDate(2004, 8, 5), MyMoneyMoney(92.0)); | 342 | list += CashFlowListItem(QDate(2004, 8, 5), MyMoneyMoney(92.0)); | ||
342 | list += CashFlowListItem(QDate(2004, 9, 2), MyMoneyMoney(18.0)); | 343 | list += CashFlowListItem(QDate(2004, 9, 2), MyMoneyMoney(18.0)); | ||
343 | list += CashFlowListItem(QDate(2004, 9, 21), MyMoneyMoney(5.0)); | 344 | list += CashFlowListItem(QDate(2004, 9, 21), MyMoneyMoney(5.0)); | ||
344 | list += CashFlowListItem(QDate(2004, 10, 16), MyMoneyMoney(-2037.0)); | 345 | list += CashFlowListItem(QDate(2004, 10, 16), MyMoneyMoney(-2037.0)); | ||
345 | 346 | | |||
346 | MyMoneyMoney IRR(list.IRR(), 1000); | 347 | MyMoneyMoney XIRR(list.XIRR(), 1000); | ||
347 | 348 | QVERIFY(XIRR == MyMoneyMoney(1676, 1000)); | |||
348 | QVERIFY(IRR == MyMoneyMoney(1676, 1000)); | | |||
349 | 349 | | |||
350 | list.pop_back(); | 350 | list.pop_back(); | ||
351 | list += CashFlowListItem(QDate(2004, 10, 16), MyMoneyMoney(-1358.0)); | 351 | list += CashFlowListItem(QDate(2004, 10, 16), MyMoneyMoney(-1358.0)); | ||
352 | 352 | | |||
353 | IRR = MyMoneyMoney(list.IRR(), 1000); | 353 | XIRR = MyMoneyMoney(list.XIRR(), 1000); | ||
354 | QVERIFY(XIRR.isZero()); | ||||
355 | | ||||
356 | // two entries | ||||
357 | list.clear(); | ||||
358 | list += CashFlowListItem(QDate(2005, 9, 22), MyMoneyMoney(-3472.57)); | ||||
359 | list += CashFlowListItem(QDate(2009, 3, 18), MyMoneyMoney(6051.36)); | ||||
360 | | ||||
361 | XIRR = MyMoneyMoney(list.XIRR(), 1000); | ||||
362 | QCOMPARE(XIRR.toDouble(), MyMoneyMoney(173, 1000).toDouble()); | ||||
363 | | ||||
364 | // check ignoring zero values | ||||
365 | list += CashFlowListItem(QDate(1998, 11, 1), MyMoneyMoney(0.0)); | ||||
366 | list += CashFlowListItem(QDate(2017, 8, 11), MyMoneyMoney(0.0)); | ||||
367 | | ||||
368 | XIRR = MyMoneyMoney(list.XIRR(), 1000); | ||||
369 | QCOMPARE(XIRR.toDouble(), MyMoneyMoney(173, 1000).toDouble()); | ||||
370 | | ||||
371 | list.pop_back(); | ||||
372 | // former implementation crashed | ||||
373 | list += CashFlowListItem(QDate(2014, 8, 11), MyMoneyMoney(0.0)); | ||||
374 | | ||||
375 | XIRR = MyMoneyMoney(list.XIRR(), 1000); | ||||
376 | QCOMPARE(XIRR.toDouble(), MyMoneyMoney(173, 1000).toDouble()); | ||||
377 | | ||||
378 | // different ordering | ||||
379 | list.clear(); | ||||
380 | list += CashFlowListItem(QDate(2004, 3, 18), MyMoneyMoney(6051.36)); | ||||
381 | list += CashFlowListItem(QDate(2005, 9, 22), MyMoneyMoney(-3472.57)); | ||||
354 | 382 | | |||
355 | QVERIFY(IRR.isZero()); | 383 | XIRR = MyMoneyMoney(list.XIRR(), 1000); | ||
384 | QCOMPARE(XIRR.toDouble(), MyMoneyMoney(-307, 1000).toDouble()); | ||||
385 | | ||||
386 | | ||||
387 | // not enough entries | ||||
388 | list.pop_back(); | ||||
389 | | ||||
390 | bool result = false; | ||||
391 | try { | ||||
392 | XIRR = MyMoneyMoney(list.XIRR(), 1000); | ||||
393 | } catch (MyMoneyException &e) { | ||||
394 | result = true; | ||||
395 | } | ||||
396 | QVERIFY(result); | ||||
356 | } | 397 | } | ||
357 | 398 | | |||
358 | void QueryTableTest::testAccountQuery() | 399 | void QueryTableTest::testAccountQuery() | ||
359 | { | 400 | { | ||
360 | try { | 401 | try { | ||
361 | QString htmlcontext = QString("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"html/kmymoney.css\"></head><body>\n%1\n</body></html>\n"); | 402 | QString htmlcontext = QString("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"html/kmymoney.css\"></head><body>\n%1\n</body></html>\n"); | ||
362 | 403 | | |||
363 | // | 404 | // | ||
▲ Show 20 Lines • Show All 573 Lines • Show Last 20 Lines |