diff options
author | tripun <tripun@gmail.com> | 2014-08-07 20:14:29 +0530 |
---|---|---|
committer | tripun <tripun@gmail.com> | 2014-08-11 21:01:24 +0530 |
commit | fe91656aa15d3eff23efaaae8f392e04a0f9d361 (patch) | |
tree | e81050854ff6c273d60db4931b3d7fbd9e3418d9 /test/unit/t_balance.cc | |
parent | 57877bf06250ecff207e716d99324b937e99f0eb (diff) | |
download | fork-ledger-fe91656aa15d3eff23efaaae8f392e04a0f9d361.tar.gz fork-ledger-fe91656aa15d3eff23efaaae8f392e04a0f9d361.tar.bz2 fork-ledger-fe91656aa15d3eff23efaaae8f392e04a0f9d361.zip |
add Equality unit test for balance
Diffstat (limited to 'test/unit/t_balance.cc')
-rw-r--r-- | test/unit/t_balance.cc | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index badfccee..3521f252 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -36,18 +36,38 @@ BOOST_AUTO_TEST_CASE(testConstructors) balance_t b1(1.00); balance_t b2(123456UL); balance_t b3(12345L); + balance_t b4(string ("EUR 123")); + balance_t b5("$ 456"); + balance_t b6; + balance_t b7(amount_t("$ 1.00")); + balance_t b8(b7); BOOST_CHECK_EQUAL(balance_t(), b0); BOOST_CHECK_NE(balance_t("0"), b0); BOOST_CHECK_NE(balance_t("0.0"), b0); BOOST_CHECK_EQUAL(b2, 123456UL); BOOST_CHECK_EQUAL(b3, 12345L); + BOOST_CHECK_EQUAL(b4, "EUR 123"); + BOOST_CHECK_EQUAL(b5, string("$ 456")); + BOOST_CHECK_EQUAL(b7, b8); + BOOST_CHECK_EQUAL(b8, amount_t("$ 1.00")); + + b5 = "euro 2345"; + b6 = string("DM -34532"); + b7 = amount_t("$ 1.00"); + + b8 = b5; + BOOST_CHECK_EQUAL(b5, b8); BOOST_CHECK(b0.valid()); BOOST_CHECK(b1.valid()); BOOST_CHECK(b2.valid()); BOOST_CHECK(b3.valid()); - + BOOST_CHECK(b4.valid()); + BOOST_CHECK(b5.valid()); + BOOST_CHECK(b6.valid()); + BOOST_CHECK(b7.valid()); + BOOST_CHECK(b8.valid()); } BOOST_AUTO_TEST_CASE(testAddition) @@ -86,7 +106,6 @@ BOOST_AUTO_TEST_CASE(testAddition) BOOST_CHECK(b3.valid()); BOOST_CHECK(b4.valid()); BOOST_CHECK(b5.valid()); - } BOOST_AUTO_TEST_CASE(testSubtraction) @@ -115,6 +134,7 @@ BOOST_AUTO_TEST_CASE(testSubtraction) BOOST_CHECK_EQUAL(balance_t(-1.00), b0); BOOST_CHECK_EQUAL(b3 -= a3, b4); BOOST_CHECK_EQUAL(balance_t(), b2); + BOOST_CHECK_EQUAL(b3 -= b2, b3); BOOST_CHECK_EQUAL(balance_t() -= amount_t("$3"), b5); BOOST_CHECK_THROW(b3 -= a0, balance_error); @@ -127,4 +147,47 @@ BOOST_AUTO_TEST_CASE(testSubtraction) BOOST_CHECK(b5.valid()); } +BOOST_AUTO_TEST_CASE(testEqaulity) +{ + amount_t a0; + amount_t a1("$1"); + amount_t a2("2 EUR"); + amount_t a3("0.00 CAD"); + + balance_t b0; + balance_t b1(1.00); + balance_t b2(2UL); + balance_t b3(2L); + balance_t b4("EUR 2"); + balance_t b5("$-1"); + balance_t b6("0.00"); + balance_t b7("0.00"); + + + BOOST_CHECK(b2 == b3); + BOOST_CHECK(b4 == a2); + BOOST_CHECK(b1 == "1.00"); + BOOST_CHECK(b5 == amount_t("-$1")); + BOOST_CHECK(!(b6 == "0")); + BOOST_CHECK(!(b6 == a3)); + BOOST_CHECK(!(b6 == "0.00")); + BOOST_CHECK(b6 == b7); + + b4 += b5; + b5 += a2; + + BOOST_CHECK(b4 == b5); + + BOOST_CHECK_THROW(b0 == a0, balance_error); + + BOOST_CHECK(b0.valid()); + BOOST_CHECK(b1.valid()); + BOOST_CHECK(b2.valid()); + BOOST_CHECK(b3.valid()); + BOOST_CHECK(b4.valid()); + BOOST_CHECK(b5.valid()); + BOOST_CHECK(b6.valid()); + BOOST_CHECK(b7.valid()); +} + BOOST_AUTO_TEST_SUITE_END() |