From 57877bf06250ecff207e716d99324b937e99f0eb Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 28 Jul 2014 21:04:49 +0530 Subject: added boost subtraction unit test --- test/unit/t_balance.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index 7dff7e1d..badfccee 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -85,7 +85,46 @@ BOOST_AUTO_TEST_CASE(testAddition) BOOST_CHECK(b2.valid()); BOOST_CHECK(b3.valid()); BOOST_CHECK(b4.valid()); + BOOST_CHECK(b5.valid()); } +BOOST_AUTO_TEST_CASE(testSubtraction) +{ + 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(), 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_CHECK(b5.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3