diff options
author | John Wiegley <johnw@newartisans.com> | 2007-05-08 10:33:25 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:38:42 -0400 |
commit | 42d799a1fdde6278fe42be58786937e49fcf1c3f (patch) | |
tree | feebcb9be4b03093e961b083bf90fe05f21b9329 /tests/numerics | |
parent | 4e9056b6ce395531098a72d431b911f4ecbbbaab (diff) | |
download | fork-ledger-42d799a1fdde6278fe42be58786937e49fcf1c3f.tar.gz fork-ledger-42d799a1fdde6278fe42be58786937e49fcf1c3f.tar.bz2 fork-ledger-42d799a1fdde6278fe42be58786937e49fcf1c3f.zip |
Added tests to complete coverage.
Diffstat (limited to 'tests/numerics')
-rw-r--r-- | tests/numerics/t_amount.cc | 72 | ||||
-rw-r--r-- | tests/numerics/t_amount.h | 2 |
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/numerics/t_amount.cc b/tests/numerics/t_amount.cc index 002b70b0..51d7a2f7 100644 --- a/tests/numerics/t_amount.cc +++ b/tests/numerics/t_amount.cc @@ -20,6 +20,71 @@ void AmountTestCase::tearDown() ledger::set_session_context(); } +void AmountTestCase::testParser() +{ + amount_t x0; + amount_t x1; + amount_t x2; + amount_t x3; + amount_t x4(123.456); + amount_t x5(x4); + amount_t x6(x4); + amount_t x7(x4); + amount_t x8("$123.456"); + amount_t x9(x8); + amount_t x10(x8); + amount_t x11(x8); + amount_t x12("$100"); + + assertEqual(amount_t::precision_t(3), x12.commodity().precision()); + + x1.parse("$100.0000", AMOUNT_PARSE_NO_MIGRATE); + assertEqual(amount_t::precision_t(3), x12.commodity().precision()); + assertEqual(x1.commodity(), x12.commodity()); + assertEqual(x1, x12); + + x0.parse("$100.0000"); + assertEqual(amount_t::precision_t(4), x12.commodity().precision()); + assertEqual(x0.commodity(), x12.commodity()); + assertEqual(x0, x12); + + x2.parse("$100.00", AMOUNT_PARSE_NO_REDUCE); + assertEqual(x2, x12); + x3.parse("$100.00", AMOUNT_PARSE_NO_MIGRATE | AMOUNT_PARSE_NO_REDUCE); + assertEqual(x3, x12); + + x4.parse("$100.00"); + assertEqual(x4, x12); + x5.parse("$100.00", AMOUNT_PARSE_NO_MIGRATE); + assertEqual(x5, x12); + x6.parse("$100.00", AMOUNT_PARSE_NO_REDUCE); + assertEqual(x6, x12); + x7.parse("$100.00", AMOUNT_PARSE_NO_MIGRATE | AMOUNT_PARSE_NO_REDUCE); + assertEqual(x7, x12); + + x8.parse("$100.00"); + assertEqual(x8, x12); + x9.parse("$100.00", AMOUNT_PARSE_NO_MIGRATE); + assertEqual(x9, x12); + x10.parse("$100.00", AMOUNT_PARSE_NO_REDUCE); + assertEqual(x10, x12); + x11.parse("$100.00", AMOUNT_PARSE_NO_MIGRATE | AMOUNT_PARSE_NO_REDUCE); + assertEqual(x11, x12); + + 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()); + assertTrue(x12.valid()); +} + void AmountTestCase::testConstructors() { amount_t x0; @@ -108,6 +173,7 @@ void AmountTestCase::testCommodityConstructors() void AmountTestCase::testAssignment() { + amount_t x0; amount_t x1 = 123456L; amount_t x2 = 123456UL; amount_t x3 = 123.456; @@ -144,6 +210,12 @@ void AmountTestCase::testAssignment() assertEqual(x10, x3); assertEqual(x10, x9); + assertFalse(x1.is_null()); + x1 = x0; // sets x1 back to uninitialized state + assertTrue(x0.is_null()); + assertTrue(x1.is_null()); + + assertTrue(x0.valid()); assertTrue(x1.valid()); assertTrue(x2.valid()); assertTrue(x3.valid()); diff --git a/tests/numerics/t_amount.h b/tests/numerics/t_amount.h index 0bf0017f..9b3d36f0 100644 --- a/tests/numerics/t_amount.h +++ b/tests/numerics/t_amount.h @@ -9,6 +9,7 @@ class AmountTestCase : public CPPUNIT_NS::TestCase CPPUNIT_TEST(testConstructors); CPPUNIT_TEST(testCommodityConstructors); + CPPUNIT_TEST(testParser); CPPUNIT_TEST(testAssignment); CPPUNIT_TEST(testCommodityAssignment); CPPUNIT_TEST(testEquality); @@ -60,6 +61,7 @@ public: void testConstructors(); void testCommodityConstructors(); + void testParser(); void testAssignment(); void testCommodityAssignment(); void testEquality(); |