From 2db0bc9bf908ca1c1ba2c90a2e2d81d03d3e311a Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 10 Aug 2014 23:32:11 +0530 Subject: add test for multiplication --- test/unit/t_balance.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test/unit/t_balance.cc') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index eb47993d..1856ddb3 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -190,4 +190,49 @@ BOOST_AUTO_TEST_CASE(testEqaulity) BOOST_CHECK(b7.valid()); } +BOOST_AUTO_TEST_CASE(testMultiplication) +{ + amount_t a0; + amount_t a1("0.00"); + + balance_t b0; + balance_t b1(1.00); + balance_t b2(2UL); + balance_t b3("CAD -3"); + balance_t b4("EUR 4.99999"); + balance_t b5("$1"); + balance_t b6; + + BOOST_CHECK_EQUAL(b1 *= 2.00, amount_t(2.00)); + BOOST_CHECK_EQUAL(b2 *= 2L, amount_t(4L)); + BOOST_CHECK_EQUAL(b2 *= 2UL, amount_t(8UL)); + BOOST_CHECK_EQUAL(b3 *= amount_t("-8 CAD"), amount_t("CAD 24")); + BOOST_CHECK_EQUAL(b0 *= 2UL, b0); + BOOST_CHECK_EQUAL(b0 *= a1, a1); + + b6 += b3; + b3 += b4; + b3 += b5; + b3 *= 2L; + b6 *= 2L; + b4 *= 2L; + b5 *= 2L; + b6 += b4; + b6 += b5; + + BOOST_CHECK_EQUAL(b3, b6); + + BOOST_CHECK_THROW(b1 *= a0 , balance_error); + BOOST_CHECK_THROW(b4 *= amount_t("1 CAD") , balance_error); + BOOST_CHECK_THROW(b3 *= amount_t("1 CAD") , 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_AUTO_TEST_SUITE_END() -- cgit v1.2.3