diff options
Diffstat (limited to 'tests/corelib/numerics/BasicAmount.cc')
-rw-r--r-- | tests/corelib/numerics/BasicAmount.cc | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/tests/corelib/numerics/BasicAmount.cc b/tests/corelib/numerics/BasicAmount.cc index 44246c40..16d8b1ea 100644 --- a/tests/corelib/numerics/BasicAmount.cc +++ b/tests/corelib/numerics/BasicAmount.cc @@ -24,6 +24,9 @@ void BasicAmountTestCase::testConstructors() amount_t x11(x8); assertEqual(amount_t(0L), x0); + assertEqual(amount_t(), x0); + assertEqual(amount_t("0"), x0); + assertEqual(amount_t("0.0"), x0); assertEqual(x2, x1); assertEqual(x5, x1); assertEqual(x7, x1); @@ -70,6 +73,16 @@ void BasicAmountTestCase::testNegation() x10.negate(); 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()); } void BasicAmountTestCase::testAssignment() @@ -117,6 +130,18 @@ void BasicAmountTestCase::testAssignment() assertEqual(x10, x3); assertEqual(amount_t(1L), x4); assertEqual(x10, x9); + + 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()); + CPPUNIT_ASSERT(x7.valid()); + CPPUNIT_ASSERT(x8.valid()); + CPPUNIT_ASSERT(x9.valid()); + CPPUNIT_ASSERT(x10.valid()); } void BasicAmountTestCase::testEquality() @@ -134,6 +159,13 @@ void BasicAmountTestCase::testEquality() 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()); } void BasicAmountTestCase::testIntegerAddition() @@ -159,6 +191,12 @@ void BasicAmountTestCase::testIntegerAddition() amount_t x4("123456789123456789123456789"); assertEqual(amount_t("246913578246913578246913578"), x4 + x4); + + CPPUNIT_ASSERT(x1.valid()); + CPPUNIT_ASSERT(y1.valid()); + CPPUNIT_ASSERT(x3.valid()); + CPPUNIT_ASSERT(y3.valid()); + CPPUNIT_ASSERT(x4.valid()); } void BasicAmountTestCase::testFractionalAddition() @@ -180,6 +218,10 @@ void BasicAmountTestCase::testFractionalAddition() amount_t x2("123456789123456789.123456789123456789"); assertEqual(amount_t("246913578246913578.246913578246913578"), x2 + x2); + + CPPUNIT_ASSERT(x1.valid()); + CPPUNIT_ASSERT(y1.valid()); + CPPUNIT_ASSERT(x2.valid()); } void BasicAmountTestCase::testIntegerSubtraction() @@ -207,6 +249,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(x3.valid()); + CPPUNIT_ASSERT(y3.valid()); + CPPUNIT_ASSERT(x4.valid()); + CPPUNIT_ASSERT(y4.valid()); } void BasicAmountTestCase::testFractionalSubtraction() @@ -229,6 +278,11 @@ 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()); } void BasicAmountTestCase::testIntegerMultiplication() @@ -265,6 +319,12 @@ void BasicAmountTestCase::testIntegerMultiplication() assertEqual(amount_t("15241578780673678546105778281054720515622620750190521"), x4 * x4); + + CPPUNIT_ASSERT(x1.valid()); + CPPUNIT_ASSERT(y1.valid()); + CPPUNIT_ASSERT(x3.valid()); + CPPUNIT_ASSERT(y3.valid()); + CPPUNIT_ASSERT(x4.valid()); } void BasicAmountTestCase::testFractionalMultiplication() @@ -298,6 +358,10 @@ void BasicAmountTestCase::testFractionalMultiplication() assertEqual(amount_t("15241578780673678546105778311537878.046486820281054720515622620750190521"), x2 * x2); + + CPPUNIT_ASSERT(x1.valid()); + CPPUNIT_ASSERT(y1.valid()); + CPPUNIT_ASSERT(x2.valid()); } void BasicAmountTestCase::testIntegerDivision() @@ -330,6 +394,11 @@ 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()); } void BasicAmountTestCase::testFractionalDivision() @@ -365,6 +434,11 @@ void BasicAmountTestCase::testFractionalDivision() assertEqual(amount_t(1.0), x4 / x4); assertEqual(amount_t("21739560323910.7554497273748437197344556164"), x4 / y4); + + CPPUNIT_ASSERT(x1.valid()); + CPPUNIT_ASSERT(y1.valid()); + CPPUNIT_ASSERT(x4.valid()); + CPPUNIT_ASSERT(y4.valid()); } void BasicAmountTestCase::testIntegerConversion() @@ -376,6 +450,8 @@ void BasicAmountTestCase::testIntegerConversion() assertEqual(123456.0, double(x1)); assertEqual(std::string("123456"), x1.to_string()); assertEqual(std::string("123456"), x1.quantity_string()); + + CPPUNIT_ASSERT(x1.valid()); } void BasicAmountTestCase::testFractionalConversion() @@ -387,6 +463,8 @@ void BasicAmountTestCase::testFractionalConversion() assertEqual(1234.56, double(x1)); assertEqual(std::string("1234.56"), x1.to_string()); assertEqual(std::string("1234.56"), x1.quantity_string()); + + CPPUNIT_ASSERT(x1.valid()); } void BasicAmountTestCase::testFractionalRound() @@ -430,6 +508,17 @@ void BasicAmountTestCase::testFractionalRound() 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::testTruth() @@ -452,6 +541,10 @@ void BasicAmountTestCase::testTruth() CPPUNIT_ASSERT(true); else CPPUNIT_ASSERT(false); + + CPPUNIT_ASSERT(x0.valid()); + CPPUNIT_ASSERT(x1.valid()); + CPPUNIT_ASSERT(x2.valid()); } void BasicAmountTestCase::testForZero() @@ -465,6 +558,9 @@ void BasicAmountTestCase::testForZero() CPPUNIT_ASSERT(x0.realzero()); CPPUNIT_ASSERT(! x1.zero()); CPPUNIT_ASSERT(! x1.realzero()); + + CPPUNIT_ASSERT(x0.valid()); + CPPUNIT_ASSERT(x1.valid()); } void BasicAmountTestCase::testComparisons() @@ -489,6 +585,14 @@ void BasicAmountTestCase::testComparisons() CPPUNIT_ASSERT(x3 >= x5); CPPUNIT_ASSERT(x3 < x1); CPPUNIT_ASSERT(x3 < x4); + + 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()); } void BasicAmountTestCase::testSign() @@ -504,6 +608,12 @@ void BasicAmountTestCase::testSign() 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::testAbs() @@ -523,6 +633,10 @@ void BasicAmountTestCase::testAbs() assertEqual(amount_t(), x0); assertEqual(amount_t(1234L), x1); assertEqual(amount_t(1234L), x2); + + CPPUNIT_ASSERT(x0.valid()); + CPPUNIT_ASSERT(x1.valid()); + CPPUNIT_ASSERT(x2.valid()); } void BasicAmountTestCase::testPrinting() @@ -544,4 +658,7 @@ void BasicAmountTestCase::testPrinting() assertEqual(std::string("982340823.380238098235098235098235098"), bufstr.str()); } + + CPPUNIT_ASSERT(x0.valid()); + CPPUNIT_ASSERT(x1.valid()); } |