summaryrefslogtreecommitdiffstats
path: root/kmymoney2/mymoney/mymoneyfinancialcalculatortest.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-07-04 22:38:03 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-07-04 22:38:03 +0000
commitdadc34655c3ab961b0b0b94a10eaaba710f0b5e8 (patch)
tree99e72842fe687baea16376a147619b6048d7e441 /kmymoney2/mymoney/mymoneyfinancialcalculatortest.cpp
downloadkmymoney-dadc34655c3ab961b0b0b94a10eaaba710f0b5e8.tar.gz
kmymoney-dadc34655c3ab961b0b0b94a10eaaba710f0b5e8.zip
Added kmymoney
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kmymoney@1239792 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmymoney2/mymoney/mymoneyfinancialcalculatortest.cpp')
-rw-r--r--kmymoney2/mymoney/mymoneyfinancialcalculatortest.cpp189
1 files changed, 189 insertions, 0 deletions
diff --git a/kmymoney2/mymoney/mymoneyfinancialcalculatortest.cpp b/kmymoney2/mymoney/mymoneyfinancialcalculatortest.cpp
new file mode 100644
index 0000000..fa5b1a3
--- /dev/null
+++ b/kmymoney2/mymoney/mymoneyfinancialcalculatortest.cpp
@@ -0,0 +1,189 @@
+/***************************************************************************
+ mymoneyfinancialcalculatortest.cpp
+ -------------------
+ copyright : (C) 2003 by Thomas Baumgart
+ email : ipwizard@users.sourceforge.net
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+#include <iostream>
+
+#include <math.h>
+#include "mymoneymoney.h"
+#include "mymoneyfinancialcalculatortest.h"
+
+MyMoneyFinancialCalculatorTest::MyMoneyFinancialCalculatorTest () {}
+
+
+void MyMoneyFinancialCalculatorTest::setUp () {
+ m = new MyMoneyFinancialCalculator;
+}
+
+void MyMoneyFinancialCalculatorTest::tearDown () {
+ delete m;
+}
+
+void MyMoneyFinancialCalculatorTest::testEmptyConstructor() {
+ CPPUNIT_ASSERT(m->m_ir == 0.0);
+ CPPUNIT_ASSERT(m->m_pv == 0.0);
+ CPPUNIT_ASSERT(m->m_pmt == 0.0);
+ CPPUNIT_ASSERT(m->m_fv == 0.0);
+ CPPUNIT_ASSERT(m->m_npp == 0);
+ CPPUNIT_ASSERT(m->m_CF == 12);
+ CPPUNIT_ASSERT(m->m_PF == 12);
+ CPPUNIT_ASSERT(m->m_prec == 2);
+ CPPUNIT_ASSERT(m->m_bep == false);
+ CPPUNIT_ASSERT(m->m_disc == true);
+ CPPUNIT_ASSERT(m->m_mask == 0);
+}
+
+void MyMoneyFinancialCalculatorTest::testSetPrec() {
+ m->setPrec(3);
+ CPPUNIT_ASSERT(m->m_prec == 3);
+}
+
+void MyMoneyFinancialCalculatorTest::testSetNpp() {
+ m->setNpp(20);
+ CPPUNIT_ASSERT(m->m_npp == 20);
+ CPPUNIT_ASSERT(m->m_mask == NPP_SET);
+}
+
+void MyMoneyFinancialCalculatorTest::testSetPF() {
+ m->setPF(1);
+ CPPUNIT_ASSERT(m->m_PF == 1);
+ m->setPF();
+ CPPUNIT_ASSERT(m->m_PF == 12);
+}
+
+void MyMoneyFinancialCalculatorTest::testSetCF() {
+ m->setCF(1);
+ CPPUNIT_ASSERT(m->m_CF == 1);
+ m->setCF();
+ CPPUNIT_ASSERT(m->m_CF == 12);
+}
+
+void MyMoneyFinancialCalculatorTest::testSetBep() {
+ m->setBep(true);
+ CPPUNIT_ASSERT(m->m_bep == true);
+ m->setBep();
+ CPPUNIT_ASSERT(m->m_bep == false);
+}
+
+void MyMoneyFinancialCalculatorTest::testSetDisc() {
+ m->setDisc(false);
+ CPPUNIT_ASSERT(m->m_disc == false);
+ m->setDisc();
+ CPPUNIT_ASSERT(m->m_disc == true);
+}
+
+void MyMoneyFinancialCalculatorTest::testSetIr() {
+ m->setIr(12.3);
+ CPPUNIT_ASSERT(m->m_ir == 12.3);
+ CPPUNIT_ASSERT(m->m_mask == IR_SET);
+}
+
+void MyMoneyFinancialCalculatorTest::testSetPv() {
+ m->setPv(23.4);
+ CPPUNIT_ASSERT(m->m_pv == 23.4);
+ CPPUNIT_ASSERT(m->m_mask == PV_SET);
+}
+
+void MyMoneyFinancialCalculatorTest::testSetPmt() {
+ m->setPmt(34.5);
+ CPPUNIT_ASSERT(m->m_pmt == 34.5);
+ CPPUNIT_ASSERT(m->m_mask == PMT_SET);
+}
+
+void MyMoneyFinancialCalculatorTest::testSetFv() {
+ m->setFv(45.6);
+ CPPUNIT_ASSERT(m->m_fv == 45.6);
+ CPPUNIT_ASSERT(m->m_mask == FV_SET);
+}
+
+void MyMoneyFinancialCalculatorTest::testCombinedSet() {
+ m->setNpp(20);
+ m->setIr(12.3);
+ m->setPv(23.4);
+ m->setPmt(34.5);
+ m->setFv(45.6);
+
+ CPPUNIT_ASSERT(m->m_mask == (NPP_SET | PV_SET | IR_SET | PMT_SET | FV_SET));
+}
+
+void MyMoneyFinancialCalculatorTest::testNumPayments() {
+ m->setPF(12);
+ m->setCF(12);
+ try {
+ m->numPayments();
+ CPPUNIT_FAIL("Missing expected exception");
+ } catch (MyMoneyException *e) {
+ delete e;
+ }
+
+ try {
+ m->setPv(-80000.0);
+ m->numPayments();
+ CPPUNIT_FAIL("Missing expected exception");
+ } catch (MyMoneyException *e) {
+ delete e;
+ }
+
+ try {
+ m->setIr(12.0);
+ m->numPayments();
+ CPPUNIT_FAIL("Missing expected exception");
+ } catch (MyMoneyException *e) {
+ delete e;
+ }
+
+ try {
+ m->setPmt(7108.0);
+ m->numPayments();
+ CPPUNIT_FAIL("Missing expected exception");
+ } catch (MyMoneyException *e) {
+ delete e;
+ }
+
+ try {
+ m->setFv(0.0);
+ m->numPayments();
+ } catch (MyMoneyException *e) {
+ CPPUNIT_FAIL("Unexpected exception");
+ delete e;
+ }
+
+ CPPUNIT_ASSERT(roundl(m->m_npp) == 12);
+}
+
+void MyMoneyFinancialCalculatorTest::testUseCase1() {
+ m->setPv(-300000.0);
+ m->setIr(5.0);
+ m->setNpp(360);
+ m->setFv(0.0);
+ m->setPF(12);
+ MyMoneyMoney res(m->payment());
+ CPPUNIT_ASSERT(res == MyMoneyMoney(161046,100));
+
+ res = MyMoneyMoney(m->futureValue());
+ CPPUNIT_ASSERT(res == MyMoneyMoney(405,100));
+}
+
+void MyMoneyFinancialCalculatorTest::testUseCase2() {
+ m->setPv(-320000.0);
+ m->setIr(5.0);
+ m->setNpp(360);
+ m->setFv(0.0);
+ m->setPF(12);
+ MyMoneyMoney res(m->payment());
+ CPPUNIT_ASSERT(res == MyMoneyMoney(171783,100));
+
+ res = MyMoneyMoney(m->futureValue());
+ CPPUNIT_ASSERT(res == MyMoneyMoney(-67,100));
+}