diff options
author | tripun <tripun@gmail.com> | 2014-07-28 20:01:23 +0530 |
---|---|---|
committer | tripun <tripun@gmail.com> | 2014-08-11 21:01:24 +0530 |
commit | 696440e73591bc2e59d07adad54494247b0f4421 (patch) | |
tree | 89199a500662927e048cb8678c721a5c1b269a2c /test/unit/t_balance.cc | |
parent | 6f39d1169d67de29927a7bfe16c389075a6a9a43 (diff) | |
download | fork-ledger-696440e73591bc2e59d07adad54494247b0f4421.tar.gz fork-ledger-696440e73591bc2e59d07adad54494247b0f4421.tar.bz2 fork-ledger-696440e73591bc2e59d07adad54494247b0f4421.zip |
added balance addition unit test
Diffstat (limited to 'test/unit/t_balance.cc')
-rw-r--r-- | test/unit/t_balance.cc | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index dfa96821..7dff7e1d 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -34,14 +34,14 @@ BOOST_AUTO_TEST_CASE(testConstructors) { balance_t b0; balance_t b1(1.00); - balance_t b2(12345UL); - balance_t b3(123456L); + balance_t b2(123456UL); + balance_t b3(12345L); BOOST_CHECK_EQUAL(balance_t(), b0); BOOST_CHECK_NE(balance_t("0"), b0); BOOST_CHECK_NE(balance_t("0.0"), b0); - BOOST_CHECK_EQUAL(balance_t(12345UL), 12345UL); - BOOST_CHECK_EQUAL(balance_t(123456L), 123456L); + BOOST_CHECK_EQUAL(b2, 123456UL); + BOOST_CHECK_EQUAL(b3, 12345L); BOOST_CHECK(b0.valid()); BOOST_CHECK(b1.valid()); @@ -50,4 +50,42 @@ BOOST_AUTO_TEST_CASE(testConstructors) } +BOOST_AUTO_TEST_CASE(testAddition) +{ + amount_t a0; + amount_t a1("$1"); + amount_t a2("2 EUR"); + amount_t a3("0.00 CAD"); + amount_t a4("$2"); + + balance_t b0; + balance_t b1(1.00); + balance_t b2(2UL); + balance_t b3(2L); + balance_t b4; + balance_t b5; + + b0 += b1; + b2 += b3; + b3 += a1; + b3 += a2; + b4 += b3; + b5 += a1; + b5 += a4; + + BOOST_CHECK_EQUAL(balance_t(1.00), b0); + BOOST_CHECK_EQUAL(b3 += a3, b4); + BOOST_CHECK_EQUAL(balance_t(4L), b2); + BOOST_CHECK_EQUAL(balance_t() += amount_t("$3"), b5); + + BOOST_CHECK_THROW(b3 += a0, balance_error); + + BOOST_CHECK(b0.valid()); + BOOST_CHECK(b1.valid()); + BOOST_CHECK(b2.valid()); + BOOST_CHECK(b3.valid()); + BOOST_CHECK(b4.valid()); + +} + BOOST_AUTO_TEST_SUITE_END() |