From 6f39d1169d67de29927a7bfe16c389075a6a9a43 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 28 Jul 2014 18:36:57 +0530 Subject: add balance Test constructors --- test/unit/t_balance.cc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index 0d681a88..dfa96821 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -28,6 +28,26 @@ struct balance_fixture { } }; -//BOOST_FIXTURE_TEST_SUITE(balance, balance_fixture) +BOOST_FIXTURE_TEST_SUITE(balance, balance_fixture) -//BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_CASE(testConstructors) +{ + balance_t b0; + balance_t b1(1.00); + balance_t b2(12345UL); + balance_t b3(123456L); + + 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(b0.valid()); + BOOST_CHECK(b1.valid()); + BOOST_CHECK(b2.valid()); + BOOST_CHECK(b3.valid()); + +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 696440e73591bc2e59d07adad54494247b0f4421 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 28 Jul 2014 20:01:23 +0530 Subject: added balance addition unit test --- test/unit/t_balance.cc | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'test/unit') 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() -- cgit v1.2.3 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 From fe91656aa15d3eff23efaaae8f392e04a0f9d361 Mon Sep 17 00:00:00 2001 From: tripun Date: Thu, 7 Aug 2014 20:14:29 +0530 Subject: add Equality unit test for balance --- test/unit/t_balance.cc | 67 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) (limited to 'test/unit') 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() -- cgit v1.2.3 From b9aef7b1ec3807149956fd0fd8567395064c7ad8 Mon Sep 17 00:00:00 2001 From: tripun Date: Thu, 7 Aug 2014 20:18:28 +0530 Subject: edited subraction test --- test/unit/t_balance.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index 3521f252..eb47993d 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -127,7 +127,7 @@ BOOST_AUTO_TEST_CASE(testSubtraction) b2 -= b3; b3 -= a1; b3 -= a2; - b4 += b3; + b4 = b3; b5 -= a1; b5 -= a4; -- cgit v1.2.3 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') 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 From 763c8c1162c9e2318e5e78c8b71e71607bcfeeef Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 10 Aug 2014 23:57:07 +0530 Subject: add unit test for balance division --- test/unit/t_balance.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index 1856ddb3..b7f68b14 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -235,4 +235,49 @@ BOOST_AUTO_TEST_CASE(testMultiplication) BOOST_CHECK(b6.valid()); } +BOOST_AUTO_TEST_CASE(testDivision) +{ + amount_t a0; + amount_t a1("0.00"); + + balance_t b0; + balance_t b1(4.00); + balance_t b2(4UL); + balance_t b3("CAD -24"); + balance_t b4("EUR 4"); + balance_t b5("$2"); + balance_t b6; + + BOOST_CHECK_EQUAL(b1 /= 2.00, amount_t(2.00)); + BOOST_CHECK_EQUAL(b2 /= 2L, amount_t(2L)); + BOOST_CHECK_EQUAL(b2 /= 2UL, amount_t(1UL)); + BOOST_CHECK_EQUAL(b3 /= amount_t("-3 CAD"), amount_t("CAD 8")); + BOOST_CHECK_EQUAL(b0 /= 2UL, b0); + + 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(b1 /= a1 , 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 From c24fbd6dfb10904b01d048c8b7787f5ae7cb5eb2 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 11 Aug 2014 00:39:41 +0530 Subject: add unit test negation for balance_t --- test/unit/t_balance.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index b7f68b14..239bc626 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -280,4 +280,39 @@ BOOST_AUTO_TEST_CASE(testDivision) BOOST_CHECK(b6.valid()); } +BOOST_AUTO_TEST_CASE(testNegation) +{ + amount_t a1("0.00"); + amount_t a2("$ 123"); + amount_t a3("EUR 456"); + + balance_t b0; + balance_t b1; + balance_t b2; + balance_t b3; + + b1 += a1; + b1 += a2; + b1 += a3; + b2 += -a1; + b2 += -a2; + b2 += -a3; + b3 = -b1; + + BOOST_CHECK_EQUAL(b0.negated(), b0); + BOOST_CHECK_EQUAL(b2, b3); + BOOST_CHECK_EQUAL(b2, -b1); + BOOST_CHECK_EQUAL(b2.negated(), b1); + + b2.in_place_negate(); + + BOOST_CHECK_EQUAL(b2, b1); + BOOST_CHECK_EQUAL(b1, -b3); + + BOOST_CHECK(b0.valid()); + BOOST_CHECK(b1.valid()); + BOOST_CHECK(b2.valid()); + BOOST_CHECK(b3.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 264f8c553cefb328debaa07b82b00a95a4a5e644 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 11 Aug 2014 00:46:32 +0530 Subject: add unit test Absolute for balance_t --- test/unit/t_balance.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index 239bc626..d9242929 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -315,4 +315,29 @@ BOOST_AUTO_TEST_CASE(testNegation) BOOST_CHECK(b3.valid()); } +BOOST_AUTO_TEST_CASE(testAbs) +{ + amount_t a1("0.00"); + amount_t a2("$ 123"); + amount_t a3("EUR 456"); + + balance_t b0; + balance_t b1; + balance_t b2; + + b1 += a1; + b1 += a2; + b1 += a3; + b2 += -a1; + b2 += -a2; + b2 += -a3; + + BOOST_CHECK_EQUAL(b0.abs(), b0); + BOOST_CHECK_EQUAL(b2.abs(), b1.abs()); + + BOOST_CHECK(b0.valid()); + BOOST_CHECK(b1.valid()); + BOOST_CHECK(b2.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From e94efddfb60bd07525865658b83c324de446fe7d Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 11 Aug 2014 01:17:08 +0530 Subject: add unit test Ceiling for balance_t --- test/unit/t_balance.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index d9242929..104e605e 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -340,4 +340,47 @@ BOOST_AUTO_TEST_CASE(testAbs) BOOST_CHECK(b2.valid()); } +BOOST_AUTO_TEST_CASE(testCeiling) +{ + amount_t a1("0.00"); + amount_t a2("$ 123.123"); + amount_t a3("EUR 456.56"); + amount_t a4(-a1); + amount_t a5(-a2); + amount_t a6(-a3); + + balance_t b0; + balance_t b1; + balance_t b2; + balance_t b3; + balance_t b4; + + b1 += a1; + b1 += a2; + b1 += a3; + b2 += -a1; + b2 += -a2; + b2 += -a3; + + b3 += a1.ceilinged(); + b3 += a2.ceilinged(); + b3 += a3.ceilinged(); + b4 += a4.ceilinged(); + b4 += a5.ceilinged(); + b4 += a6.ceilinged(); + + BOOST_CHECK_EQUAL(b0.ceilinged(), b0); + BOOST_CHECK_EQUAL(b2.ceilinged(), b4); + BOOST_CHECK_EQUAL(b1.ceilinged(), b3); + + b1.in_place_ceiling(); + BOOST_CHECK_EQUAL(b1, b3); + + 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() -- cgit v1.2.3 From 3a35d16c289e4f499fced36297e1313084e4d8ab Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 11 Aug 2014 01:21:36 +0530 Subject: add unit test Floor for balance_t --- test/unit/t_balance.cc | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index 104e605e..19a1bd69 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -383,4 +383,47 @@ BOOST_AUTO_TEST_CASE(testCeiling) BOOST_CHECK(b4.valid()); } +BOOST_AUTO_TEST_CASE(testFloor) +{ + amount_t a1("0.00"); + amount_t a2("$ 123.123"); + amount_t a3("EUR 456.56"); + amount_t a4(-a1); + amount_t a5(-a2); + amount_t a6(-a3); + + balance_t b0; + balance_t b1; + balance_t b2; + balance_t b3; + balance_t b4; + + b1 += a1; + b1 += a2; + b1 += a3; + b2 += -a1; + b2 += -a2; + b2 += -a3; + + b3 += a1.floored(); + b3 += a2.floored(); + b3 += a3.floored(); + b4 += a4.floored(); + b4 += a5.floored(); + b4 += a6.floored(); + + BOOST_CHECK_EQUAL(b0.floored(), b0); + BOOST_CHECK_EQUAL(b2.floored(), b4); + BOOST_CHECK_EQUAL(b1.floored(), b3); + + b1.in_place_floor(); + BOOST_CHECK_EQUAL(b1, b3); + + 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() -- cgit v1.2.3 From c5f41b85195cb3f671888289071d26531f198a80 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 11 Aug 2014 02:02:05 +0530 Subject: add unit test Round for balance_t --- test/unit/t_balance.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index 19a1bd69..8f21e23f 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -426,4 +426,54 @@ BOOST_AUTO_TEST_CASE(testFloor) BOOST_CHECK(b4.valid()); } +BOOST_AUTO_TEST_CASE(testRound) +{ + amount_t a1("0.00"); + amount_t a2("$ 123.123"); + amount_t a3("EUR 456.567"); + amount_t a4("0.00"); + amount_t a5("$ 123.12"); + amount_t a6("EUR 456.57"); + + balance_t b0; + balance_t b1; + balance_t b2; + balance_t b3; + balance_t b4; + + b1 += a1; + b1 += a2; + b1 += a3; + b2 += a4; + b2 += a5; + b2 += a6; + + a1.in_place_roundto(2); + a2.in_place_roundto(2); + a3.in_place_roundto(2); + a4.in_place_roundto(2); + a5.in_place_roundto(2); + a6.in_place_roundto(2); + + b3 += a1; + b3 += a2; + b3 += a3; + b4 += a4; + b4 += a5; + b4 += a6; + + BOOST_CHECK_EQUAL(b0.rounded(), b0); + BOOST_CHECK_EQUAL(b2.rounded(), b4); + BOOST_CHECK_EQUAL(b1.rounded(), b4); + + b1.in_place_round(); + BOOST_CHECK_EQUAL(b1, b3); + + 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() -- cgit v1.2.3 From 7e817d45d9c5a7cdee5d5df59e9794e8512a0d9a Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 11 Aug 2014 02:30:01 +0530 Subject: add unit test Truth for balance_t --- test/unit/t_balance.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index 8f21e23f..468f03bb 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -476,4 +476,24 @@ BOOST_AUTO_TEST_CASE(testRound) BOOST_CHECK(b4.valid()); } +BOOST_AUTO_TEST_CASE(testTruth) +{ + amount_t a1("0.00"); + amount_t a2("$ 123"); + amount_t a3("EUR 456"); + + balance_t b0; + balance_t b1; + + b1 += a1; + b1 += a2; + b1 += a3; + + BOOST_CHECK(!b0); + BOOST_CHECK(b1); + + BOOST_CHECK(b0.valid()); + BOOST_CHECK(b1.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 3c04ea50ac60662e436ead8af09fd3a5559db199 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 11 Aug 2014 02:36:13 +0530 Subject: add unit test of Zero for balance_t --- test/unit/t_balance.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index 468f03bb..c4ec2f31 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -496,4 +496,30 @@ BOOST_AUTO_TEST_CASE(testTruth) BOOST_CHECK(b1.valid()); } +BOOST_AUTO_TEST_CASE(testForZero) +{ + amount_t a1("0.00"); + amount_t a2("$ 123"); + amount_t a3("EUR 456"); + + balance_t b0; + balance_t b1; + + b1 += a1; + b1 += a2; + b1 += a3; + + BOOST_CHECK(b0.is_empty()); + BOOST_CHECK(b0.is_zero()); + BOOST_CHECK(b0.is_realzero()); + BOOST_CHECK(!b0.is_nonzero()); + BOOST_CHECK(!b1.is_empty()); + BOOST_CHECK(!b1.is_zero()); + BOOST_CHECK(!b1.is_realzero()); + BOOST_CHECK(b1.is_nonzero()); + + BOOST_CHECK(b0.valid()); + BOOST_CHECK(b1.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 84b9ca73aac73b6c7938abea91f8f550a0fad101 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 11 Aug 2014 02:46:01 +0530 Subject: add unit test printing for balance_t --- test/unit/t_balance.cc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index c4ec2f31..eac230be 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -522,4 +522,35 @@ BOOST_AUTO_TEST_CASE(testForZero) BOOST_CHECK(b1.valid()); } +BOOST_AUTO_TEST_CASE(testPrinting) +{ + amount_t a1("0.00"); + amount_t a2("$ 123"); + amount_t a3("EUR 456"); + + balance_t b0; + balance_t b1; + + b1 += a1; + b1 += a2; + b1 += a3; + + { + std::ostringstream bufstr; + b0.dump(bufstr); + BOOST_CHECK_EQUAL(std::string("BALANCE()"), bufstr.str()); + } + + { + std::ostringstream bufstr; + b1.dump(bufstr); + + BOOST_CHECK_EQUAL(std::string("BALANCE(EUR 456, $ 123.00)"), + bufstr.str()); + } + + BOOST_CHECK(b0.valid()); + BOOST_CHECK(b1.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 0e1ced72bd7839162a33eb34f717a94eae777fc4 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 11 Aug 2014 20:54:59 +0530 Subject: Revert "add unit test printing for balance_t" until issue is fixed. Getting different output on system than travis-ci. This reverts commit 272e3cb3799937dcd3c379de56b299a3cbde52ca. --- test/unit/t_balance.cc | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'test/unit') diff --git a/test/unit/t_balance.cc b/test/unit/t_balance.cc index eac230be..c4ec2f31 100644 --- a/test/unit/t_balance.cc +++ b/test/unit/t_balance.cc @@ -522,35 +522,4 @@ BOOST_AUTO_TEST_CASE(testForZero) BOOST_CHECK(b1.valid()); } -BOOST_AUTO_TEST_CASE(testPrinting) -{ - amount_t a1("0.00"); - amount_t a2("$ 123"); - amount_t a3("EUR 456"); - - balance_t b0; - balance_t b1; - - b1 += a1; - b1 += a2; - b1 += a3; - - { - std::ostringstream bufstr; - b0.dump(bufstr); - BOOST_CHECK_EQUAL(std::string("BALANCE()"), bufstr.str()); - } - - { - std::ostringstream bufstr; - b1.dump(bufstr); - - BOOST_CHECK_EQUAL(std::string("BALANCE(EUR 456, $ 123.00)"), - bufstr.str()); - } - - BOOST_CHECK(b0.valid()); - BOOST_CHECK(b1.valid()); -} - BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3