From a99695f69b395c9664447b5af82893fb755bd4c0 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 7 May 2007 11:36:36 +0000 Subject: More test reorg. --- tests/numerics/t_amount.cc | 1619 ++++++++++++++++++++++---------------------- tests/numerics/t_amount.h | 76 +-- 2 files changed, 843 insertions(+), 852 deletions(-) (limited to 'tests/numerics') diff --git a/tests/numerics/t_amount.cc b/tests/numerics/t_amount.cc index 94e32c01..67ea1781 100644 --- a/tests/numerics/t_amount.cc +++ b/tests/numerics/t_amount.cc @@ -2,9 +2,9 @@ #define internalAmount(x) amount_t::exact(x) -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicAmountTestCase, "numerics"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AmountTestCase, "numerics"); -void BasicAmountTestCase::setUp() +void AmountTestCase::setUp() { ledger::set_session_context(&session); @@ -14,14 +14,14 @@ void BasicAmountTestCase::setUp() amount_t::stream_fullstrings = true; // makes error reports from UnitTests accurate } -void BasicAmountTestCase::tearDown() +void AmountTestCase::tearDown() { amount_t::stream_fullstrings = false; ledger::set_session_context(); } -void BasicAmountTestCase::testConstructors() +void AmountTestCase::testConstructors() { amount_t x0; amount_t x1(123456L); @@ -47,20 +47,67 @@ void BasicAmountTestCase::testConstructors() assertEqual(x10, x3); assertEqual(x10, x9); - CPPUNIT_ASSERT(x0.valid()); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(x2.valid()); - CPPUNIT_ASSERT(x3.valid()); - CPPUNIT_ASSERT(x5.valid()); - CPPUNIT_ASSERT(x6.valid()); - CPPUNIT_ASSERT(x7.valid()); - CPPUNIT_ASSERT(x8.valid()); - CPPUNIT_ASSERT(x9.valid()); - CPPUNIT_ASSERT(x10.valid()); - CPPUNIT_ASSERT(x11.valid()); + assertTrue(x0.valid()); + assertTrue(x1.valid()); + assertTrue(x2.valid()); + assertTrue(x3.valid()); + assertTrue(x5.valid()); + assertTrue(x6.valid()); + assertTrue(x7.valid()); + assertTrue(x8.valid()); + assertTrue(x9.valid()); + assertTrue(x10.valid()); + assertTrue(x11.valid()); } -void BasicAmountTestCase::testAssignment() +void AmountTestCase::testCommodityConstructors() +{ + amount_t x1("$123.45"); + amount_t x2("-$123.45"); + amount_t x3("$-123.45"); + amount_t x4("DM 123.45"); + amount_t x5("-DM 123.45"); + amount_t x6("DM -123.45"); + amount_t x7("123.45 euro"); + amount_t x8("-123.45 euro"); + amount_t x9("123.45€"); + amount_t x10("-123.45€"); + + assertEqual(amount_t("$123.45"), x1); + assertEqual(amount_t("-$123.45"), x2); + assertEqual(amount_t("$-123.45"), x3); + assertEqual(amount_t("DM 123.45"), x4); + assertEqual(amount_t("-DM 123.45"), x5); + assertEqual(amount_t("DM -123.45"), x6); + assertEqual(amount_t("123.45 euro"), x7); + assertEqual(amount_t("-123.45 euro"), x8); + assertEqual(amount_t("123.45€"), x9); + assertEqual(amount_t("-123.45€"), x10); + + assertEqual(string("$123.45"), x1.to_string()); + assertEqual(string("$-123.45"), x2.to_string()); + assertEqual(string("$-123.45"), x3.to_string()); + assertEqual(string("DM 123.45"), x4.to_string()); + assertEqual(string("DM -123.45"), x5.to_string()); + assertEqual(string("DM -123.45"), x6.to_string()); + assertEqual(string("123.45 euro"), x7.to_string()); + assertEqual(string("-123.45 euro"), x8.to_string()); + assertEqual(string("123.45€"), x9.to_string()); + assertEqual(string("-123.45€"), x10.to_string()); + + assertValid(x1); + assertValid(x2); + assertValid(x3); + assertValid(x4); + assertValid(x5); + assertValid(x6); + assertValid(x7); + assertValid(x8); + assertValid(x9); + assertValid(x10); +} + +void AmountTestCase::testAssignment() { amount_t x0; amount_t x1 = 123456L; @@ -102,19 +149,66 @@ void BasicAmountTestCase::testAssignment() assertEqual(x10, x3); assertEqual(x10, x9); - CPPUNIT_ASSERT(x0.valid()); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(x2.valid()); - CPPUNIT_ASSERT(x3.valid()); - CPPUNIT_ASSERT(x5.valid()); - CPPUNIT_ASSERT(x6.valid()); - CPPUNIT_ASSERT(x7.valid()); - CPPUNIT_ASSERT(x8.valid()); - CPPUNIT_ASSERT(x9.valid()); - CPPUNIT_ASSERT(x10.valid()); + assertTrue(x0.valid()); + assertTrue(x1.valid()); + assertTrue(x2.valid()); + assertTrue(x3.valid()); + assertTrue(x5.valid()); + assertTrue(x6.valid()); + assertTrue(x7.valid()); + assertTrue(x8.valid()); + assertTrue(x9.valid()); + assertTrue(x10.valid()); +} + +void AmountTestCase::testCommodityAssignment() +{ + amount_t x1 = "$123.45"; + amount_t x2 = "-$123.45"; + amount_t x3 = "$-123.45"; + amount_t x4 = "DM 123.45"; + amount_t x5 = "-DM 123.45"; + amount_t x6 = "DM -123.45"; + amount_t x7 = "123.45 euro"; + amount_t x8 = "-123.45 euro"; + amount_t x9 = "123.45€"; + amount_t x10 = "-123.45€"; + + assertEqual(amount_t("$123.45"), x1); + assertEqual(amount_t("-$123.45"), x2); + assertEqual(amount_t("$-123.45"), x3); + assertEqual(amount_t("DM 123.45"), x4); + assertEqual(amount_t("-DM 123.45"), x5); + assertEqual(amount_t("DM -123.45"), x6); + assertEqual(amount_t("123.45 euro"), x7); + assertEqual(amount_t("-123.45 euro"), x8); + assertEqual(amount_t("123.45€"), x9); + assertEqual(amount_t("-123.45€"), x10); + + assertEqual(string("$123.45"), x1.to_string()); + assertEqual(string("$-123.45"), x2.to_string()); + assertEqual(string("$-123.45"), x3.to_string()); + assertEqual(string("DM 123.45"), x4.to_string()); + assertEqual(string("DM -123.45"), x5.to_string()); + assertEqual(string("DM -123.45"), x6.to_string()); + assertEqual(string("123.45 euro"), x7.to_string()); + assertEqual(string("-123.45 euro"), x8.to_string()); + assertEqual(string("123.45€"), x9.to_string()); + assertEqual(string("-123.45€"), x10.to_string()); + + assertValid(x1); + assertValid(x2); + assertValid(x3); + assertValid(x4); + assertValid(x5); + assertValid(x6); + assertValid(x7); + assertValid(x8); + assertValid(x9); + assertValid(x10); } -void BasicAmountTestCase::testEquality() +void AmountTestCase::testEquality() { amount_t x1(123456L); amount_t x2(456789L); @@ -123,22 +217,67 @@ void BasicAmountTestCase::testEquality() amount_t x5("123456.0"); amount_t x6(123456.0F); - CPPUNIT_ASSERT(x1 == 123456L); - CPPUNIT_ASSERT(x1 != x2); - CPPUNIT_ASSERT(x1 == (x2 - x3)); - CPPUNIT_ASSERT(x1 == x4); - CPPUNIT_ASSERT(x4 == x5); - CPPUNIT_ASSERT(x4 == x6); - - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(x2.valid()); - CPPUNIT_ASSERT(x3.valid()); - CPPUNIT_ASSERT(x4.valid()); - CPPUNIT_ASSERT(x5.valid()); - CPPUNIT_ASSERT(x6.valid()); + assertTrue(x1 == 123456L); + assertTrue(x1 != x2); + assertTrue(x1 == (x2 - x3)); + assertTrue(x1 == x4); + assertTrue(x4 == x5); + assertTrue(x4 == x6); + + assertTrue(x1.valid()); + assertTrue(x2.valid()); + assertTrue(x3.valid()); + assertTrue(x4.valid()); + assertTrue(x5.valid()); + assertTrue(x6.valid()); +} + +void AmountTestCase::testCommodityEquality() +{ + amount_t x0; + amount_t x1 = "$123.45"; + amount_t x2 = "-$123.45"; + amount_t x3 = "$-123.45"; + amount_t x4 = "DM 123.45"; + amount_t x5 = "-DM 123.45"; + amount_t x6 = "DM -123.45"; + amount_t x7 = "123.45 euro"; + amount_t x8 = "-123.45 euro"; + amount_t x9 = "123.45€"; + amount_t x10 = "-123.45€"; + + assertTrue(x0.is_null()); + assertTrue(x0.is_zero()); + assertTrue(x0.is_realzero()); + assertTrue(x0.sign() == 0); + assertTrue(x0.compare(x1) < 0); + assertTrue(x0.compare(x2) > 0); + assertTrue(x0.compare(x0) == 0); + + assertTrue(x1 != x2); + assertTrue(x1 != x4); + assertTrue(x1 != x7); + assertTrue(x1 != x9); + assertTrue(x2 == x3); + assertTrue(x4 != x5); + assertTrue(x5 == x6); + assertTrue(x7 == - x8); + assertTrue(x9 == - x10); + + assertValid(x0); + assertValid(x1); + assertValid(x2); + assertValid(x3); + assertValid(x4); + assertValid(x5); + assertValid(x6); + assertValid(x7); + assertValid(x8); + assertValid(x9); + assertValid(x10); } -void BasicAmountTestCase::testComparisons() +void AmountTestCase::testComparisons() { amount_t x0; amount_t x1(-123L); @@ -148,36 +287,70 @@ void BasicAmountTestCase::testComparisons() amount_t x5("-123.45"); amount_t x6("123.45"); - CPPUNIT_ASSERT(x0 > x1); - CPPUNIT_ASSERT(x0 < x2); - CPPUNIT_ASSERT(x0 > x3); - CPPUNIT_ASSERT(x0 < x4); - CPPUNIT_ASSERT(x0 > x5); - CPPUNIT_ASSERT(x0 < x6); - - CPPUNIT_ASSERT(x1 > x3); - CPPUNIT_ASSERT(x3 <= x5); - CPPUNIT_ASSERT(x3 >= x5); - CPPUNIT_ASSERT(x3 < x1); - CPPUNIT_ASSERT(x3 < x4); - - CPPUNIT_ASSERT(x1 < 100L); - CPPUNIT_ASSERT(x1 < 100UL); - CPPUNIT_ASSERT(x1 < 100.0); - CPPUNIT_ASSERT(100L > x1); - CPPUNIT_ASSERT(100UL > x1); - CPPUNIT_ASSERT(100.0 > x1); - - CPPUNIT_ASSERT(x0.valid()); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(x2.valid()); - CPPUNIT_ASSERT(x3.valid()); - CPPUNIT_ASSERT(x4.valid()); - CPPUNIT_ASSERT(x5.valid()); - CPPUNIT_ASSERT(x6.valid()); + assertTrue(x0 > x1); + assertTrue(x0 < x2); + assertTrue(x0 > x3); + assertTrue(x0 < x4); + assertTrue(x0 > x5); + assertTrue(x0 < x6); + + assertTrue(x1 > x3); + assertTrue(x3 <= x5); + assertTrue(x3 >= x5); + assertTrue(x3 < x1); + assertTrue(x3 < x4); + + assertTrue(x1 < 100L); + assertTrue(x1 < 100UL); + assertTrue(x1 < 100.0); + assertTrue(100L > x1); + assertTrue(100UL > x1); + assertTrue(100.0 > x1); + + assertTrue(x0.valid()); + assertTrue(x1.valid()); + assertTrue(x2.valid()); + assertTrue(x3.valid()); + assertTrue(x4.valid()); + assertTrue(x5.valid()); + assertTrue(x6.valid()); +} + +void AmountTestCase::testCommodityComparisons() +{ + amount_t x0; + amount_t x1("$-123"); + amount_t x2("$123.00"); + amount_t x3(internalAmount("$-123.4544")); + amount_t x4(internalAmount("$123.4544")); + amount_t x5("$-123.45"); + amount_t x6("$123.45"); + + assertTrue(x0 > x1); + assertTrue(x0 < x2); + assertTrue(x0 > x3); + assertTrue(x0 < x4); + assertTrue(x0 > x5); + assertTrue(x0 < x6); + + assertTrue(x1 > x3); + assertTrue(x3 <= x5); + assertTrue(x3 < x5); + assertTrue(x3 <= x5); + assertFalse(x3 == x5); + assertTrue(x3 < x1); + assertTrue(x3 < x4); + + assertValid(x0); + assertValid(x1); + assertValid(x2); + assertValid(x3); + assertValid(x4); + assertValid(x5); + assertValid(x6); } -void BasicAmountTestCase::testIntegerAddition() +void AmountTestCase::testIntegerAddition() { amount_t x1(123L); amount_t y1(456L); @@ -195,12 +368,12 @@ void BasicAmountTestCase::testIntegerAddition() assertEqual(amount_t("246913578246913578246913578"), x4 + x4); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(y1.valid()); - CPPUNIT_ASSERT(x4.valid()); + assertTrue(x1.valid()); + assertTrue(y1.valid()); + assertTrue(x4.valid()); } -void BasicAmountTestCase::testFractionalAddition() +void AmountTestCase::testFractionalAddition() { amount_t x1(123.123); amount_t y1(456.456); @@ -220,12 +393,66 @@ void BasicAmountTestCase::testFractionalAddition() assertEqual(amount_t("246913578246913578.246913578246913578"), x2 + x2); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(y1.valid()); - CPPUNIT_ASSERT(x2.valid()); + assertTrue(x1.valid()); + assertTrue(y1.valid()); + assertTrue(x2.valid()); +} + +void AmountTestCase::testCommodityAddition() +{ + amount_t x0; + amount_t x1("$123.45"); + amount_t x2(internalAmount("$123.456789")); + amount_t x3("DM 123.45"); + amount_t x4("123.45 euro"); + amount_t x5("123.45€"); + amount_t x6("123.45"); + + assertEqual(amount_t("$246.90"), x1 + x1); + assertNotEqual(amount_t("$246.91"), x1 + x2); + assertEqual(internalAmount("$246.906789"), x1 + x2); + + // Converting to string drops internal precision + assertEqual(string("$246.90"), (x1 + x1).to_string()); + assertEqual(string("$246.91"), (x1 + x2).to_string()); + + assertThrow(x1 + x0, amount_error); + assertThrow(x1 + x3, amount_error); + assertThrow(x1 + x4, amount_error); + assertThrow(x1 + x5, amount_error); + assertThrow(x1 + x6, amount_error); + assertThrow(x1 + 123.45, amount_error); + assertThrow(x1 + 123L, amount_error); + + assertEqual(amount_t("DM 246.90"), x3 + x3); + assertEqual(amount_t("246.90 euro"), x4 + x4); + assertEqual(amount_t("246.90€"), x5 + x5); + + assertEqual(string("DM 246.90"), (x3 + x3).to_string()); + assertEqual(string("246.90 euro"), (x4 + x4).to_string()); + assertEqual(string("246.90€"), (x5 + x5).to_string()); + + x1 += amount_t("$456.45"); + assertEqual(amount_t("$579.90"), x1); + x1 += amount_t("$456.45"); + assertEqual(amount_t("$1036.35"), x1); + x1 += amount_t("$456"); + assertEqual(amount_t("$1492.35"), x1); + + amount_t x7(internalAmount("$123456789123456789.123456789123456789")); + + assertEqual(internalAmount("$246913578246913578.246913578246913578"), x7 + x7); + + assertValid(x1); + assertValid(x2); + assertValid(x3); + assertValid(x4); + assertValid(x5); + assertValid(x6); + assertValid(x7); } -void BasicAmountTestCase::testIntegerSubtraction() +void AmountTestCase::testIntegerSubtraction() { amount_t x1(123L); amount_t y1(456L); @@ -246,13 +473,13 @@ void BasicAmountTestCase::testIntegerSubtraction() assertEqual(amount_t("123456789115218063137220803"), x4 - y4); assertEqual(amount_t("-123456789115218063137220803"), y4 - x4); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(y1.valid()); - CPPUNIT_ASSERT(x4.valid()); - CPPUNIT_ASSERT(y4.valid()); + assertTrue(x1.valid()); + assertTrue(y1.valid()); + assertTrue(x4.valid()); + assertTrue(y4.valid()); } -void BasicAmountTestCase::testFractionalSubtraction() +void AmountTestCase::testFractionalSubtraction() { amount_t x1(123.123); amount_t y1(456.456); @@ -273,29 +500,108 @@ void BasicAmountTestCase::testFractionalSubtraction() assertEqual(amount_t("123446916777474329.874482549545456789"), x2 - y2); assertEqual(amount_t("-123446916777474329.874482549545456789"), y2 - x2); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(y1.valid()); - CPPUNIT_ASSERT(x2.valid()); - CPPUNIT_ASSERT(y2.valid()); + assertTrue(x1.valid()); + assertTrue(y1.valid()); + assertTrue(x2.valid()); + assertTrue(y2.valid()); } -void BasicAmountTestCase::testIntegerMultiplication() +void AmountTestCase::testCommoditySubtraction() { - amount_t x1(123L); - amount_t y1(456L); + amount_t x0; + amount_t x1("$123.45"); + amount_t x2(internalAmount("$123.456789")); + amount_t x3("DM 123.45"); + amount_t x4("123.45 euro"); + amount_t x5("123.45€"); + amount_t x6("123.45"); - assertEqual(amount_t(0L), x1 * 0L); - assertEqual(amount_t(0L), amount_t(0L) * x1); - assertEqual(amount_t(0L), 0L * x1); - assertEqual(x1, x1 * 1L); - assertEqual(x1, amount_t(1L) * x1); - assertEqual(x1, 1L * x1); - assertEqual(- x1, x1 * -1L); - assertEqual(- x1, amount_t(-1L) * x1); - assertEqual(- x1, -1L * x1); - assertEqual(amount_t(56088L), x1 * y1); - assertEqual(amount_t(56088L), y1 * x1); - assertEqual(amount_t(56088L), x1 * 456L); + assertNotEqual(amount_t(), x1 - x1); + assertEqual(amount_t("$0"), x1 - x1); + assertEqual(amount_t("$23.45"), x1 - amount_t("$100.00")); + assertEqual(amount_t("$-23.45"), amount_t("$100.00") - x1); + assertNotEqual(amount_t("$-0.01"), x1 - x2); + assertEqual(internalAmount("$-0.006789"), x1 - x2); + + // Converting to string drops internal precision. If an amount is + // zero, it drops the commodity as well. + assertEqual(string("$0.00"), (x1 - x1).to_string()); + assertEqual(string("$-0.01"), (x1 - x2).to_string()); + + assertThrow(x1 - x0, amount_error); + assertThrow(x1 - x3, amount_error); + assertThrow(x1 - x4, amount_error); + assertThrow(x1 - x5, amount_error); + assertThrow(x1 - x6, amount_error); + assertThrow(x1 - 123.45, amount_error); + assertThrow(x1 - 123L, amount_error); + + assertEqual(amount_t("DM 0.00"), x3 - x3); + assertEqual(amount_t("DM 23.45"), x3 - amount_t("DM 100.00")); + assertEqual(amount_t("DM -23.45"), amount_t("DM 100.00") - x3); + assertEqual(amount_t("0.00 euro"), x4 - x4); + assertEqual(amount_t("23.45 euro"), x4 - amount_t("100.00 euro")); + assertEqual(amount_t("-23.45 euro"), amount_t("100.00 euro") - x4); + assertEqual(amount_t("0.00€"), x5 - x5); + assertEqual(amount_t("23.45€"), x5 - amount_t("100.00€")); + assertEqual(amount_t("-23.45€"), amount_t("100.00€") - x5); + + assertEqual(string("DM 0.00"), (x3 - x3).to_string()); + assertEqual(string("DM 23.45"), (x3 - amount_t("DM 100.00")).to_string()); + assertEqual(string("DM -23.45"), (amount_t("DM 100.00") - x3).to_string()); + assertEqual(string("0.00 euro"), (x4 - x4).to_string()); + assertEqual(string("23.45 euro"), (x4 - amount_t("100.00 euro")).to_string()); + assertEqual(string("-23.45 euro"), (amount_t("100.00 euro") - x4).to_string()); + assertEqual(string("0.00€"), (x5 - x5).to_string()); + assertEqual(string("23.45€"), (x5 - amount_t("100.00€")).to_string()); + assertEqual(string("-23.45€"), (amount_t("100.00€") - x5).to_string()); + + x1 -= amount_t("$456.45"); + assertEqual(amount_t("$-333.00"), x1); + x1 -= amount_t("$456.45"); + assertEqual(amount_t("$-789.45"), x1); + x1 -= amount_t("$456"); + assertEqual(amount_t("$-1245.45"), x1); + + amount_t x7(internalAmount("$123456789123456789.123456789123456789")); + amount_t x8(internalAmount("$2354974984698.98459845984598")); + + assertEqual(internalAmount("$123454434148472090.138858329277476789"), x7 - x8); + assertEqual(string("$123454434148472090.138858329277476789"), (x7 - x8).to_string()); + assertEqual(string("$123454434148472090.14"), + (amount_t("$1.00") * (x7 - x8)).to_string()); + assertEqual(internalAmount("$-123454434148472090.138858329277476789"), x8 - x7); + assertEqual(string("$-123454434148472090.138858329277476789"), (x8 - x7).to_string()); + assertEqual(string("$-123454434148472090.14"), + (amount_t("$1.00") * (x8 - x7)).to_string()); + + assertValid(x1); + assertValid(x2); + assertValid(x3); + assertValid(x4); + assertValid(x5); + assertValid(x6); + assertValid(x7); + assertValid(x8); +} + +void AmountTestCase::testIntegerMultiplication() +{ + amount_t x1(123L); + amount_t y1(456L); + + assertEqual(amount_t(0L), x1 * 0L); + assertEqual(amount_t(0L), amount_t(0L) * x1); + assertEqual(amount_t(0L), 0L * x1); + assertEqual(x1, x1 * 1L); + assertEqual(x1, amount_t(1L) * x1); + assertEqual(x1, 1L * x1); + assertEqual(- x1, x1 * -1L); + assertEqual(- x1, amount_t(-1L) * x1); + assertEqual(- x1, -1L * x1); + assertEqual(amount_t(56088L), x1 * y1); + assertEqual(amount_t(56088L), y1 * x1); + assertEqual(amount_t(56088L), x1 * 456L); assertEqual(amount_t(56088L), amount_t(456L) * x1); assertEqual(amount_t(56088L), 456L * x1); @@ -309,12 +615,12 @@ void BasicAmountTestCase::testIntegerMultiplication() assertEqual(amount_t("15241578780673678546105778281054720515622620750190521"), x4 * x4); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(y1.valid()); - CPPUNIT_ASSERT(x4.valid()); + assertTrue(x1.valid()); + assertTrue(y1.valid()); + assertTrue(x4.valid()); } -void BasicAmountTestCase::testFractionalMultiplication() +void AmountTestCase::testFractionalMultiplication() { amount_t x1(123.123); amount_t y1(456.456); @@ -346,12 +652,66 @@ void BasicAmountTestCase::testFractionalMultiplication() assertEqual(amount_t("15241578780673678546105778311537878.046486820281054720515622620750190521"), x2 * x2); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(y1.valid()); - CPPUNIT_ASSERT(x2.valid()); + assertTrue(x1.valid()); + assertTrue(y1.valid()); + assertTrue(x2.valid()); +} + +void AmountTestCase::testCommodityMultiplication() +{ + amount_t x1("$123.12"); + amount_t y1("$456.45"); + amount_t x2(internalAmount("$123.456789")); + amount_t x3("DM 123.45"); + amount_t x4("123.45 euro"); + amount_t x5("123.45€"); + + assertEqual(amount_t("$0.00"), x1 * 0L); + assertEqual(amount_t("$0.00"), 0L * x1); + assertEqual(x1, x1 * 1L); + assertEqual(x1, 1L * x1); + assertEqual(- x1, x1 * -1L); + assertEqual(- x1, -1L * x1); + assertEqual(internalAmount("$56198.124"), x1 * y1); + assertEqual(string("$56198.12"), (x1 * y1).to_string()); + assertEqual(internalAmount("$56198.124"), y1 * x1); + assertEqual(string("$56198.12"), (y1 * x1).to_string()); + + // Internal amounts retain their precision, even when being + // converted to strings + assertEqual(internalAmount("$15199.99986168"), x1 * x2); + assertEqual(internalAmount("$15199.99986168"), x2 * x1); + assertEqual(string("$15200.00"), (x1 * x2).to_string()); + assertEqual(string("$15199.99986168"), (x2 * x1).to_string()); + + assertThrow(x1 * x3, amount_error); + assertThrow(x1 * x4, amount_error); + assertThrow(x1 * x5, amount_error); + + x1 *= amount_t("123.12"); + assertEqual(internalAmount("$15158.5344"), x1); + assertEqual(string("$15158.53"), x1.to_string()); + x1 *= 123.12; + assertEqual(internalAmount("$1866318.755328"), x1); + assertEqual(string("$1866318.76"), x1.to_string()); + x1 *= 123L; + assertEqual(internalAmount("$229557206.905344"), x1); + assertEqual(string("$229557206.91"), x1.to_string()); + + amount_t x7(internalAmount("$123456789123456789.123456789123456789")); + + assertEqual(internalAmount("$15241578780673678546105778311537878.046486820281054720515622620750190521"), + x7 * x7); + + assertValid(x1); + assertValid(x2); + assertValid(x3); + assertValid(x4); + assertValid(x5); + assertValid(x7); } -void BasicAmountTestCase::testIntegerDivision() +void AmountTestCase::testIntegerDivision() { amount_t x1(123L); amount_t y1(456L); @@ -382,13 +742,13 @@ void BasicAmountTestCase::testIntegerDivision() assertEqual(amount_t(1L), x4 / x4); assertEqual(amount_t("2204585520061728377204585.517857"), x4 / y4); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(y1.valid()); - CPPUNIT_ASSERT(x4.valid()); - CPPUNIT_ASSERT(y4.valid()); + assertTrue(x1.valid()); + assertTrue(y1.valid()); + assertTrue(x4.valid()); + assertTrue(y4.valid()); } -void BasicAmountTestCase::testFractionalDivision() +void AmountTestCase::testFractionalDivision() { amount_t x1(123.123); amount_t y1(456.456); @@ -421,13 +781,72 @@ void BasicAmountTestCase::testFractionalDivision() assertEqual(amount_t(1.0), x4 / x4); assertEqual(amount_t("21739560323910.7554497273748437197344556164046"), x4 / y4); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(y1.valid()); - CPPUNIT_ASSERT(x4.valid()); - CPPUNIT_ASSERT(y4.valid()); + assertTrue(x1.valid()); + assertTrue(y1.valid()); + assertTrue(x4.valid()); + assertTrue(y4.valid()); +} + +void AmountTestCase::testCommodityDivision() +{ + amount_t x1("$123.12"); + amount_t y1("$456.45"); + amount_t x2(internalAmount("$123.456789")); + amount_t x3("DM 123.45"); + amount_t x4("123.45 euro"); + amount_t x5("123.45€"); + + assertThrow(x1 / 0L, amount_error); + assertEqual(amount_t("$0.00"), 0L / x1); + assertEqual(x1, x1 / 1L); + assertEqual(internalAmount("$0.00812216"), 1L / x1); + assertEqual(- x1, x1 / -1L); + assertEqual(internalAmount("$-0.00812216"), -1L / x1); + assertEqual(internalAmount("$0.26973382"), x1 / y1); + assertEqual(string("$0.27"), (x1 / y1).to_string()); + assertEqual(internalAmount("$3.70735867"), y1 / x1); + assertEqual(string("$3.71"), (y1 / x1).to_string()); + + // Internal amounts retain their precision, even when being + // converted to strings + assertEqual(internalAmount("$0.99727201"), x1 / x2); + assertEqual(internalAmount("$1.00273545321637426901"), x2 / x1); + assertEqual(string("$1.00"), (x1 / x2).to_string()); + assertEqual(string("$1.00273545321637426901"), (x2 / x1).to_string()); + + assertThrow(x1 / x3, amount_error); + assertThrow(x1 / x4, amount_error); + assertThrow(x1 / x5, amount_error); + + x1 /= amount_t("123.12"); + assertEqual(internalAmount("$1.00"), x1); + assertEqual(string("$1.00"), x1.to_string()); + x1 /= 123.12; + assertEqual(internalAmount("$0.00812216"), x1); + assertEqual(string("$0.01"), x1.to_string()); + x1 /= 123L; + assertEqual(internalAmount("$0.00006603"), x1); + assertEqual(string("$0.00"), x1.to_string()); + + amount_t x6(internalAmount("$237235987235987.98723987235978")); + amount_t x7(internalAmount("$123456789123456789.123456789123456789")); + + assertEqual(amount_t("$1"), x7 / x7); + assertEqual(internalAmount("$0.0019216115121765559608381226612019501046413574469262"), + x6 / x7); + assertEqual(internalAmount("$520.39654928343335571379527154924040947271699678158689736256"), + x7 / x6); + + assertValid(x1); + assertValid(x2); + assertValid(x3); + assertValid(x4); + assertValid(x5); + assertValid(x6); + assertValid(x7); } -void BasicAmountTestCase::testNegation() +void AmountTestCase::testNegation() { amount_t x0; amount_t x1(-123456L); @@ -450,18 +869,73 @@ void BasicAmountTestCase::testNegation() assertEqual(x3, x10); - CPPUNIT_ASSERT(x0.valid()); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(x3.valid()); - CPPUNIT_ASSERT(x5.valid()); - CPPUNIT_ASSERT(x6.valid()); - CPPUNIT_ASSERT(x7.valid()); - CPPUNIT_ASSERT(x8.valid()); - CPPUNIT_ASSERT(x9.valid()); - CPPUNIT_ASSERT(x10.valid()); + assertTrue(x0.valid()); + assertTrue(x1.valid()); + assertTrue(x3.valid()); + assertTrue(x5.valid()); + assertTrue(x6.valid()); + assertTrue(x7.valid()); + assertTrue(x8.valid()); + assertTrue(x9.valid()); + assertTrue(x10.valid()); +} + +void AmountTestCase::testCommodityNegation() +{ + amount_t x1("$123.45"); + amount_t x2("-$123.45"); + amount_t x3("$-123.45"); + amount_t x4("DM 123.45"); + amount_t x5("-DM 123.45"); + amount_t x6("DM -123.45"); + amount_t x7("123.45 euro"); + amount_t x8("-123.45 euro"); + amount_t x9("123.45€"); + amount_t x10("-123.45€"); + + assertEqual(amount_t("$-123.45"), - x1); + assertEqual(amount_t("$123.45"), - x2); + assertEqual(amount_t("$123.45"), - x3); + assertEqual(amount_t("DM -123.45"), - x4); + assertEqual(amount_t("DM 123.45"), - x5); + assertEqual(amount_t("DM 123.45"), - x6); + assertEqual(amount_t("-123.45 euro"), - x7); + assertEqual(amount_t("123.45 euro"), - x8); + assertEqual(amount_t("-123.45€"), - x9); + assertEqual(amount_t("123.45€"), - x10); + + assertEqual(amount_t("$-123.45"), x1.negate()); + assertEqual(amount_t("$123.45"), x2.negate()); + assertEqual(amount_t("$123.45"), x3.negate()); + + assertEqual(string("$-123.45"), (- x1).to_string()); + assertEqual(string("$123.45"), (- x2).to_string()); + assertEqual(string("$123.45"), (- x3).to_string()); + assertEqual(string("DM -123.45"), (- x4).to_string()); + assertEqual(string("DM 123.45"), (- x5).to_string()); + assertEqual(string("DM 123.45"), (- x6).to_string()); + assertEqual(string("-123.45 euro"), (- x7).to_string()); + assertEqual(string("123.45 euro"), (- x8).to_string()); + assertEqual(string("-123.45€"), (- x9).to_string()); + assertEqual(string("123.45€"), (- x10).to_string()); + + assertEqual(amount_t("$-123.45"), x1.negate()); + assertEqual(amount_t("$123.45"), x2.negate()); + assertEqual(amount_t("$123.45"), x3.negate()); + + assertValid(x1); + assertValid(x2); + assertValid(x3); + assertValid(x4); + assertValid(x5); + assertValid(x6); + assertValid(x7); + assertValid(x8); + assertValid(x9); + assertValid(x10); } -void BasicAmountTestCase::testAbs() +void AmountTestCase::testAbs() { amount_t x0; amount_t x1(-1234L); @@ -471,654 +945,82 @@ void BasicAmountTestCase::testAbs() assertEqual(amount_t(1234L), x1.abs()); assertEqual(amount_t(1234L), x2.abs()); - CPPUNIT_ASSERT(x0.valid()); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(x2.valid()); + assertTrue(x0.valid()); + assertTrue(x1.valid()); + assertTrue(x2.valid()); } -void BasicAmountTestCase::testFractionalRound() +void AmountTestCase::testCommodityAbs() { - amount_t x1("1234.567890"); + amount_t x0; + amount_t x1("$-1234.56"); + amount_t x2("$1234.56"); - assertEqual(amount_t("1234.56789"), x1.round(6)); - assertEqual(amount_t("1234.56789"), x1.round(5)); - assertEqual(amount_t("1234.5679"), x1.round(4)); - assertEqual(amount_t("1234.568"), x1.round(3)); - assertEqual(amount_t("1234.57"), x1.round(2)); - assertEqual(amount_t("1234.6"), x1.round(1)); - assertEqual(amount_t("1235"), x1.round(0)); - - amount_t x2("9876.543210"); - - assertEqual(amount_t("9876.543210"), x2.round(6)); - assertEqual(amount_t("9876.54321"), x2.round(5)); - assertEqual(amount_t("9876.5432"), x2.round(4)); - assertEqual(amount_t("9876.543"), x2.round(3)); - assertEqual(amount_t("9876.54"), x2.round(2)); - assertEqual(amount_t("9876.5"), x2.round(1)); - assertEqual(amount_t("9877"), x2.round(0)); - - amount_t x3("-1234.567890"); - - assertEqual(amount_t("-1234.56789"), x3.round(6)); - assertEqual(amount_t("-1234.56789"), x3.round(5)); - assertEqual(amount_t("-1234.5679"), x3.round(4)); - assertEqual(amount_t("-1234.568"), x3.round(3)); - assertEqual(amount_t("-1234.57"), x3.round(2)); - assertEqual(amount_t("-1234.6"), x3.round(1)); - assertEqual(amount_t("-1235"), x3.round(0)); - - amount_t x4("-9876.543210"); - - assertEqual(amount_t("-9876.543210"), x4.round(6)); - assertEqual(amount_t("-9876.54321"), x4.round(5)); - assertEqual(amount_t("-9876.5432"), x4.round(4)); - assertEqual(amount_t("-9876.543"), x4.round(3)); - assertEqual(amount_t("-9876.54"), x4.round(2)); - assertEqual(amount_t("-9876.5"), x4.round(1)); - assertEqual(amount_t("-9877"), x4.round(0)); - - amount_t x5("0.0000000000000000000000000000000000001"); - - assertEqual(amount_t("0.0000000000000000000000000000000000001"), - x5.round(37)); - assertEqual(amount_t(), x5.round(36)); - - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(x2.valid()); - CPPUNIT_ASSERT(x3.valid()); - CPPUNIT_ASSERT(x4.valid()); -} - -void BasicAmountTestCase::testReduction() -{ - amount_t x1("60s"); - amount_t x2("600s"); - amount_t x3("6000s"); - amount_t x4("360000s"); - amount_t x5("10m"); // 600s - amount_t x6("100m"); // 6000s - amount_t x7("1000m"); // 60000s - amount_t x8("10000m"); // 600000s - amount_t x9("10h"); // 36000s - amount_t x10("100h"); // 360000s - amount_t x11("1000h"); // 3600000s - amount_t x12("10000h"); // 36000000s - - assertEqual(x2, x5); - assertEqual(x3, x6); - assertEqual(x4, x10); -} - -void BasicAmountTestCase::testSign() -{ - amount_t x0; - amount_t x1("0.0000000000000000000000000000000000001"); - amount_t x2("-0.0000000000000000000000000000000000001"); - amount_t x3("1"); - amount_t x4("-1"); - - CPPUNIT_ASSERT(! x0.sign()); - CPPUNIT_ASSERT(x1.sign() > 0); - CPPUNIT_ASSERT(x2.sign() < 0); - CPPUNIT_ASSERT(x3.sign() > 0); - CPPUNIT_ASSERT(x4.sign() < 0); - - CPPUNIT_ASSERT(x0.valid()); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(x2.valid()); - CPPUNIT_ASSERT(x3.valid()); - CPPUNIT_ASSERT(x4.valid()); -} - -void BasicAmountTestCase::testTruth() -{ - amount_t x0; - amount_t x1("1234"); - amount_t x2("1234.56"); - - if (x0) - CPPUNIT_ASSERT(false); - else - CPPUNIT_ASSERT(true); - - if (x1) - CPPUNIT_ASSERT(true); - else - CPPUNIT_ASSERT(false); - - if (x2) - CPPUNIT_ASSERT(true); - else - CPPUNIT_ASSERT(false); - - CPPUNIT_ASSERT(x0.valid()); - CPPUNIT_ASSERT(x1.valid()); - CPPUNIT_ASSERT(x2.valid()); -} - -void BasicAmountTestCase::testForZero() -{ - amount_t x0; - amount_t x1("0.000000000000000000001"); - - CPPUNIT_ASSERT(! x0); - CPPUNIT_ASSERT(x1); - CPPUNIT_ASSERT(x0.is_zero()); - CPPUNIT_ASSERT(x0.is_realzero()); - CPPUNIT_ASSERT(! x1.is_zero()); - CPPUNIT_ASSERT(! x1.is_realzero()); - - CPPUNIT_ASSERT(x0.valid()); - CPPUNIT_ASSERT(x1.valid()); -} - -void BasicAmountTestCase::testIntegerConversion() -{ - amount_t x1(123456L); - - assertEqual(true, bool(x1)); - assertEqual(123456L, x1.to_long()); - assertEqual(123456.0, x1.to_double()); - assertEqual(string("123456"), x1.to_string()); - assertEqual(string("123456"), x1.quantity_string()); - - CPPUNIT_ASSERT(x1.valid()); -} - -void BasicAmountTestCase::testFractionalConversion() -{ - amount_t x1(1234.56); - - assertEqual(true, bool(x1)); - assertThrow(x1.to_long(), amount_error); // loses precision - assertEqual(1234L, x1.to_long(true)); - assertEqual(1234.56, x1.to_double()); - assertEqual(string("1234.56"), x1.to_string()); - assertEqual(string("1234.56"), x1.quantity_string()); - - CPPUNIT_ASSERT(x1.valid()); -} - -void BasicAmountTestCase::testPrinting() -{ - amount_t x0; - amount_t x1("982340823.380238098235098235098235098"); - - { - std::ostringstream bufstr; - bufstr << x0; - - assertEqual(std::string("0"), bufstr.str()); - } - - { - std::ostringstream bufstr; - bufstr << x1; - - assertEqual(std::string("982340823.380238098235098235098235098"), - bufstr.str()); - } - - CPPUNIT_ASSERT(x0.valid()); - CPPUNIT_ASSERT(x1.valid()); -} - -void BasicAmountTestCase::testCommodityConstructors() -{ - amount_t x1("$123.45"); - amount_t x2("-$123.45"); - amount_t x3("$-123.45"); - amount_t x4("DM 123.45"); - amount_t x5("-DM 123.45"); - amount_t x6("DM -123.45"); - amount_t x7("123.45 euro"); - amount_t x8("-123.45 euro"); - amount_t x9("123.45€"); - amount_t x10("-123.45€"); - - assertEqual(amount_t("$123.45"), x1); - assertEqual(amount_t("-$123.45"), x2); - assertEqual(amount_t("$-123.45"), x3); - assertEqual(amount_t("DM 123.45"), x4); - assertEqual(amount_t("-DM 123.45"), x5); - assertEqual(amount_t("DM -123.45"), x6); - assertEqual(amount_t("123.45 euro"), x7); - assertEqual(amount_t("-123.45 euro"), x8); - assertEqual(amount_t("123.45€"), x9); - assertEqual(amount_t("-123.45€"), x10); - - assertEqual(string("$123.45"), x1.to_string()); - assertEqual(string("$-123.45"), x2.to_string()); - assertEqual(string("$-123.45"), x3.to_string()); - assertEqual(string("DM 123.45"), x4.to_string()); - assertEqual(string("DM -123.45"), x5.to_string()); - assertEqual(string("DM -123.45"), x6.to_string()); - assertEqual(string("123.45 euro"), x7.to_string()); - assertEqual(string("-123.45 euro"), x8.to_string()); - assertEqual(string("123.45€"), x9.to_string()); - assertEqual(string("-123.45€"), x10.to_string()); - - assertValid(x1); - assertValid(x2); - assertValid(x3); - assertValid(x4); - assertValid(x5); - assertValid(x6); - assertValid(x7); - assertValid(x8); - assertValid(x9); - assertValid(x10); -} - -void BasicAmountTestCase::testCommodityNegation() -{ - amount_t x1("$123.45"); - amount_t x2("-$123.45"); - amount_t x3("$-123.45"); - amount_t x4("DM 123.45"); - amount_t x5("-DM 123.45"); - amount_t x6("DM -123.45"); - amount_t x7("123.45 euro"); - amount_t x8("-123.45 euro"); - amount_t x9("123.45€"); - amount_t x10("-123.45€"); - - assertEqual(amount_t("$-123.45"), - x1); - assertEqual(amount_t("$123.45"), - x2); - assertEqual(amount_t("$123.45"), - x3); - assertEqual(amount_t("DM -123.45"), - x4); - assertEqual(amount_t("DM 123.45"), - x5); - assertEqual(amount_t("DM 123.45"), - x6); - assertEqual(amount_t("-123.45 euro"), - x7); - assertEqual(amount_t("123.45 euro"), - x8); - assertEqual(amount_t("-123.45€"), - x9); - assertEqual(amount_t("123.45€"), - x10); - - assertEqual(amount_t("$-123.45"), x1.negate()); - assertEqual(amount_t("$123.45"), x2.negate()); - assertEqual(amount_t("$123.45"), x3.negate()); - - assertEqual(string("$-123.45"), (- x1).to_string()); - assertEqual(string("$123.45"), (- x2).to_string()); - assertEqual(string("$123.45"), (- x3).to_string()); - assertEqual(string("DM -123.45"), (- x4).to_string()); - assertEqual(string("DM 123.45"), (- x5).to_string()); - assertEqual(string("DM 123.45"), (- x6).to_string()); - assertEqual(string("-123.45 euro"), (- x7).to_string()); - assertEqual(string("123.45 euro"), (- x8).to_string()); - assertEqual(string("-123.45€"), (- x9).to_string()); - assertEqual(string("123.45€"), (- x10).to_string()); - - assertEqual(amount_t("$-123.45"), x1.negate()); - assertEqual(amount_t("$123.45"), x2.negate()); - assertEqual(amount_t("$123.45"), x3.negate()); - - assertValid(x1); - assertValid(x2); - assertValid(x3); - assertValid(x4); - assertValid(x5); - assertValid(x6); - assertValid(x7); - assertValid(x8); - assertValid(x9); - assertValid(x10); -} - -void BasicAmountTestCase::testCommodityAssignment() -{ - amount_t x1 = "$123.45"; - amount_t x2 = "-$123.45"; - amount_t x3 = "$-123.45"; - amount_t x4 = "DM 123.45"; - amount_t x5 = "-DM 123.45"; - amount_t x6 = "DM -123.45"; - amount_t x7 = "123.45 euro"; - amount_t x8 = "-123.45 euro"; - amount_t x9 = "123.45€"; - amount_t x10 = "-123.45€"; - - assertEqual(amount_t("$123.45"), x1); - assertEqual(amount_t("-$123.45"), x2); - assertEqual(amount_t("$-123.45"), x3); - assertEqual(amount_t("DM 123.45"), x4); - assertEqual(amount_t("-DM 123.45"), x5); - assertEqual(amount_t("DM -123.45"), x6); - assertEqual(amount_t("123.45 euro"), x7); - assertEqual(amount_t("-123.45 euro"), x8); - assertEqual(amount_t("123.45€"), x9); - assertEqual(amount_t("-123.45€"), x10); - - assertEqual(string("$123.45"), x1.to_string()); - assertEqual(string("$-123.45"), x2.to_string()); - assertEqual(string("$-123.45"), x3.to_string()); - assertEqual(string("DM 123.45"), x4.to_string()); - assertEqual(string("DM -123.45"), x5.to_string()); - assertEqual(string("DM -123.45"), x6.to_string()); - assertEqual(string("123.45 euro"), x7.to_string()); - assertEqual(string("-123.45 euro"), x8.to_string()); - assertEqual(string("123.45€"), x9.to_string()); - assertEqual(string("-123.45€"), x10.to_string()); - - assertValid(x1); - assertValid(x2); - assertValid(x3); - assertValid(x4); - assertValid(x5); - assertValid(x6); - assertValid(x7); - assertValid(x8); - assertValid(x9); - assertValid(x10); -} - -void BasicAmountTestCase::testCommodityEquality() -{ - amount_t x0; - amount_t x1 = "$123.45"; - amount_t x2 = "-$123.45"; - amount_t x3 = "$-123.45"; - amount_t x4 = "DM 123.45"; - amount_t x5 = "-DM 123.45"; - amount_t x6 = "DM -123.45"; - amount_t x7 = "123.45 euro"; - amount_t x8 = "-123.45 euro"; - amount_t x9 = "123.45€"; - amount_t x10 = "-123.45€"; - - assertTrue(x0.is_null()); - assertTrue(x0.is_zero()); - assertTrue(x0.is_realzero()); - assertTrue(x0.sign() == 0); - assertTrue(x0.compare(x1) < 0); - assertTrue(x0.compare(x2) > 0); - assertTrue(x0.compare(x0) == 0); - - assertTrue(x1 != x2); - assertTrue(x1 != x4); - assertTrue(x1 != x7); - assertTrue(x1 != x9); - assertTrue(x2 == x3); - assertTrue(x4 != x5); - assertTrue(x5 == x6); - assertTrue(x7 == - x8); - assertTrue(x9 == - x10); + assertEqual(amount_t(), x0.abs()); + assertEqual(amount_t("$1234.56"), x1.abs()); + assertEqual(amount_t("$1234.56"), x2.abs()); assertValid(x0); assertValid(x1); assertValid(x2); - assertValid(x3); - assertValid(x4); - assertValid(x5); - assertValid(x6); - assertValid(x7); - assertValid(x8); - assertValid(x9); - assertValid(x10); -} - -void BasicAmountTestCase::testCommodityAddition() -{ - amount_t x0; - amount_t x1("$123.45"); - amount_t x2(internalAmount("$123.456789")); - amount_t x3("DM 123.45"); - amount_t x4("123.45 euro"); - amount_t x5("123.45€"); - amount_t x6("123.45"); - - assertEqual(amount_t("$246.90"), x1 + x1); - assertNotEqual(amount_t("$246.91"), x1 + x2); - assertEqual(internalAmount("$246.906789"), x1 + x2); - - // Converting to string drops internal precision - assertEqual(string("$246.90"), (x1 + x1).to_string()); - assertEqual(string("$246.91"), (x1 + x2).to_string()); - - assertThrow(x1 + x0, amount_error); - assertThrow(x1 + x3, amount_error); - assertThrow(x1 + x4, amount_error); - assertThrow(x1 + x5, amount_error); - assertThrow(x1 + x6, amount_error); - assertThrow(x1 + 123.45, amount_error); - assertThrow(x1 + 123L, amount_error); - - assertEqual(amount_t("DM 246.90"), x3 + x3); - assertEqual(amount_t("246.90 euro"), x4 + x4); - assertEqual(amount_t("246.90€"), x5 + x5); - - assertEqual(string("DM 246.90"), (x3 + x3).to_string()); - assertEqual(string("246.90 euro"), (x4 + x4).to_string()); - assertEqual(string("246.90€"), (x5 + x5).to_string()); - - x1 += amount_t("$456.45"); - assertEqual(amount_t("$579.90"), x1); - x1 += amount_t("$456.45"); - assertEqual(amount_t("$1036.35"), x1); - x1 += amount_t("$456"); - assertEqual(amount_t("$1492.35"), x1); - - amount_t x7(internalAmount("$123456789123456789.123456789123456789")); - - assertEqual(internalAmount("$246913578246913578.246913578246913578"), x7 + x7); - - assertValid(x1); - assertValid(x2); - assertValid(x3); - assertValid(x4); - assertValid(x5); - assertValid(x6); - assertValid(x7); -} - -void BasicAmountTestCase::testCommoditySubtraction() -{ - amount_t x0; - amount_t x1("$123.45"); - amount_t x2(internalAmount("$123.456789")); - amount_t x3("DM 123.45"); - amount_t x4("123.45 euro"); - amount_t x5("123.45€"); - amount_t x6("123.45"); - - assertNotEqual(amount_t(), x1 - x1); - assertEqual(amount_t("$0"), x1 - x1); - assertEqual(amount_t("$23.45"), x1 - amount_t("$100.00")); - assertEqual(amount_t("$-23.45"), amount_t("$100.00") - x1); - assertNotEqual(amount_t("$-0.01"), x1 - x2); - assertEqual(internalAmount("$-0.006789"), x1 - x2); - - // Converting to string drops internal precision. If an amount is - // zero, it drops the commodity as well. - assertEqual(string("$0.00"), (x1 - x1).to_string()); - assertEqual(string("$-0.01"), (x1 - x2).to_string()); - - assertThrow(x1 - x0, amount_error); - assertThrow(x1 - x3, amount_error); - assertThrow(x1 - x4, amount_error); - assertThrow(x1 - x5, amount_error); - assertThrow(x1 - x6, amount_error); - assertThrow(x1 - 123.45, amount_error); - assertThrow(x1 - 123L, amount_error); - - assertEqual(amount_t("DM 0.00"), x3 - x3); - assertEqual(amount_t("DM 23.45"), x3 - amount_t("DM 100.00")); - assertEqual(amount_t("DM -23.45"), amount_t("DM 100.00") - x3); - assertEqual(amount_t("0.00 euro"), x4 - x4); - assertEqual(amount_t("23.45 euro"), x4 - amount_t("100.00 euro")); - assertEqual(amount_t("-23.45 euro"), amount_t("100.00 euro") - x4); - assertEqual(amount_t("0.00€"), x5 - x5); - assertEqual(amount_t("23.45€"), x5 - amount_t("100.00€")); - assertEqual(amount_t("-23.45€"), amount_t("100.00€") - x5); - - assertEqual(string("DM 0.00"), (x3 - x3).to_string()); - assertEqual(string("DM 23.45"), (x3 - amount_t("DM 100.00")).to_string()); - assertEqual(string("DM -23.45"), (amount_t("DM 100.00") - x3).to_string()); - assertEqual(string("0.00 euro"), (x4 - x4).to_string()); - assertEqual(string("23.45 euro"), (x4 - amount_t("100.00 euro")).to_string()); - assertEqual(string("-23.45 euro"), (amount_t("100.00 euro") - x4).to_string()); - assertEqual(string("0.00€"), (x5 - x5).to_string()); - assertEqual(string("23.45€"), (x5 - amount_t("100.00€")).to_string()); - assertEqual(string("-23.45€"), (amount_t("100.00€") - x5).to_string()); - - x1 -= amount_t("$456.45"); - assertEqual(amount_t("$-333.00"), x1); - x1 -= amount_t("$456.45"); - assertEqual(amount_t("$-789.45"), x1); - x1 -= amount_t("$456"); - assertEqual(amount_t("$-1245.45"), x1); - - amount_t x7(internalAmount("$123456789123456789.123456789123456789")); - amount_t x8(internalAmount("$2354974984698.98459845984598")); - - assertEqual(internalAmount("$123454434148472090.138858329277476789"), x7 - x8); - assertEqual(string("$123454434148472090.138858329277476789"), (x7 - x8).to_string()); - assertEqual(string("$123454434148472090.14"), - (amount_t("$1.00") * (x7 - x8)).to_string()); - assertEqual(internalAmount("$-123454434148472090.138858329277476789"), x8 - x7); - assertEqual(string("$-123454434148472090.138858329277476789"), (x8 - x7).to_string()); - assertEqual(string("$-123454434148472090.14"), - (amount_t("$1.00") * (x8 - x7)).to_string()); - - assertValid(x1); - assertValid(x2); - assertValid(x3); - assertValid(x4); - assertValid(x5); - assertValid(x6); - assertValid(x7); - assertValid(x8); -} - -void BasicAmountTestCase::testCommodityMultiplication() -{ - amount_t x1("$123.12"); - amount_t y1("$456.45"); - amount_t x2(internalAmount("$123.456789")); - amount_t x3("DM 123.45"); - amount_t x4("123.45 euro"); - amount_t x5("123.45€"); - - assertEqual(amount_t("$0.00"), x1 * 0L); - assertEqual(amount_t("$0.00"), 0L * x1); - assertEqual(x1, x1 * 1L); - assertEqual(x1, 1L * x1); - assertEqual(- x1, x1 * -1L); - assertEqual(- x1, -1L * x1); - assertEqual(internalAmount("$56198.124"), x1 * y1); - assertEqual(string("$56198.12"), (x1 * y1).to_string()); - assertEqual(internalAmount("$56198.124"), y1 * x1); - assertEqual(string("$56198.12"), (y1 * x1).to_string()); - - // Internal amounts retain their precision, even when being - // converted to strings - assertEqual(internalAmount("$15199.99986168"), x1 * x2); - assertEqual(internalAmount("$15199.99986168"), x2 * x1); - assertEqual(string("$15200.00"), (x1 * x2).to_string()); - assertEqual(string("$15199.99986168"), (x2 * x1).to_string()); - - assertThrow(x1 * x3, amount_error); - assertThrow(x1 * x4, amount_error); - assertThrow(x1 * x5, amount_error); - - x1 *= amount_t("123.12"); - assertEqual(internalAmount("$15158.5344"), x1); - assertEqual(string("$15158.53"), x1.to_string()); - x1 *= 123.12; - assertEqual(internalAmount("$1866318.755328"), x1); - assertEqual(string("$1866318.76"), x1.to_string()); - x1 *= 123L; - assertEqual(internalAmount("$229557206.905344"), x1); - assertEqual(string("$229557206.91"), x1.to_string()); - - amount_t x7(internalAmount("$123456789123456789.123456789123456789")); - - assertEqual(internalAmount("$15241578780673678546105778311537878.046486820281054720515622620750190521"), - x7 * x7); - - assertValid(x1); - assertValid(x2); - assertValid(x3); - assertValid(x4); - assertValid(x5); - assertValid(x7); } -void BasicAmountTestCase::testCommodityDivision() +void AmountTestCase::testFractionalRound() { - amount_t x1("$123.12"); - amount_t y1("$456.45"); - amount_t x2(internalAmount("$123.456789")); - amount_t x3("DM 123.45"); - amount_t x4("123.45 euro"); - amount_t x5("123.45€"); + amount_t x1("1234.567890"); - assertThrow(x1 / 0L, amount_error); - assertEqual(amount_t("$0.00"), 0L / x1); - assertEqual(x1, x1 / 1L); - assertEqual(internalAmount("$0.00812216"), 1L / x1); - assertEqual(- x1, x1 / -1L); - assertEqual(internalAmount("$-0.00812216"), -1L / x1); - assertEqual(internalAmount("$0.26973382"), x1 / y1); - assertEqual(string("$0.27"), (x1 / y1).to_string()); - assertEqual(internalAmount("$3.70735867"), y1 / x1); - assertEqual(string("$3.71"), (y1 / x1).to_string()); + assertEqual(amount_t("1234.56789"), x1.round(6)); + assertEqual(amount_t("1234.56789"), x1.round(5)); + assertEqual(amount_t("1234.5679"), x1.round(4)); + assertEqual(amount_t("1234.568"), x1.round(3)); + assertEqual(amount_t("1234.57"), x1.round(2)); + assertEqual(amount_t("1234.6"), x1.round(1)); + assertEqual(amount_t("1235"), x1.round(0)); - // Internal amounts retain their precision, even when being - // converted to strings - assertEqual(internalAmount("$0.99727201"), x1 / x2); - assertEqual(internalAmount("$1.00273545321637426901"), x2 / x1); - assertEqual(string("$1.00"), (x1 / x2).to_string()); - assertEqual(string("$1.00273545321637426901"), (x2 / x1).to_string()); + amount_t x2("9876.543210"); - assertThrow(x1 / x3, amount_error); - assertThrow(x1 / x4, amount_error); - assertThrow(x1 / x5, amount_error); + assertEqual(amount_t("9876.543210"), x2.round(6)); + assertEqual(amount_t("9876.54321"), x2.round(5)); + assertEqual(amount_t("9876.5432"), x2.round(4)); + assertEqual(amount_t("9876.543"), x2.round(3)); + assertEqual(amount_t("9876.54"), x2.round(2)); + assertEqual(amount_t("9876.5"), x2.round(1)); + assertEqual(amount_t("9877"), x2.round(0)); - x1 /= amount_t("123.12"); - assertEqual(internalAmount("$1.00"), x1); - assertEqual(string("$1.00"), x1.to_string()); - x1 /= 123.12; - assertEqual(internalAmount("$0.00812216"), x1); - assertEqual(string("$0.01"), x1.to_string()); - x1 /= 123L; - assertEqual(internalAmount("$0.00006603"), x1); - assertEqual(string("$0.00"), x1.to_string()); + amount_t x3("-1234.567890"); - amount_t x6(internalAmount("$237235987235987.98723987235978")); - amount_t x7(internalAmount("$123456789123456789.123456789123456789")); + assertEqual(amount_t("-1234.56789"), x3.round(6)); + assertEqual(amount_t("-1234.56789"), x3.round(5)); + assertEqual(amount_t("-1234.5679"), x3.round(4)); + assertEqual(amount_t("-1234.568"), x3.round(3)); + assertEqual(amount_t("-1234.57"), x3.round(2)); + assertEqual(amount_t("-1234.6"), x3.round(1)); + assertEqual(amount_t("-1235"), x3.round(0)); - assertEqual(amount_t("$1"), x7 / x7); - assertEqual(internalAmount("$0.0019216115121765559608381226612019501046413574469262"), - x6 / x7); - assertEqual(internalAmount("$520.39654928343335571379527154924040947271699678158689736256"), - x7 / x6); + amount_t x4("-9876.543210"); - assertValid(x1); - assertValid(x2); - assertValid(x3); - assertValid(x4); - assertValid(x5); - assertValid(x6); - assertValid(x7); -} + assertEqual(amount_t("-9876.543210"), x4.round(6)); + assertEqual(amount_t("-9876.54321"), x4.round(5)); + assertEqual(amount_t("-9876.5432"), x4.round(4)); + assertEqual(amount_t("-9876.543"), x4.round(3)); + assertEqual(amount_t("-9876.54"), x4.round(2)); + assertEqual(amount_t("-9876.5"), x4.round(1)); + assertEqual(amount_t("-9877"), x4.round(0)); -void BasicAmountTestCase::testCommodityConversion() -{ - amount_t x1("$1234.56"); + amount_t x5("0.0000000000000000000000000000000000001"); - assertEqual(true, bool(x1)); - assertThrow(x1.to_long(), amount_error); // loses precision - assertEqual(1234L, x1.to_long(true)); - assertEqual(1234.56, x1.to_double()); - assertEqual(string("$1234.56"), x1.to_string()); - assertEqual(string("1234.56"), x1.quantity_string()); + assertEqual(amount_t("0.0000000000000000000000000000000000001"), + x5.round(37)); + assertEqual(amount_t(), x5.round(36)); - assertValid(x1); + assertTrue(x1.valid()); + assertTrue(x2.valid()); + assertTrue(x3.valid()); + assertTrue(x4.valid()); + assertTrue(x5.valid()); } -void BasicAmountTestCase::testCommodityRound() +void AmountTestCase::testCommodityRound() { amount_t x1(internalAmount("$1234.567890")); @@ -1176,7 +1078,7 @@ void BasicAmountTestCase::testCommodityRound() assertValid(x5); } -void BasicAmountTestCase::testCommodityDisplayRound() +void AmountTestCase::testCommodityDisplayRound() { amount_t x1("$0.85"); amount_t x2("$0.1"); @@ -1198,26 +1100,123 @@ void BasicAmountTestCase::testCommodityDisplayRound() assertEqual(string("$1.13"), x1.to_string()); } -void BasicAmountTestCase::testCommodityTruth() +void AmountTestCase::testReduction() +{ + amount_t x1("60s"); + amount_t x2("600s"); + amount_t x3("6000s"); + amount_t x4("360000s"); + amount_t x5("10m"); // 600s + amount_t x6("100m"); // 6000s + amount_t x7("1000m"); // 60000s + amount_t x8("10000m"); // 600000s + amount_t x9("10h"); // 36000s + amount_t x10("100h"); // 360000s + amount_t x11("1000h"); // 3600000s + amount_t x12("10000h"); // 36000000s + + assertEqual(x2, x5); + assertEqual(x3, x6); + assertEqual(x4, x10); +} + +void AmountTestCase::testSign() +{ + amount_t x0; + amount_t x1("0.0000000000000000000000000000000000001"); + amount_t x2("-0.0000000000000000000000000000000000001"); + amount_t x3("1"); + amount_t x4("-1"); + + assertEqual(x0.sign(), 0); + assertTrue(x1.sign() > 0); + assertTrue(x2.sign() < 0); + assertTrue(x3.sign() > 0); + assertTrue(x4.sign() < 0); + + assertTrue(x0.valid()); + assertTrue(x1.valid()); + assertTrue(x2.valid()); + assertTrue(x3.valid()); + assertTrue(x4.valid()); +} + +void AmountTestCase::testCommoditySign() +{ + amount_t x0; + amount_t x1(internalAmount("$0.0000000000000000000000000000000000001")); + amount_t x2(internalAmount("$-0.0000000000000000000000000000000000001")); + amount_t x3("$1"); + amount_t x4("$-1"); + + assertFalse(x0.sign()); + assertTrue(x1.sign() != 0); + assertTrue(x2.sign() != 0); + assertTrue(x3.sign() > 0); + assertTrue(x4.sign() < 0); + + assertValid(x0); + assertValid(x1); + assertValid(x2); + assertValid(x3); + assertValid(x4); +} + +void AmountTestCase::testTruth() +{ + amount_t x0; + amount_t x1("1234"); + amount_t x2("1234.56"); + + if (x0) + assertTrue(false); + else + assertTrue(true); + + assertTrue(x1); + assertTrue(x2); + + assertTrue(x0.valid()); + assertTrue(x1.valid()); + assertTrue(x2.valid()); +} + +void AmountTestCase::testCommodityTruth() { amount_t x1("$1234"); amount_t x2("$1234.56"); if (x1) - CPPUNIT_ASSERT(true); + assertTrue(true); else - CPPUNIT_ASSERT(false); + assertTrue(false); if (x2) - CPPUNIT_ASSERT(true); + assertTrue(true); else - CPPUNIT_ASSERT(false); + assertTrue(false); assertValid(x1); assertValid(x2); } -void BasicAmountTestCase::testCommodityForZero() +void AmountTestCase::testForZero() +{ + amount_t x0; + amount_t x1("0.000000000000000000001"); + + assertFalse(x0); + assertTrue(x1); + assertTrue(x0.is_zero()); + assertTrue(x0.is_realzero()); + assertFalse(x1.is_zero()); + assertFalse(x1.is_realzero()); + + assertTrue(x0.valid()); + assertTrue(x1.valid()); +} + +void AmountTestCase::testCommodityForZero() { amount_t x1(internalAmount("$0.000000000000000000001")); @@ -1228,77 +1227,69 @@ void BasicAmountTestCase::testCommodityForZero() assertValid(x1); } -void BasicAmountTestCase::testCommodityComparisons() +void AmountTestCase::testIntegerConversion() { - amount_t x0; - amount_t x1("$-123"); - amount_t x2("$123.00"); - amount_t x3(internalAmount("$-123.4544")); - amount_t x4(internalAmount("$123.4544")); - amount_t x5("$-123.45"); - amount_t x6("$123.45"); + amount_t x1(123456L); - assertTrue(x0 > x1); - assertTrue(x0 < x2); - assertTrue(x0 > x3); - assertTrue(x0 < x4); - assertTrue(x0 > x5); - assertTrue(x0 < x6); + assertEqual(123456L, x1.to_long()); + assertEqual(123456.0, x1.to_double()); + assertEqual(string("123456"), x1.to_string()); + assertEqual(string("123456"), x1.quantity_string()); - assertTrue(x1 > x3); - assertTrue(x3 <= x5); - assertTrue(x3 < x5); - assertTrue(x3 <= x5); - assertFalse(x3 == x5); - assertTrue(x3 < x1); - assertTrue(x3 < x4); + assertTrue(x1.valid()); +} - assertValid(x0); - assertValid(x1); - assertValid(x2); - assertValid(x3); - assertValid(x4); - assertValid(x5); - assertValid(x6); +void AmountTestCase::testFractionalConversion() +{ + amount_t x1(1234.56); + + assertThrow(x1.to_long(), amount_error); // loses precision + assertEqual(1234L, x1.to_long(true)); + assertEqual(1234.56, x1.to_double()); + assertEqual(string("1234.56"), x1.to_string()); + assertEqual(string("1234.56"), x1.quantity_string()); + + assertTrue(x1.valid()); } -void BasicAmountTestCase::testCommoditySign() +void AmountTestCase::testCommodityConversion() { - amount_t x0; - amount_t x1(internalAmount("$0.0000000000000000000000000000000000001")); - amount_t x2(internalAmount("$-0.0000000000000000000000000000000000001")); - amount_t x3("$1"); - amount_t x4("$-1"); + amount_t x1("$1234.56"); - assertFalse(x0.sign()); - assertTrue(x1.sign() != 0); - assertTrue(x2.sign() != 0); - assertTrue(x3.sign() > 0); - assertTrue(x4.sign() < 0); + assertThrow(x1.to_long(), amount_error); // loses precision + assertEqual(1234L, x1.to_long(true)); + assertEqual(1234.56, x1.to_double()); + assertEqual(string("$1234.56"), x1.to_string()); + assertEqual(string("1234.56"), x1.quantity_string()); - assertValid(x0); assertValid(x1); - assertValid(x2); - assertValid(x3); - assertValid(x4); } -void BasicAmountTestCase::testCommodityAbs() +void AmountTestCase::testPrinting() { amount_t x0; - amount_t x1("$-1234.56"); - amount_t x2("$1234.56"); + amount_t x1("982340823.380238098235098235098235098"); - assertEqual(amount_t(), x0.abs()); - assertEqual(amount_t("$1234.56"), x1.abs()); - assertEqual(amount_t("$1234.56"), x2.abs()); + { + std::ostringstream bufstr; + bufstr << x0; - assertValid(x0); - assertValid(x1); - assertValid(x2); + assertEqual(std::string("0"), bufstr.str()); + } + + { + std::ostringstream bufstr; + bufstr << x1; + + assertEqual(std::string("982340823.380238098235098235098235098"), + bufstr.str()); + } + + assertTrue(x0.valid()); + assertTrue(x1.valid()); } -void BasicAmountTestCase::testCommodityPrinting() +void AmountTestCase::testCommodityPrinting() { amount_t x0; amount_t x1(internalAmount("$982340823.386238098235098235098235098")); diff --git a/tests/numerics/t_amount.h b/tests/numerics/t_amount.h index ee227a5c..0bf0017f 100644 --- a/tests/numerics/t_amount.h +++ b/tests/numerics/t_amount.h @@ -3,48 +3,48 @@ #include "UnitTests.h" -class BasicAmountTestCase : public CPPUNIT_NS::TestCase +class AmountTestCase : public CPPUNIT_NS::TestCase { - CPPUNIT_TEST_SUITE(BasicAmountTestCase); + CPPUNIT_TEST_SUITE(AmountTestCase); CPPUNIT_TEST(testConstructors); + CPPUNIT_TEST(testCommodityConstructors); CPPUNIT_TEST(testAssignment); + CPPUNIT_TEST(testCommodityAssignment); CPPUNIT_TEST(testEquality); + CPPUNIT_TEST(testCommodityEquality); CPPUNIT_TEST(testComparisons); + CPPUNIT_TEST(testCommodityComparisons); CPPUNIT_TEST(testIntegerAddition); CPPUNIT_TEST(testFractionalAddition); + CPPUNIT_TEST(testCommodityAddition); CPPUNIT_TEST(testIntegerSubtraction); CPPUNIT_TEST(testFractionalSubtraction); + CPPUNIT_TEST(testCommoditySubtraction); CPPUNIT_TEST(testIntegerMultiplication); CPPUNIT_TEST(testFractionalMultiplication); + CPPUNIT_TEST(testCommodityMultiplication); CPPUNIT_TEST(testIntegerDivision); CPPUNIT_TEST(testFractionalDivision); + CPPUNIT_TEST(testCommodityDivision); CPPUNIT_TEST(testNegation); + CPPUNIT_TEST(testCommodityNegation); CPPUNIT_TEST(testAbs); + CPPUNIT_TEST(testCommodityAbs); CPPUNIT_TEST(testFractionalRound); + CPPUNIT_TEST(testCommodityRound); + CPPUNIT_TEST(testCommodityDisplayRound); CPPUNIT_TEST(testReduction); CPPUNIT_TEST(testSign); + CPPUNIT_TEST(testCommoditySign); CPPUNIT_TEST(testTruth); + CPPUNIT_TEST(testCommodityTruth); CPPUNIT_TEST(testForZero); + CPPUNIT_TEST(testCommodityForZero); CPPUNIT_TEST(testIntegerConversion); CPPUNIT_TEST(testFractionalConversion); - CPPUNIT_TEST(testPrinting); - CPPUNIT_TEST(testCommodityConstructors); - CPPUNIT_TEST(testCommodityNegation); - CPPUNIT_TEST(testCommodityAssignment); - CPPUNIT_TEST(testCommodityEquality); - CPPUNIT_TEST(testCommodityAddition); - CPPUNIT_TEST(testCommoditySubtraction); - CPPUNIT_TEST(testCommodityMultiplication); - CPPUNIT_TEST(testCommodityDivision); CPPUNIT_TEST(testCommodityConversion); - CPPUNIT_TEST(testCommodityRound); - CPPUNIT_TEST(testCommodityDisplayRound); - CPPUNIT_TEST(testCommodityTruth); - CPPUNIT_TEST(testCommodityForZero); - CPPUNIT_TEST(testCommodityComparisons); - CPPUNIT_TEST(testCommoditySign); - CPPUNIT_TEST(testCommodityAbs); + CPPUNIT_TEST(testPrinting); CPPUNIT_TEST(testCommodityPrinting); CPPUNIT_TEST_SUITE_END(); @@ -52,55 +52,55 @@ class BasicAmountTestCase : public CPPUNIT_NS::TestCase public: ledger::session_t session; - BasicAmountTestCase() {} - virtual ~BasicAmountTestCase() {} + AmountTestCase() {} + virtual ~AmountTestCase() {} virtual void setUp(); virtual void tearDown(); void testConstructors(); + void testCommodityConstructors(); void testAssignment(); + void testCommodityAssignment(); void testEquality(); + void testCommodityEquality(); void testComparisons(); + void testCommodityComparisons(); void testIntegerAddition(); void testFractionalAddition(); + void testCommodityAddition(); void testIntegerSubtraction(); void testFractionalSubtraction(); + void testCommoditySubtraction(); void testIntegerMultiplication(); void testFractionalMultiplication(); + void testCommodityMultiplication(); void testIntegerDivision(); void testFractionalDivision(); + void testCommodityDivision(); void testNegation(); + void testCommodityNegation(); void testAbs(); + void testCommodityAbs(); void testFractionalRound(); + void testCommodityRound(); + void testCommodityDisplayRound(); void testReduction(); void testSign(); + void testCommoditySign(); void testTruth(); + void testCommodityTruth(); void testForZero(); + void testCommodityForZero(); void testIntegerConversion(); void testFractionalConversion(); - void testPrinting(); - void testCommodityConstructors(); - void testCommodityNegation(); - void testCommodityAssignment(); - void testCommodityEquality(); - void testCommodityAddition(); - void testCommoditySubtraction(); - void testCommodityMultiplication(); - void testCommodityDivision(); void testCommodityConversion(); - void testCommodityRound(); - void testCommodityDisplayRound(); - void testCommodityTruth(); - void testCommodityForZero(); - void testCommodityComparisons(); - void testCommoditySign(); - void testCommodityAbs(); + void testPrinting(); void testCommodityPrinting(); private: - BasicAmountTestCase(const BasicAmountTestCase ©); - void operator=(const BasicAmountTestCase ©); + AmountTestCase(const AmountTestCase ©); + void operator=(const AmountTestCase ©); }; #endif // _T_AMOUNT_H -- cgit v1.2.3