summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/numerics/BasicAmount.cc653
-rw-r--r--tests/numerics/CommodityAmount.h62
-rw-r--r--tests/numerics/t_amount.cc (renamed from tests/numerics/CommodityAmount.cc)686
-rw-r--r--tests/numerics/t_amount.h (renamed from tests/numerics/BasicAmount.h)40
-rw-r--r--tests/numerics/t_commodity.cc (renamed from tests/numerics/Commodity.cc)2
-rw-r--r--tests/numerics/t_commodity.h (renamed from tests/numerics/Commodity.h)6
-rw-r--r--tests/numerics/t_times.cc (renamed from tests/numerics/DateTime.cc)2
-rw-r--r--tests/numerics/t_times.h (renamed from tests/numerics/DateTimeTest.h)6
-rw-r--r--tests/python/UnitTests.py6
-rw-r--r--tests/python/baseline/__init__.py0
-rw-r--r--tests/python/cases/__init__.py0
-rw-r--r--tests/python/driver/__init__.py0
-rw-r--r--tests/python/journal/__init__.py0
-rw-r--r--tests/python/numerics/BasicAmount.py531
-rw-r--r--tests/python/numerics/balances/__init__.py0
-rw-r--r--tests/python/numerics/t_amount.py (renamed from tests/python/numerics/CommodityAmount.py)556
-rw-r--r--tests/python/numerics/values/__init__.py0
-rw-r--r--tests/python/parsers/__init__.py0
-rw-r--r--tests/python/parsers/binary/__init__.py0
-rw-r--r--tests/python/parsers/gnucash/__init__.py0
-rw-r--r--tests/python/parsers/ofx/__init__.py0
-rw-r--r--tests/python/parsers/qif/__init__.py0
-rw-r--r--tests/python/parsers/textual/__init__.py0
-rw-r--r--tests/python/python/__init__.py0
-rw-r--r--tests/python/reports/__init__.py0
-rw-r--r--tests/python/reports/balance/__init__.py0
-rw-r--r--tests/python/reports/emacs/__init__.py0
-rw-r--r--tests/python/reports/equity/__init__.py0
-rw-r--r--tests/python/reports/print/__init__.py0
-rw-r--r--tests/python/reports/register/__init__.py0
-rw-r--r--tests/python/transforms/__init__.py0
31 files changed, 1249 insertions, 1301 deletions
diff --git a/tests/numerics/BasicAmount.cc b/tests/numerics/BasicAmount.cc
deleted file mode 100644
index 6d9e3dc7..00000000
--- a/tests/numerics/BasicAmount.cc
+++ /dev/null
@@ -1,653 +0,0 @@
-#include "BasicAmount.h"
-
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicAmountTestCase, "numerics");
-
-void BasicAmountTestCase::setUp() {
- ledger::set_session_context(&session);
-}
-void BasicAmountTestCase::tearDown() {
- ledger::set_session_context();
-}
-
-void BasicAmountTestCase::testConstructors()
-{
- amount_t x0;
- amount_t x1(123456L);
- amount_t x2(123456UL);
- amount_t x3(123.456);
- amount_t x5("123456");
- amount_t x6("123.456");
- amount_t x7(string("123456"));
- amount_t x8(string("123.456"));
- amount_t x9(x3);
- amount_t x10(x6);
- 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);
- assertEqual(x6, x3);
- assertEqual(x8, x3);
- 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());
-}
-
-void BasicAmountTestCase::testAssignment()
-{
- amount_t x0;
- amount_t x1 = 123456L;
- amount_t x2 = 123456UL;
- amount_t x3 = 123.456;
- amount_t x5 = "123456";
- amount_t x6 = "123.456";
- amount_t x7 = string("123456");
- amount_t x8 = string("123.456");
- amount_t x9 = x3;
- amount_t x10 = amount_t(x6);
-
- assertEqual(amount_t(0L), x0);
- assertEqual(x2, x1);
- assertEqual(x5, x1);
- assertEqual(x7, x1);
- assertEqual(x6, x3);
- assertEqual(x8, x3);
- assertEqual(x10, x3);
- assertEqual(x10, x9);
-
- x0 = amount_t();
- x1 = 123456L;
- x2 = 123456UL;
- x3 = 123.456;
- x5 = "123456";
- x6 = "123.456";
- x7 = string("123456");
- x8 = string("123.456");
- x9 = x3;
- x10 = amount_t(x6);
-
- assertEqual(amount_t(0L), x0);
- assertEqual(x2, x1);
- assertEqual(x5, x1);
- assertEqual(x7, x1);
- assertEqual(x6, x3);
- assertEqual(x8, x3);
- 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());
-}
-
-void BasicAmountTestCase::testEquality()
-{
- amount_t x1(123456L);
- amount_t x2(456789L);
- amount_t x3(333333L);
- amount_t x4(123456.0);
- 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());
-}
-
-void BasicAmountTestCase::testComparisons()
-{
- amount_t x0;
- amount_t x1(-123L);
- amount_t x2(123L);
- amount_t x3(-123.45);
- amount_t x4(123.45);
- 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());
-}
-
-void BasicAmountTestCase::testIntegerAddition()
-{
- amount_t x1(123L);
- amount_t y1(456L);
-
- assertEqual(amount_t(579L), x1 + y1);
- assertEqual(amount_t(579L), x1 + 456L);
- assertEqual(amount_t(579L), 456L + x1);
-
- x1 += amount_t(456L);
- assertEqual(amount_t(579L), x1);
- x1 += 456L;
- assertEqual(amount_t(1035L), x1);
-
- amount_t x4("123456789123456789123456789");
-
- assertEqual(amount_t("246913578246913578246913578"), x4 + x4);
-
- CPPUNIT_ASSERT(x1.valid());
- CPPUNIT_ASSERT(y1.valid());
- CPPUNIT_ASSERT(x4.valid());
-}
-
-void BasicAmountTestCase::testFractionalAddition()
-{
- amount_t x1(123.123);
- amount_t y1(456.456);
-
- assertEqual(amount_t(579.579), x1 + y1);
- assertEqual(amount_t(579.579), x1 + 456.456);
- assertEqual(amount_t(579.579), 456.456 + x1);
-
- x1 += amount_t(456.456);
- assertEqual(amount_t(579.579), x1);
- x1 += 456.456;
- assertEqual(amount_t(1036.035), x1);
- x1 += 456L;
- assertEqual(amount_t(1492.035), x1);
-
- 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()
-{
- amount_t x1(123L);
- amount_t y1(456L);
-
- assertEqual(amount_t(333L), y1 - x1);
- assertEqual(amount_t(-333L), x1 - y1);
- assertEqual(amount_t(23L), x1 - 100L);
- assertEqual(amount_t(-23L), 100L - x1);
-
- x1 -= amount_t(456L);
- assertEqual(amount_t(-333L), x1);
- x1 -= 456L;
- assertEqual(amount_t(-789L), x1);
-
- amount_t x4("123456789123456789123456789");
- amount_t y4("8238725986235986");
-
- 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());
-}
-
-void BasicAmountTestCase::testFractionalSubtraction()
-{
- amount_t x1(123.123);
- amount_t y1(456.456);
-
- assertEqual(amount_t(-333.333), x1 - y1);
- assertEqual(amount_t(333.333), y1 - x1);
-
- x1 -= amount_t(456.456);
- assertEqual(amount_t(-333.333), x1);
- x1 -= 456.456;
- assertEqual(amount_t(-789.789), x1);
- x1 -= 456L;
- assertEqual(amount_t(-1245.789), x1);
-
- amount_t x2("123456789123456789.123456789123456789");
- amount_t y2("9872345982459.248974239578");
-
- 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()
-{
- 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);
-
- x1 *= amount_t(123L);
- assertEqual(amount_t(15129L), x1);
- x1 *= 123L;
- assertEqual(amount_t(1860867L), x1);
-
- amount_t x4("123456789123456789123456789");
-
- assertEqual(amount_t("15241578780673678546105778281054720515622620750190521"),
- x4 * x4);
-
- CPPUNIT_ASSERT(x1.valid());
- CPPUNIT_ASSERT(y1.valid());
- CPPUNIT_ASSERT(x4.valid());
-}
-
-void BasicAmountTestCase::testFractionalMultiplication()
-{
- amount_t x1(123.123);
- amount_t y1(456.456);
-
- 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("56200.232088"), x1 * y1);
- assertEqual(amount_t("56200.232088"), y1 * x1);
- assertEqual(amount_t("56200.232088"), x1 * 456.456);
- assertEqual(amount_t("56200.232088"), amount_t(456.456) * x1);
- assertEqual(amount_t("56200.232088"), 456.456 * x1);
-
- x1 *= amount_t(123.123);
- assertEqual(amount_t("15159.273129"), x1);
- x1 *= 123.123;
- assertEqual(amount_t("1866455.185461867"), x1);
- x1 *= 123L;
- assertEqual(amount_t("229573987.811809641"), x1);
-
- amount_t x2("123456789123456789.123456789123456789");
-
- assertEqual(amount_t("15241578780673678546105778311537878.046486820281054720515622620750190521"),
- x2 * x2);
-
- CPPUNIT_ASSERT(x1.valid());
- CPPUNIT_ASSERT(y1.valid());
- CPPUNIT_ASSERT(x2.valid());
-}
-
-void BasicAmountTestCase::testIntegerDivision()
-{
- amount_t x1(123L);
- amount_t y1(456L);
-
- assertThrow(x1 / 0L, amount_error);
- assertEqual(amount_t(0L), amount_t(0L) / x1);
- assertEqual(amount_t(0L), 0L / x1);
- assertEqual(x1, x1 / 1L);
- assertEqual(amount_t("0.008130"), amount_t(1L) / x1);
- assertEqual(amount_t("0.008130"), 1L / x1);
- assertEqual(- x1, x1 / -1L);
- assertEqual(- amount_t("0.008130"), amount_t(-1L) / x1);
- assertEqual(- amount_t("0.008130"), -1L / x1);
- assertEqual(amount_t("0.269737"), x1 / y1);
- assertEqual(amount_t("3.707317"), y1 / x1);
- assertEqual(amount_t("0.269737"), x1 / 456L);
- assertEqual(amount_t("3.707317"), amount_t(456L) / x1);
- assertEqual(amount_t("3.707317"), 456L / x1);
-
- x1 /= amount_t(456L);
- assertEqual(amount_t("0.269737"), x1);
- x1 /= 456L;
- assertEqual(amount_t("0.00059152850877193"), x1);
-
- amount_t x4("123456789123456789123456789");
- amount_t y4("56");
-
- 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()
-{
- amount_t x1(123.123);
- amount_t y1(456.456);
-
- assertThrow(x1 / 0L, amount_error);
- assertEqual(amount_t("0.008121959"), amount_t(1.0) / x1);
- assertEqual(amount_t("0.008121959"), 1.0 / x1);
- assertEqual(x1, x1 / 1.0);
- assertEqual(amount_t("0.008121959"), amount_t(1.0) / x1);
- assertEqual(amount_t("0.008121959"), 1.0 / x1);
- assertEqual(- x1, x1 / -1.0);
- assertEqual(- amount_t("0.008121959"), amount_t(-1.0) / x1);
- assertEqual(- amount_t("0.008121959"), -1.0 / x1);
- assertEqual(amount_t("0.269736842105263"), x1 / y1);
- assertEqual(amount_t("3.707317073170732"), y1 / x1);
- assertEqual(amount_t("0.269736842105263"), x1 / 456.456);
- assertEqual(amount_t("3.707317073170732"), amount_t(456.456) / x1);
- assertEqual(amount_t("3.707317073170732"), 456.456 / x1);
-
- x1 /= amount_t(456.456);
- assertEqual(amount_t("0.269736842105263"), x1);
- x1 /= 456.456;
- assertEqual(amount_t("0.000590937225286255411255411255411255411"), x1);
- x1 /= 456L;
- assertEqual(amount_t("0.000001295914967733016252753094858358016252192982456140350877192982456140350877192982"), x1);
-
- amount_t x4("1234567891234567.89123456789");
- amount_t y4("56.789");
-
- 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());
-}
-
-void BasicAmountTestCase::testNegation()
-{
- amount_t x0;
- amount_t x1(-123456L);
- amount_t x3(-123.456);
- amount_t x5("-123456");
- amount_t x6("-123.456");
- amount_t x7(string("-123456"));
- amount_t x8(string("-123.456"));
- amount_t x9(- x3);
-
- assertEqual(amount_t(0L), x0);
- assertEqual(x5, x1);
- assertEqual(x7, x1);
- assertEqual(x6, x3);
- assertEqual(x8, x3);
- assertEqual(- x6, x9);
- assertEqual(x3.negate(), x9);
-
- amount_t x10(x9.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::testAbs()
-{
- amount_t x0;
- amount_t x1(-1234L);
- amount_t x2(1234L);
-
- assertEqual(amount_t(), x0.abs());
- assertEqual(amount_t(1234L), x1.abs());
- assertEqual(amount_t(1234L), x2.abs());
-
- CPPUNIT_ASSERT(x0.valid());
- CPPUNIT_ASSERT(x1.valid());
- CPPUNIT_ASSERT(x2.valid());
-}
-
-void BasicAmountTestCase::testFractionalRound()
-{
- amount_t x1("1234.567890");
-
- 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());
-}
diff --git a/tests/numerics/CommodityAmount.h b/tests/numerics/CommodityAmount.h
deleted file mode 100644
index d80a3e15..00000000
--- a/tests/numerics/CommodityAmount.h
+++ /dev/null
@@ -1,62 +0,0 @@
-#ifndef _COMMODITYAMOUNT_H
-#define _COMMODITYAMOUNT_H
-
-#include "UnitTests.h"
-
-class CommodityAmountTestCase : public CPPUNIT_NS::TestCase
-{
- CPPUNIT_TEST_SUITE(CommodityAmountTestCase);
-
- CPPUNIT_TEST(testConstructors);
- CPPUNIT_TEST(testNegation);
- CPPUNIT_TEST(testAssignment);
- CPPUNIT_TEST(testEquality);
- CPPUNIT_TEST(testAddition);
- CPPUNIT_TEST(testSubtraction);
- CPPUNIT_TEST(testMultiplication);
- CPPUNIT_TEST(testDivision);
- CPPUNIT_TEST(testConversion);
- CPPUNIT_TEST(testRound);
- CPPUNIT_TEST(testDisplayRound);
- CPPUNIT_TEST(testTruth);
- CPPUNIT_TEST(testForZero);
- CPPUNIT_TEST(testComparisons);
- CPPUNIT_TEST(testSign);
- CPPUNIT_TEST(testAbs);
- CPPUNIT_TEST(testPrinting);
-
- CPPUNIT_TEST_SUITE_END();
-
-public:
- ledger::session_t session;
-
- CommodityAmountTestCase() {}
- virtual ~CommodityAmountTestCase() {}
-
- virtual void setUp();
- virtual void tearDown();
-
- void testConstructors();
- void testNegation();
- void testAssignment();
- void testEquality();
- void testAddition();
- void testSubtraction();
- void testMultiplication();
- void testDivision();
- void testConversion();
- void testRound();
- void testDisplayRound();
- void testTruth();
- void testForZero();
- void testComparisons();
- void testSign();
- void testAbs();
- void testPrinting();
-
-private:
- CommodityAmountTestCase(const CommodityAmountTestCase &copy);
- void operator=(const CommodityAmountTestCase &copy);
-};
-
-#endif /* _COMMODITYAMOUNT_H */
diff --git a/tests/numerics/CommodityAmount.cc b/tests/numerics/t_amount.cc
index cc26bc80..94e32c01 100644
--- a/tests/numerics/CommodityAmount.cc
+++ b/tests/numerics/t_amount.cc
@@ -1,10 +1,10 @@
-#include "CommodityAmount.h"
+#include "t_amount.h"
#define internalAmount(x) amount_t::exact(x)
-CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(CommodityAmountTestCase, "numerics");
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicAmountTestCase, "numerics");
-void CommodityAmountTestCase::setUp()
+void BasicAmountTestCase::setUp()
{
ledger::set_session_context(&session);
@@ -14,14 +14,657 @@ void CommodityAmountTestCase::setUp()
amount_t::stream_fullstrings = true; // makes error reports from UnitTests accurate
}
-void CommodityAmountTestCase::tearDown()
+void BasicAmountTestCase::tearDown()
{
amount_t::stream_fullstrings = false;
ledger::set_session_context();
}
-void CommodityAmountTestCase::testConstructors()
+void BasicAmountTestCase::testConstructors()
+{
+ amount_t x0;
+ amount_t x1(123456L);
+ amount_t x2(123456UL);
+ amount_t x3(123.456);
+ amount_t x5("123456");
+ amount_t x6("123.456");
+ amount_t x7(string("123456"));
+ amount_t x8(string("123.456"));
+ amount_t x9(x3);
+ amount_t x10(x6);
+ 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);
+ assertEqual(x6, x3);
+ assertEqual(x8, x3);
+ 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());
+}
+
+void BasicAmountTestCase::testAssignment()
+{
+ amount_t x0;
+ amount_t x1 = 123456L;
+ amount_t x2 = 123456UL;
+ amount_t x3 = 123.456;
+ amount_t x5 = "123456";
+ amount_t x6 = "123.456";
+ amount_t x7 = string("123456");
+ amount_t x8 = string("123.456");
+ amount_t x9 = x3;
+ amount_t x10 = amount_t(x6);
+
+ assertEqual(amount_t(0L), x0);
+ assertEqual(x2, x1);
+ assertEqual(x5, x1);
+ assertEqual(x7, x1);
+ assertEqual(x6, x3);
+ assertEqual(x8, x3);
+ assertEqual(x10, x3);
+ assertEqual(x10, x9);
+
+ x0 = amount_t();
+ x1 = 123456L;
+ x2 = 123456UL;
+ x3 = 123.456;
+ x5 = "123456";
+ x6 = "123.456";
+ x7 = string("123456");
+ x8 = string("123.456");
+ x9 = x3;
+ x10 = amount_t(x6);
+
+ assertEqual(amount_t(0L), x0);
+ assertEqual(x2, x1);
+ assertEqual(x5, x1);
+ assertEqual(x7, x1);
+ assertEqual(x6, x3);
+ assertEqual(x8, x3);
+ 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());
+}
+
+void BasicAmountTestCase::testEquality()
+{
+ amount_t x1(123456L);
+ amount_t x2(456789L);
+ amount_t x3(333333L);
+ amount_t x4(123456.0);
+ 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());
+}
+
+void BasicAmountTestCase::testComparisons()
+{
+ amount_t x0;
+ amount_t x1(-123L);
+ amount_t x2(123L);
+ amount_t x3(-123.45);
+ amount_t x4(123.45);
+ 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());
+}
+
+void BasicAmountTestCase::testIntegerAddition()
+{
+ amount_t x1(123L);
+ amount_t y1(456L);
+
+ assertEqual(amount_t(579L), x1 + y1);
+ assertEqual(amount_t(579L), x1 + 456L);
+ assertEqual(amount_t(579L), 456L + x1);
+
+ x1 += amount_t(456L);
+ assertEqual(amount_t(579L), x1);
+ x1 += 456L;
+ assertEqual(amount_t(1035L), x1);
+
+ amount_t x4("123456789123456789123456789");
+
+ assertEqual(amount_t("246913578246913578246913578"), x4 + x4);
+
+ CPPUNIT_ASSERT(x1.valid());
+ CPPUNIT_ASSERT(y1.valid());
+ CPPUNIT_ASSERT(x4.valid());
+}
+
+void BasicAmountTestCase::testFractionalAddition()
+{
+ amount_t x1(123.123);
+ amount_t y1(456.456);
+
+ assertEqual(amount_t(579.579), x1 + y1);
+ assertEqual(amount_t(579.579), x1 + 456.456);
+ assertEqual(amount_t(579.579), 456.456 + x1);
+
+ x1 += amount_t(456.456);
+ assertEqual(amount_t(579.579), x1);
+ x1 += 456.456;
+ assertEqual(amount_t(1036.035), x1);
+ x1 += 456L;
+ assertEqual(amount_t(1492.035), x1);
+
+ 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()
+{
+ amount_t x1(123L);
+ amount_t y1(456L);
+
+ assertEqual(amount_t(333L), y1 - x1);
+ assertEqual(amount_t(-333L), x1 - y1);
+ assertEqual(amount_t(23L), x1 - 100L);
+ assertEqual(amount_t(-23L), 100L - x1);
+
+ x1 -= amount_t(456L);
+ assertEqual(amount_t(-333L), x1);
+ x1 -= 456L;
+ assertEqual(amount_t(-789L), x1);
+
+ amount_t x4("123456789123456789123456789");
+ amount_t y4("8238725986235986");
+
+ 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());
+}
+
+void BasicAmountTestCase::testFractionalSubtraction()
+{
+ amount_t x1(123.123);
+ amount_t y1(456.456);
+
+ assertEqual(amount_t(-333.333), x1 - y1);
+ assertEqual(amount_t(333.333), y1 - x1);
+
+ x1 -= amount_t(456.456);
+ assertEqual(amount_t(-333.333), x1);
+ x1 -= 456.456;
+ assertEqual(amount_t(-789.789), x1);
+ x1 -= 456L;
+ assertEqual(amount_t(-1245.789), x1);
+
+ amount_t x2("123456789123456789.123456789123456789");
+ amount_t y2("9872345982459.248974239578");
+
+ 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()
+{
+ 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);
+
+ x1 *= amount_t(123L);
+ assertEqual(amount_t(15129L), x1);
+ x1 *= 123L;
+ assertEqual(amount_t(1860867L), x1);
+
+ amount_t x4("123456789123456789123456789");
+
+ assertEqual(amount_t("15241578780673678546105778281054720515622620750190521"),
+ x4 * x4);
+
+ CPPUNIT_ASSERT(x1.valid());
+ CPPUNIT_ASSERT(y1.valid());
+ CPPUNIT_ASSERT(x4.valid());
+}
+
+void BasicAmountTestCase::testFractionalMultiplication()
+{
+ amount_t x1(123.123);
+ amount_t y1(456.456);
+
+ 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("56200.232088"), x1 * y1);
+ assertEqual(amount_t("56200.232088"), y1 * x1);
+ assertEqual(amount_t("56200.232088"), x1 * 456.456);
+ assertEqual(amount_t("56200.232088"), amount_t(456.456) * x1);
+ assertEqual(amount_t("56200.232088"), 456.456 * x1);
+
+ x1 *= amount_t(123.123);
+ assertEqual(amount_t("15159.273129"), x1);
+ x1 *= 123.123;
+ assertEqual(amount_t("1866455.185461867"), x1);
+ x1 *= 123L;
+ assertEqual(amount_t("229573987.811809641"), x1);
+
+ amount_t x2("123456789123456789.123456789123456789");
+
+ assertEqual(amount_t("15241578780673678546105778311537878.046486820281054720515622620750190521"),
+ x2 * x2);
+
+ CPPUNIT_ASSERT(x1.valid());
+ CPPUNIT_ASSERT(y1.valid());
+ CPPUNIT_ASSERT(x2.valid());
+}
+
+void BasicAmountTestCase::testIntegerDivision()
+{
+ amount_t x1(123L);
+ amount_t y1(456L);
+
+ assertThrow(x1 / 0L, amount_error);
+ assertEqual(amount_t(0L), amount_t(0L) / x1);
+ assertEqual(amount_t(0L), 0L / x1);
+ assertEqual(x1, x1 / 1L);
+ assertEqual(amount_t("0.008130"), amount_t(1L) / x1);
+ assertEqual(amount_t("0.008130"), 1L / x1);
+ assertEqual(- x1, x1 / -1L);
+ assertEqual(- amount_t("0.008130"), amount_t(-1L) / x1);
+ assertEqual(- amount_t("0.008130"), -1L / x1);
+ assertEqual(amount_t("0.269737"), x1 / y1);
+ assertEqual(amount_t("3.707317"), y1 / x1);
+ assertEqual(amount_t("0.269737"), x1 / 456L);
+ assertEqual(amount_t("3.707317"), amount_t(456L) / x1);
+ assertEqual(amount_t("3.707317"), 456L / x1);
+
+ x1 /= amount_t(456L);
+ assertEqual(amount_t("0.269737"), x1);
+ x1 /= 456L;
+ assertEqual(amount_t("0.00059152850877193"), x1);
+
+ amount_t x4("123456789123456789123456789");
+ amount_t y4("56");
+
+ 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()
+{
+ amount_t x1(123.123);
+ amount_t y1(456.456);
+
+ assertThrow(x1 / 0L, amount_error);
+ assertEqual(amount_t("0.008121959"), amount_t(1.0) / x1);
+ assertEqual(amount_t("0.008121959"), 1.0 / x1);
+ assertEqual(x1, x1 / 1.0);
+ assertEqual(amount_t("0.008121959"), amount_t(1.0) / x1);
+ assertEqual(amount_t("0.008121959"), 1.0 / x1);
+ assertEqual(- x1, x1 / -1.0);
+ assertEqual(- amount_t("0.008121959"), amount_t(-1.0) / x1);
+ assertEqual(- amount_t("0.008121959"), -1.0 / x1);
+ assertEqual(amount_t("0.269736842105263"), x1 / y1);
+ assertEqual(amount_t("3.707317073170732"), y1 / x1);
+ assertEqual(amount_t("0.269736842105263"), x1 / 456.456);
+ assertEqual(amount_t("3.707317073170732"), amount_t(456.456) / x1);
+ assertEqual(amount_t("3.707317073170732"), 456.456 / x1);
+
+ x1 /= amount_t(456.456);
+ assertEqual(amount_t("0.269736842105263"), x1);
+ x1 /= 456.456;
+ assertEqual(amount_t("0.000590937225286255411255411255411255411"), x1);
+ x1 /= 456L;
+ assertEqual(amount_t("0.000001295914967733016252753094858358016252192982456140350877192982456140350877192982"), x1);
+
+ amount_t x4("1234567891234567.89123456789");
+ amount_t y4("56.789");
+
+ 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());
+}
+
+void BasicAmountTestCase::testNegation()
+{
+ amount_t x0;
+ amount_t x1(-123456L);
+ amount_t x3(-123.456);
+ amount_t x5("-123456");
+ amount_t x6("-123.456");
+ amount_t x7(string("-123456"));
+ amount_t x8(string("-123.456"));
+ amount_t x9(- x3);
+
+ assertEqual(amount_t(0L), x0);
+ assertEqual(x5, x1);
+ assertEqual(x7, x1);
+ assertEqual(x6, x3);
+ assertEqual(x8, x3);
+ assertEqual(- x6, x9);
+ assertEqual(x3.negate(), x9);
+
+ amount_t x10(x9.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::testAbs()
+{
+ amount_t x0;
+ amount_t x1(-1234L);
+ amount_t x2(1234L);
+
+ assertEqual(amount_t(), x0.abs());
+ assertEqual(amount_t(1234L), x1.abs());
+ assertEqual(amount_t(1234L), x2.abs());
+
+ CPPUNIT_ASSERT(x0.valid());
+ CPPUNIT_ASSERT(x1.valid());
+ CPPUNIT_ASSERT(x2.valid());
+}
+
+void BasicAmountTestCase::testFractionalRound()
+{
+ amount_t x1("1234.567890");
+
+ 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");
@@ -68,7 +711,7 @@ void CommodityAmountTestCase::testConstructors()
assertValid(x10);
}
-void CommodityAmountTestCase::testNegation()
+void BasicAmountTestCase::testCommodityNegation()
{
amount_t x1("$123.45");
amount_t x2("-$123.45");
@@ -123,7 +766,7 @@ void CommodityAmountTestCase::testNegation()
assertValid(x10);
}
-void CommodityAmountTestCase::testAssignment()
+void BasicAmountTestCase::testCommodityAssignment()
{
amount_t x1 = "$123.45";
amount_t x2 = "-$123.45";
@@ -170,7 +813,7 @@ void CommodityAmountTestCase::testAssignment()
assertValid(x10);
}
-void CommodityAmountTestCase::testEquality()
+void BasicAmountTestCase::testCommodityEquality()
{
amount_t x0;
amount_t x1 = "$123.45";
@@ -215,7 +858,7 @@ void CommodityAmountTestCase::testEquality()
assertValid(x10);
}
-void CommodityAmountTestCase::testAddition()
+void BasicAmountTestCase::testCommodityAddition()
{
amount_t x0;
amount_t x1("$123.45");
@@ -269,7 +912,7 @@ void CommodityAmountTestCase::testAddition()
assertValid(x7);
}
-void CommodityAmountTestCase::testSubtraction()
+void BasicAmountTestCase::testCommoditySubtraction()
{
amount_t x0;
amount_t x1("$123.45");
@@ -348,7 +991,7 @@ void CommodityAmountTestCase::testSubtraction()
assertValid(x8);
}
-void CommodityAmountTestCase::testMultiplication()
+void BasicAmountTestCase::testCommodityMultiplication()
{
amount_t x1("$123.12");
amount_t y1("$456.45");
@@ -402,7 +1045,7 @@ void CommodityAmountTestCase::testMultiplication()
assertValid(x7);
}
-void CommodityAmountTestCase::testDivision()
+void BasicAmountTestCase::testCommodityDivision()
{
amount_t x1("$123.12");
amount_t y1("$456.45");
@@ -461,7 +1104,7 @@ void CommodityAmountTestCase::testDivision()
assertValid(x7);
}
-void CommodityAmountTestCase::testConversion()
+void BasicAmountTestCase::testCommodityConversion()
{
amount_t x1("$1234.56");
@@ -475,7 +1118,7 @@ void CommodityAmountTestCase::testConversion()
assertValid(x1);
}
-void CommodityAmountTestCase::testRound()
+void BasicAmountTestCase::testCommodityRound()
{
amount_t x1(internalAmount("$1234.567890"));
@@ -533,7 +1176,7 @@ void CommodityAmountTestCase::testRound()
assertValid(x5);
}
-void CommodityAmountTestCase::testDisplayRound()
+void BasicAmountTestCase::testCommodityDisplayRound()
{
amount_t x1("$0.85");
amount_t x2("$0.1");
@@ -555,7 +1198,7 @@ void CommodityAmountTestCase::testDisplayRound()
assertEqual(string("$1.13"), x1.to_string());
}
-void CommodityAmountTestCase::testTruth()
+void BasicAmountTestCase::testCommodityTruth()
{
amount_t x1("$1234");
amount_t x2("$1234.56");
@@ -574,7 +1217,7 @@ void CommodityAmountTestCase::testTruth()
assertValid(x2);
}
-void CommodityAmountTestCase::testForZero()
+void BasicAmountTestCase::testCommodityForZero()
{
amount_t x1(internalAmount("$0.000000000000000000001"));
@@ -585,7 +1228,7 @@ void CommodityAmountTestCase::testForZero()
assertValid(x1);
}
-void CommodityAmountTestCase::testComparisons()
+void BasicAmountTestCase::testCommodityComparisons()
{
amount_t x0;
amount_t x1("$-123");
@@ -619,7 +1262,7 @@ void CommodityAmountTestCase::testComparisons()
assertValid(x6);
}
-void CommodityAmountTestCase::testSign()
+void BasicAmountTestCase::testCommoditySign()
{
amount_t x0;
amount_t x1(internalAmount("$0.0000000000000000000000000000000000001"));
@@ -640,7 +1283,7 @@ void CommodityAmountTestCase::testSign()
assertValid(x4);
}
-void CommodityAmountTestCase::testAbs()
+void BasicAmountTestCase::testCommodityAbs()
{
amount_t x0;
amount_t x1("$-1234.56");
@@ -655,7 +1298,7 @@ void CommodityAmountTestCase::testAbs()
assertValid(x2);
}
-void CommodityAmountTestCase::testPrinting()
+void BasicAmountTestCase::testCommodityPrinting()
{
amount_t x0;
amount_t x1(internalAmount("$982340823.386238098235098235098235098"));
@@ -695,4 +1338,3 @@ void CommodityAmountTestCase::testPrinting()
assertValid(x1);
assertValid(x2);
}
-
diff --git a/tests/numerics/BasicAmount.h b/tests/numerics/t_amount.h
index 4d11821e..ee227a5c 100644
--- a/tests/numerics/BasicAmount.h
+++ b/tests/numerics/t_amount.h
@@ -1,5 +1,5 @@
-#ifndef _BASICAMOUNT_H
-#define _BASICAMOUNT_H
+#ifndef _T_AMOUNT_H
+#define _T_AMOUNT_H
#include "UnitTests.h"
@@ -29,6 +29,23 @@ class BasicAmountTestCase : public CPPUNIT_NS::TestCase
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(testCommodityPrinting);
CPPUNIT_TEST_SUITE_END();
@@ -63,10 +80,27 @@ public:
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 testCommodityPrinting();
private:
BasicAmountTestCase(const BasicAmountTestCase &copy);
void operator=(const BasicAmountTestCase &copy);
};
-#endif /* _BASICAMOUNT_H */
+#endif // _T_AMOUNT_H
diff --git a/tests/numerics/Commodity.cc b/tests/numerics/t_commodity.cc
index 25da9d42..8b4d4fe8 100644
--- a/tests/numerics/Commodity.cc
+++ b/tests/numerics/t_commodity.cc
@@ -1,4 +1,4 @@
-#include "Commodity.h"
+#include "t_commodity.h"
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(CommodityTestCase, "numerics");
diff --git a/tests/numerics/Commodity.h b/tests/numerics/t_commodity.h
index aebe9a9e..ed739751 100644
--- a/tests/numerics/Commodity.h
+++ b/tests/numerics/t_commodity.h
@@ -1,5 +1,5 @@
-#ifndef _COMMMODITY_H
-#define _COMMMODITY_H
+#ifndef _T_COMMMODITY_H
+#define _T_COMMMODITY_H
#include "UnitTests.h"
@@ -33,4 +33,4 @@ private:
void operator=(const CommodityTestCase &copy);
};
-#endif /* _COMMMODITY_H */
+#endif // _T_COMMMODITY_H
diff --git a/tests/numerics/DateTime.cc b/tests/numerics/t_times.cc
index 24b8dd16..0d89d03f 100644
--- a/tests/numerics/DateTime.cc
+++ b/tests/numerics/t_times.cc
@@ -1,4 +1,4 @@
-#include "DateTimeTest.h"
+#include "t_times.h"
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(DateTimeTestCase, "numerics");
diff --git a/tests/numerics/DateTimeTest.h b/tests/numerics/t_times.h
index abc914cd..5bbadf21 100644
--- a/tests/numerics/DateTimeTest.h
+++ b/tests/numerics/t_times.h
@@ -1,5 +1,5 @@
-#ifndef _DATETIMETEST_H
-#define _DATETIMETEST_H
+#ifndef _T_TIMES_H
+#define _T_TIMES_H
#include "UnitTests.h"
@@ -25,4 +25,4 @@ private:
void operator=(const DateTimeTestCase &copy);
};
-#endif /* _DATETIMETEST_H */
+#endif /* _T_TIMES_H */
diff --git a/tests/python/UnitTests.py b/tests/python/UnitTests.py
index 84b8432b..843e9fc1 100644
--- a/tests/python/UnitTests.py
+++ b/tests/python/UnitTests.py
@@ -1,11 +1,9 @@
from unittest import TextTestRunner, TestSuite
-import tests.python.numerics.BasicAmount as BasicAmount
-import tests.python.numerics.CommodityAmount as CommodityAmount
+import tests.python.numerics.t_amount as t_amount
suites = [
- BasicAmount.suite(),
- CommodityAmount.suite(),
+ t_amount.suite(),
]
TextTestRunner().run(TestSuite(suites))
diff --git a/tests/python/baseline/__init__.py b/tests/python/baseline/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/baseline/__init__.py
+++ /dev/null
diff --git a/tests/python/cases/__init__.py b/tests/python/cases/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/cases/__init__.py
+++ /dev/null
diff --git a/tests/python/driver/__init__.py b/tests/python/driver/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/driver/__init__.py
+++ /dev/null
diff --git a/tests/python/journal/__init__.py b/tests/python/journal/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/journal/__init__.py
+++ /dev/null
diff --git a/tests/python/numerics/BasicAmount.py b/tests/python/numerics/BasicAmount.py
deleted file mode 100644
index 07c1f426..00000000
--- a/tests/python/numerics/BasicAmount.py
+++ /dev/null
@@ -1,531 +0,0 @@
-import sys
-
-import unittest
-import exceptions
-
-from ledger import amount
-
-class BasicAmountTestCase(unittest.TestCase):
- def testConstructors(self):
- x0 = amount()
- x1 = amount(123456)
- x2 = amount(123456L)
- x3 = amount(123.456)
- x5 = amount("123456")
- x6 = amount("123.456")
- x9 = amount(x3)
- x10 = amount(x6)
-
- self.assertEqual(amount(0), x0)
- self.assertEqual(x2, x1)
- self.assertEqual(x5, x1)
- self.assertEqual(x6, x3)
- self.assertEqual(x10, x3)
- self.assertEqual(x10, x9)
-
- self.assertTrue(x0.valid())
- self.assertTrue(x1.valid())
- self.assertTrue(x2.valid())
- self.assertTrue(x3.valid())
- self.assertTrue(x5.valid())
- self.assertTrue(x6.valid())
- self.assertTrue(x9.valid())
- self.assertTrue(x10.valid())
-
- def testNegation(self):
- x0 = amount()
- x1 = amount(-123456)
- x3 = amount(-123.456)
- x5 = amount("-123456")
- x6 = amount("-123.456")
- x9 = amount(- x3)
-
- self.assertEqual(amount(0), x0)
- self.assertEqual(x5, x1)
- self.assertEqual(x6, x3)
- self.assertEqual(- x6, x9)
- self.assertEqual(x3.negate(), x9)
-
- x10 = amount(x9.negate())
-
- self.assertEqual(x3, x10)
-
- self.assertTrue(x0.valid())
- self.assertTrue(x1.valid())
- self.assertTrue(x3.valid())
- self.assertTrue(x5.valid())
- self.assertTrue(x6.valid())
- self.assertTrue(x9.valid())
- self.assertTrue(x10.valid())
-
- def testAssignment(self):
- x0 = amount()
- x1 = amount(123456)
- x2 = amount(123456L)
- x3 = amount(123.456)
- x5 = amount("123456")
- x6 = amount("123.456")
- x9 = x3
- x10 = amount(x6)
-
- self.assertEqual(amount(0), x0)
- self.assertEqual(x2, x1)
- self.assertEqual(x5, x1)
- self.assertEqual(x6, x3)
- self.assertEqual(x10, x3)
- self.assertEqual(x10, x9)
-
- x0 = amount()
- x1 = amount(123456)
- x2 = amount(123456L)
- x3 = amount(123.456)
- x5 = amount("123456")
- x6 = amount("123.456")
- x9 = x3
- x10 = amount(x6)
-
- self.assertEqual(amount(0), x0)
- self.assertEqual(x2, x1)
- self.assertEqual(x5, x1)
- self.assertEqual(x6, x3)
- self.assertEqual(x10, x3)
- self.assertEqual(x10, x9)
-
- self.assertTrue(x0.valid())
- self.assertTrue(x1.valid())
- self.assertTrue(x2.valid())
- self.assertTrue(x3.valid())
- self.assertTrue(x5.valid())
- self.assertTrue(x6.valid())
- self.assertTrue(x9.valid())
- self.assertTrue(x10.valid())
-
- def testEquality(self):
- x1 = amount(123456)
- x2 = amount(456789)
- x3 = amount(333333)
- x4 = amount(123456.0)
- x5 = amount("123456.0")
-
- self.assertTrue(x1 == 123456)
- self.assertTrue(x1 != x2)
- self.assertTrue(x1 == (x2 - x3))
- self.assertTrue(x1 == x4)
- self.assertTrue(x4 == x5)
-
- self.assertTrue(x1.valid())
- self.assertTrue(x2.valid())
- self.assertTrue(x3.valid())
- self.assertTrue(x4.valid())
- self.assertTrue(x5.valid())
-
- def testIntegerAddition(self):
- x1 = amount(123)
- y1 = amount(456)
-
- self.assertEqual(amount(579), x1 + y1)
- self.assertEqual(amount(579), x1 + 456)
- self.assertEqual(amount(579), 456 + x1)
-
- x1 += amount(456)
- self.assertEqual(amount(579), x1)
- x1 += 456
- self.assertEqual(amount(1035), x1)
-
- x4 = amount("123456789123456789123456789")
-
- self.assertEqual(amount("246913578246913578246913578"), x4 + x4)
-
- self.assertTrue(x1.valid())
- self.assertTrue(y1.valid())
- self.assertTrue(x4.valid())
-
- def testFractionalAddition(self):
- x1 = amount(123.123)
- y1 = amount(456.456)
-
- self.assertEqual(amount(579.579), x1 + y1)
- self.assertEqual(amount(579.579), x1 + 456.456)
- self.assertEqual(amount(579.579), 456.456 + x1)
-
- x1 += amount(456.456)
- self.assertEqual(amount(579.579), x1)
- x1 += 456.456
- self.assertEqual(amount(1036.035), x1)
- x1 += 456
- self.assertEqual(amount(1492.035), x1)
-
- x2 = amount("123456789123456789.123456789123456789")
-
- self.assertEqual(amount("246913578246913578.246913578246913578"), x2 + x2)
-
- self.assertTrue(x1.valid())
- self.assertTrue(y1.valid())
- self.assertTrue(x2.valid())
-
- def testIntegerSubtraction(self):
- x1 = amount(123)
- y1 = amount(456)
-
- self.assertEqual(amount(333), y1 - x1)
- self.assertEqual(amount(-333), x1 - y1)
- self.assertEqual(amount(23), x1 - 100)
- self.assertEqual(amount(-23), 100 - x1)
-
- x1 -= amount(456)
- self.assertEqual(amount(-333), x1)
- x1 -= 456
- self.assertEqual(amount(-789), x1)
-
- x4 = amount("123456789123456789123456789")
- y4 = amount("8238725986235986")
-
- self.assertEqual(amount("123456789115218063137220803"), x4 - y4)
- self.assertEqual(amount("-123456789115218063137220803"), y4 - x4)
-
- self.assertTrue(x1.valid())
- self.assertTrue(y1.valid())
- self.assertTrue(x4.valid())
- self.assertTrue(y4.valid())
-
- def testFractionalSubtraction(self):
- x1 = amount(123.123)
- y1 = amount(456.456)
-
- self.assertEqual(amount(-333.333), x1 - y1)
- self.assertEqual(amount(333.333), y1 - x1)
-
- x1 -= amount(456.456)
- self.assertEqual(amount(-333.333), x1)
- x1 -= 456.456
- self.assertEqual(amount(-789.789), x1)
- x1 -= 456
- self.assertEqual(amount(-1245.789), x1)
-
- x2 = amount("123456789123456789.123456789123456789")
- y2 = amount("9872345982459.248974239578")
-
- self.assertEqual(amount("123446916777474329.874482549545456789"), x2 - y2)
- self.assertEqual(amount("-123446916777474329.874482549545456789"), y2 - x2)
-
- self.assertTrue(x1.valid())
- self.assertTrue(y1.valid())
- self.assertTrue(x2.valid())
- self.assertTrue(y2.valid())
-
- def testIntegerMultiplication(self):
- x1 = amount(123)
- y1 = amount(456)
-
- self.assertEqual(amount(0), x1 * 0)
- self.assertEqual(amount(0), amount(0) * x1)
- self.assertEqual(amount(0), 0 * x1)
- self.assertEqual(x1, x1 * 1)
- self.assertEqual(x1, amount(1) * x1)
- self.assertEqual(x1, 1 * x1)
- self.assertEqual(- x1, x1 * -1)
- self.assertEqual(- x1, amount(-1) * x1)
- self.assertEqual(- x1, -1 * x1)
- self.assertEqual(amount(56088), x1 * y1)
- self.assertEqual(amount(56088), y1 * x1)
- self.assertEqual(amount(56088), x1 * 456)
- self.assertEqual(amount(56088), amount(456) * x1)
- self.assertEqual(amount(56088), 456 * x1)
-
- x1 *= amount(123)
- self.assertEqual(amount(15129), x1)
- x1 *= 123
- self.assertEqual(amount(1860867), x1)
-
- x4 = amount("123456789123456789123456789")
-
- self.assertEqual(amount("15241578780673678546105778281054720515622620750190521"),
- x4 * x4)
-
- self.assertTrue(x1.valid())
- self.assertTrue(y1.valid())
- self.assertTrue(x4.valid())
-
- def testFractionalMultiplication(self):
- x1 = amount(123.123)
- y1 = amount(456.456)
-
- self.assertEqual(amount(0), x1 * 0)
- self.assertEqual(amount(0), amount(0) * x1)
- self.assertEqual(amount(0), 0 * x1)
- self.assertEqual(x1, x1 * 1)
- self.assertEqual(x1, amount(1) * x1)
- self.assertEqual(x1, 1 * x1)
- self.assertEqual(- x1, x1 * -1)
- self.assertEqual(- x1, amount(-1) * x1)
- self.assertEqual(- x1, -1 * x1)
- self.assertEqual(amount("56200.232088"), x1 * y1)
- self.assertEqual(amount("56200.232088"), y1 * x1)
- self.assertEqual(amount("56200.232088"), x1 * 456.456)
- self.assertEqual(amount("56200.232088"), amount(456.456) * x1)
- self.assertEqual(amount("56200.232088"), 456.456 * x1)
-
- x1 *= amount(123.123)
- self.assertEqual(amount("15159.273129"), x1)
- x1 *= 123.123
- self.assertEqual(amount("1866455.185461867"), x1)
- x1 *= 123
- self.assertEqual(amount("229573987.811809641"), x1)
-
- x2 = amount("123456789123456789.123456789123456789")
-
- self.assertEqual(amount("15241578780673678546105778311537878.046486820281054720515622620750190521"),
- x2 * x2)
-
- self.assertTrue(x1.valid())
- self.assertTrue(y1.valid())
- self.assertTrue(x2.valid())
-
- def divideByZero(self, amt):
- return amt / 0
-
- def testIntegerDivision(self):
- x1 = amount(123)
- y1 = amount(456)
-
- self.assertRaises(exceptions.ArithmeticError, self.divideByZero, x1)
- self.assertEqual(amount(0), amount(0) / x1)
- self.assertEqual(amount(0), 0 / x1)
- self.assertEqual(x1, x1 / 1)
- self.assertEqual(amount("0.008130"), amount(1) / x1)
- self.assertEqual(amount("0.008130"), 1 / x1)
- self.assertEqual(- x1, x1 / -1)
- self.assertEqual(- amount("0.008130"), amount(-1) / x1)
- self.assertEqual(- amount("0.008130"), -1 / x1)
- self.assertEqual(amount("0.269737"), x1 / y1)
- self.assertEqual(amount("3.707317"), y1 / x1)
- self.assertEqual(amount("0.269737"), x1 / 456)
- self.assertEqual(amount("3.707317"), amount(456) / x1)
- self.assertEqual(amount("3.707317"), 456 / x1)
-
- x1 /= amount(456)
- self.assertEqual(amount("0.269737"), x1)
- x1 /= 456
- self.assertEqual(amount("0.00059152850877193"), x1)
-
- x4 = amount("123456789123456789123456789")
- y4 = amount("56")
-
- self.assertEqual(amount(1), x4 / x4)
- self.assertEqual(amount("2204585520061728377204585.517857"), x4 / y4)
-
- self.assertTrue(x1.valid())
- self.assertTrue(y1.valid())
- self.assertTrue(x4.valid())
- self.assertTrue(y4.valid())
-
- def testFractionalDivision(self):
- x1 = amount(123.123)
- y1 = amount(456.456)
-
- self.assertRaises(exceptions.ArithmeticError, self.divideByZero, x1)
- self.assertEqual(amount("0.008121959"), amount(1.0) / x1)
- self.assertEqual(amount("0.008121959"), 1.0 / x1)
- self.assertEqual(x1, x1 / 1.0)
- self.assertEqual(amount("0.008121959"), amount(1.0) / x1)
- self.assertEqual(amount("0.008121959"), 1.0 / x1)
- self.assertEqual(- x1, x1 / -1.0)
- self.assertEqual(- amount("0.008121959"), amount(-1.0) / x1)
- self.assertEqual(- amount("0.008121959"), -1.0 / x1)
- self.assertEqual(amount("0.269736842105263"), x1 / y1)
- self.assertEqual(amount("3.707317073170732"), y1 / x1)
- self.assertEqual(amount("0.269736842105263"), x1 / 456.456)
- self.assertEqual(amount("3.707317073170732"), amount(456.456) / x1)
- self.assertEqual(amount("3.707317073170732"), 456.456 / x1)
-
- x1 /= amount(456.456)
- self.assertEqual(amount("0.269736842105263"), x1)
- x1 /= 456.456
- self.assertEqual(amount("0.000590937225286255411255411255411255411"), x1)
- x1 /= 456
- self.assertEqual(amount("0.000001295914967733016252753094858358016252192982456140350877192982456140350877192982"), x1)
-
- x4 = amount("1234567891234567.89123456789")
- y4 = amount("56.789")
-
- self.assertEqual(amount(1.0), x4 / x4)
- self.assertEqual(amount("21739560323910.7554497273748437197344556164046"),
- x4 / y4)
-
- self.assertTrue(x1.valid())
- self.assertTrue(y1.valid())
- self.assertTrue(x4.valid())
- self.assertTrue(y4.valid())
-
- def testIntegerConversion(self):
- x1 = amount(123456)
-
- self.assertTrue(x1)
- self.assertEqual(123456, int(x1))
- self.assertEqual(123456.0, float(x1))
- self.assertEqual("123456", x1.to_string())
- self.assertEqual("123456", x1.quantity_string())
-
- self.assertTrue(x1.valid())
-
- def testFractionalConversion(self):
- x1 = amount(1234.56)
-
- self.assertTrue(x1)
- self.assertRaises(exceptions.ArithmeticError, amount.to_long, x1)
- self.assertEqual(1234, x1.to_long(True))
- self.assertEqual(1234.56, float(x1))
- self.assertEqual("1234.56", x1.to_string())
- self.assertEqual("1234.56", x1.quantity_string())
-
- self.assertTrue(x1.valid())
-
- def testFractionalRound(self):
- x1 = amount("1234.567890")
-
- self.assertEqual(amount("1234.56789"), x1.round(6))
- self.assertEqual(amount("1234.56789"), x1.round(5))
- self.assertEqual(amount("1234.5679"), x1.round(4))
- self.assertEqual(amount("1234.568"), x1.round(3))
- self.assertEqual(amount("1234.57"), x1.round(2))
- self.assertEqual(amount("1234.6"), x1.round(1))
- self.assertEqual(amount("1235"), x1.round(0))
-
- x2 = amount("9876.543210")
-
- self.assertEqual(amount("9876.543210"), x2.round(6))
- self.assertEqual(amount("9876.54321"), x2.round(5))
- self.assertEqual(amount("9876.5432"), x2.round(4))
- self.assertEqual(amount("9876.543"), x2.round(3))
- self.assertEqual(amount("9876.54"), x2.round(2))
- self.assertEqual(amount("9876.5"), x2.round(1))
- self.assertEqual(amount("9877"), x2.round(0))
-
- x3 = amount("-1234.567890")
-
- self.assertEqual(amount("-1234.56789"), x3.round(6))
- self.assertEqual(amount("-1234.56789"), x3.round(5))
- self.assertEqual(amount("-1234.5679"), x3.round(4))
- self.assertEqual(amount("-1234.568"), x3.round(3))
- self.assertEqual(amount("-1234.57"), x3.round(2))
- self.assertEqual(amount("-1234.6"), x3.round(1))
- self.assertEqual(amount("-1235"), x3.round(0))
-
- x4 = amount("-9876.543210")
-
- self.assertEqual(amount("-9876.543210"), x4.round(6))
- self.assertEqual(amount("-9876.54321"), x4.round(5))
- self.assertEqual(amount("-9876.5432"), x4.round(4))
- self.assertEqual(amount("-9876.543"), x4.round(3))
- self.assertEqual(amount("-9876.54"), x4.round(2))
- self.assertEqual(amount("-9876.5"), x4.round(1))
- self.assertEqual(amount("-9877"), x4.round(0))
-
- self.assertTrue(x1.valid())
- self.assertTrue(x2.valid())
- self.assertTrue(x3.valid())
- self.assertTrue(x4.valid())
-
- def testTruth(self):
- x0 = amount()
- x1 = amount("1234")
- x2 = amount("1234.56")
-
- self.assertFalse(x0)
- self.assertTrue(x1)
- self.assertTrue(x2)
-
- self.assertTrue(x0.valid())
- self.assertTrue(x1.valid())
- self.assertTrue(x2.valid())
-
- def testForZero(self):
- x0 = amount()
- x1 = amount("0.000000000000000000001")
-
- self.assertFalse(x0)
- self.assertTrue(x1)
- self.assertTrue(x0.is_zero())
- self.assertTrue(x0.is_realzero())
- self.assertFalse(x1.is_zero())
- self.assertFalse(x1.is_realzero())
-
- self.assertTrue(x0.valid())
- self.assertTrue(x1.valid())
-
- def testComparisons(self):
- x0 = amount()
- x1 = amount(-123)
- x2 = amount(123)
- x3 = amount(-123.45)
- x4 = amount(123.45)
- x5 = amount("-123.45")
- x6 = amount("123.45")
-
- self.assertTrue(x0 > x1)
- self.assertTrue(x0 < x2)
- self.assertTrue(x0 > x3)
- self.assertTrue(x0 < x4)
- self.assertTrue(x0 > x5)
- self.assertTrue(x0 < x6)
-
- self.assertTrue(x1 > x3)
- self.assertTrue(x3 <= x5)
- self.assertTrue(x3 >= x5)
- self.assertTrue(x3 < x1)
- self.assertTrue(x3 < x4)
-
- self.assertTrue(x1 < 100)
- self.assertTrue(x1 < 100.0)
- self.assertTrue(100 > x1)
- self.assertTrue(100.0 > x1)
-
- self.assertTrue(x0.valid())
- self.assertTrue(x1.valid())
- self.assertTrue(x2.valid())
- self.assertTrue(x3.valid())
- self.assertTrue(x4.valid())
- self.assertTrue(x5.valid())
- self.assertTrue(x6.valid())
-
- def testSign(self):
- x0 = amount()
- x1 = amount("0.0000000000000000000000000000000000001")
- x2 = amount("-0.0000000000000000000000000000000000001")
- x3 = amount("1")
- x4 = amount("-1")
-
- self.assertEqual(x0.sign(), 0)
- self.assertTrue(x1.sign() > 0)
- self.assertTrue(x2.sign() < 0)
- self.assertTrue(x3.sign() > 0)
- self.assertTrue(x4.sign() < 0)
-
- self.assertTrue(x0.valid())
- self.assertTrue(x1.valid())
- self.assertTrue(x2.valid())
- self.assertTrue(x3.valid())
- self.assertTrue(x4.valid())
-
- def testAbs(self):
- x0 = amount()
- x1 = amount(-1234)
- x2 = amount(1234)
-
- self.assertEqual(amount(), abs(x0))
- self.assertEqual(amount(1234), abs(x1))
- self.assertEqual(amount(1234), abs(x2))
-
- self.assertTrue(x0.valid())
- self.assertTrue(x1.valid())
- self.assertTrue(x2.valid())
-
- def testPrinting(self):
- pass
-
-
-def suite():
- return unittest.TestLoader().loadTestsFromTestCase(BasicAmountTestCase)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tests/python/numerics/balances/__init__.py b/tests/python/numerics/balances/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/numerics/balances/__init__.py
+++ /dev/null
diff --git a/tests/python/numerics/CommodityAmount.py b/tests/python/numerics/t_amount.py
index 3b7c98a9..70ac0852 100644
--- a/tests/python/numerics/CommodityAmount.py
+++ b/tests/python/numerics/t_amount.py
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
+import sys
+
import unittest
import exceptions
import operator
@@ -8,7 +10,8 @@ from ledger import amount
internalAmount = amount.exact
-class CommodityAmountTestCase(unittest.TestCase):
+
+class AmountTestCase(unittest.TestCase):
def setUp(self):
# Cause the display precision for dollars to be initialized to 2.
x1 = amount("$1.00")
@@ -22,6 +25,523 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertTrue(amt.valid())
def testConstructors(self):
+ x0 = amount()
+ x1 = amount(123456)
+ x2 = amount(123456L)
+ x3 = amount(123.456)
+ x5 = amount("123456")
+ x6 = amount("123.456")
+ x9 = amount(x3)
+ x10 = amount(x6)
+
+ self.assertEqual(amount(0), x0)
+ self.assertEqual(x2, x1)
+ self.assertEqual(x5, x1)
+ self.assertEqual(x6, x3)
+ self.assertEqual(x10, x3)
+ self.assertEqual(x10, x9)
+
+ self.assertValid(x0)
+ self.assertValid(x1)
+ self.assertValid(x2)
+ self.assertValid(x3)
+ self.assertValid(x5)
+ self.assertValid(x6)
+ self.assertValid(x9)
+ self.assertValid(x10)
+
+ def testNegation(self):
+ x0 = amount()
+ x1 = amount(-123456)
+ x3 = amount(-123.456)
+ x5 = amount("-123456")
+ x6 = amount("-123.456")
+ x9 = amount(- x3)
+
+ self.assertEqual(amount(0), x0)
+ self.assertEqual(x5, x1)
+ self.assertEqual(x6, x3)
+ self.assertEqual(- x6, x9)
+ self.assertEqual(x3.negate(), x9)
+
+ x10 = amount(x9.negate())
+
+ self.assertEqual(x3, x10)
+
+ self.assertValid(x0)
+ self.assertValid(x1)
+ self.assertValid(x3)
+ self.assertValid(x5)
+ self.assertValid(x6)
+ self.assertValid(x9)
+ self.assertValid(x10)
+
+ def testAssignment(self):
+ x0 = amount()
+ x1 = amount(123456)
+ x2 = amount(123456L)
+ x3 = amount(123.456)
+ x5 = amount("123456")
+ x6 = amount("123.456")
+ x9 = x3
+ x10 = amount(x6)
+
+ self.assertEqual(amount(0), x0)
+ self.assertEqual(x2, x1)
+ self.assertEqual(x5, x1)
+ self.assertEqual(x6, x3)
+ self.assertEqual(x10, x3)
+ self.assertEqual(x10, x9)
+
+ x0 = amount()
+ x1 = amount(123456)
+ x2 = amount(123456L)
+ x3 = amount(123.456)
+ x5 = amount("123456")
+ x6 = amount("123.456")
+ x9 = x3
+ x10 = amount(x6)
+
+ self.assertEqual(amount(0), x0)
+ self.assertEqual(x2, x1)
+ self.assertEqual(x5, x1)
+ self.assertEqual(x6, x3)
+ self.assertEqual(x10, x3)
+ self.assertEqual(x10, x9)
+
+ self.assertValid(x0)
+ self.assertValid(x1)
+ self.assertValid(x2)
+ self.assertValid(x3)
+ self.assertValid(x5)
+ self.assertValid(x6)
+ self.assertValid(x9)
+ self.assertValid(x10)
+
+ def testEquality(self):
+ x1 = amount(123456)
+ x2 = amount(456789)
+ x3 = amount(333333)
+ x4 = amount(123456.0)
+ x5 = amount("123456.0")
+
+ self.assertTrue(x1 == 123456)
+ self.assertTrue(x1 != x2)
+ self.assertTrue(x1 == (x2 - x3))
+ self.assertTrue(x1 == x4)
+ self.assertTrue(x4 == x5)
+
+ self.assertValid(x1)
+ self.assertValid(x2)
+ self.assertValid(x3)
+ self.assertValid(x4)
+ self.assertValid(x5)
+
+ def testIntegerAddition(self):
+ x1 = amount(123)
+ y1 = amount(456)
+
+ self.assertEqual(amount(579), x1 + y1)
+ self.assertEqual(amount(579), x1 + 456)
+ self.assertEqual(amount(579), 456 + x1)
+
+ x1 += amount(456)
+ self.assertEqual(amount(579), x1)
+ x1 += 456
+ self.assertEqual(amount(1035), x1)
+
+ x4 = amount("123456789123456789123456789")
+
+ self.assertEqual(amount("246913578246913578246913578"), x4 + x4)
+
+ self.assertValid(x1)
+ self.assertValid(y1)
+ self.assertValid(x4)
+
+ def testFractionalAddition(self):
+ x1 = amount(123.123)
+ y1 = amount(456.456)
+
+ self.assertEqual(amount(579.579), x1 + y1)
+ self.assertEqual(amount(579.579), x1 + 456.456)
+ self.assertEqual(amount(579.579), 456.456 + x1)
+
+ x1 += amount(456.456)
+ self.assertEqual(amount(579.579), x1)
+ x1 += 456.456
+ self.assertEqual(amount(1036.035), x1)
+ x1 += 456
+ self.assertEqual(amount(1492.035), x1)
+
+ x2 = amount("123456789123456789.123456789123456789")
+
+ self.assertEqual(amount("246913578246913578.246913578246913578"), x2 + x2)
+
+ self.assertValid(x1)
+ self.assertValid(y1)
+ self.assertValid(x2)
+
+ def testIntegerSubtraction(self):
+ x1 = amount(123)
+ y1 = amount(456)
+
+ self.assertEqual(amount(333), y1 - x1)
+ self.assertEqual(amount(-333), x1 - y1)
+ self.assertEqual(amount(23), x1 - 100)
+ self.assertEqual(amount(-23), 100 - x1)
+
+ x1 -= amount(456)
+ self.assertEqual(amount(-333), x1)
+ x1 -= 456
+ self.assertEqual(amount(-789), x1)
+
+ x4 = amount("123456789123456789123456789")
+ y4 = amount("8238725986235986")
+
+ self.assertEqual(amount("123456789115218063137220803"), x4 - y4)
+ self.assertEqual(amount("-123456789115218063137220803"), y4 - x4)
+
+ self.assertValid(x1)
+ self.assertValid(y1)
+ self.assertValid(x4)
+ self.assertValid(y4)
+
+ def testFractionalSubtraction(self):
+ x1 = amount(123.123)
+ y1 = amount(456.456)
+
+ self.assertEqual(amount(-333.333), x1 - y1)
+ self.assertEqual(amount(333.333), y1 - x1)
+
+ x1 -= amount(456.456)
+ self.assertEqual(amount(-333.333), x1)
+ x1 -= 456.456
+ self.assertEqual(amount(-789.789), x1)
+ x1 -= 456
+ self.assertEqual(amount(-1245.789), x1)
+
+ x2 = amount("123456789123456789.123456789123456789")
+ y2 = amount("9872345982459.248974239578")
+
+ self.assertEqual(amount("123446916777474329.874482549545456789"), x2 - y2)
+ self.assertEqual(amount("-123446916777474329.874482549545456789"), y2 - x2)
+
+ self.assertValid(x1)
+ self.assertValid(y1)
+ self.assertValid(x2)
+ self.assertValid(y2)
+
+ def testIntegerMultiplication(self):
+ x1 = amount(123)
+ y1 = amount(456)
+
+ self.assertEqual(amount(0), x1 * 0)
+ self.assertEqual(amount(0), amount(0) * x1)
+ self.assertEqual(amount(0), 0 * x1)
+ self.assertEqual(x1, x1 * 1)
+ self.assertEqual(x1, amount(1) * x1)
+ self.assertEqual(x1, 1 * x1)
+ self.assertEqual(- x1, x1 * -1)
+ self.assertEqual(- x1, amount(-1) * x1)
+ self.assertEqual(- x1, -1 * x1)
+ self.assertEqual(amount(56088), x1 * y1)
+ self.assertEqual(amount(56088), y1 * x1)
+ self.assertEqual(amount(56088), x1 * 456)
+ self.assertEqual(amount(56088), amount(456) * x1)
+ self.assertEqual(amount(56088), 456 * x1)
+
+ x1 *= amount(123)
+ self.assertEqual(amount(15129), x1)
+ x1 *= 123
+ self.assertEqual(amount(1860867), x1)
+
+ x4 = amount("123456789123456789123456789")
+
+ self.assertEqual(amount("15241578780673678546105778281054720515622620750190521"),
+ x4 * x4)
+
+ self.assertValid(x1)
+ self.assertValid(y1)
+ self.assertValid(x4)
+
+ def testFractionalMultiplication(self):
+ x1 = amount(123.123)
+ y1 = amount(456.456)
+
+ self.assertEqual(amount(0), x1 * 0)
+ self.assertEqual(amount(0), amount(0) * x1)
+ self.assertEqual(amount(0), 0 * x1)
+ self.assertEqual(x1, x1 * 1)
+ self.assertEqual(x1, amount(1) * x1)
+ self.assertEqual(x1, 1 * x1)
+ self.assertEqual(- x1, x1 * -1)
+ self.assertEqual(- x1, amount(-1) * x1)
+ self.assertEqual(- x1, -1 * x1)
+ self.assertEqual(amount("56200.232088"), x1 * y1)
+ self.assertEqual(amount("56200.232088"), y1 * x1)
+ self.assertEqual(amount("56200.232088"), x1 * 456.456)
+ self.assertEqual(amount("56200.232088"), amount(456.456) * x1)
+ self.assertEqual(amount("56200.232088"), 456.456 * x1)
+
+ x1 *= amount(123.123)
+ self.assertEqual(amount("15159.273129"), x1)
+ x1 *= 123.123
+ self.assertEqual(amount("1866455.185461867"), x1)
+ x1 *= 123
+ self.assertEqual(amount("229573987.811809641"), x1)
+
+ x2 = amount("123456789123456789.123456789123456789")
+
+ self.assertEqual(amount("15241578780673678546105778311537878.046486820281054720515622620750190521"),
+ x2 * x2)
+
+ self.assertValid(x1)
+ self.assertValid(y1)
+ self.assertValid(x2)
+
+ def divideByZero(self, amt):
+ return amt / 0
+
+ def testIntegerDivision(self):
+ x1 = amount(123)
+ y1 = amount(456)
+
+ self.assertRaises(exceptions.ArithmeticError, self.divideByZero, x1)
+ self.assertEqual(amount(0), amount(0) / x1)
+ self.assertEqual(amount(0), 0 / x1)
+ self.assertEqual(x1, x1 / 1)
+ self.assertEqual(amount("0.008130"), amount(1) / x1)
+ self.assertEqual(amount("0.008130"), 1 / x1)
+ self.assertEqual(- x1, x1 / -1)
+ self.assertEqual(- amount("0.008130"), amount(-1) / x1)
+ self.assertEqual(- amount("0.008130"), -1 / x1)
+ self.assertEqual(amount("0.269737"), x1 / y1)
+ self.assertEqual(amount("3.707317"), y1 / x1)
+ self.assertEqual(amount("0.269737"), x1 / 456)
+ self.assertEqual(amount("3.707317"), amount(456) / x1)
+ self.assertEqual(amount("3.707317"), 456 / x1)
+
+ x1 /= amount(456)
+ self.assertEqual(amount("0.269737"), x1)
+ x1 /= 456
+ self.assertEqual(amount("0.00059152850877193"), x1)
+
+ x4 = amount("123456789123456789123456789")
+ y4 = amount("56")
+
+ self.assertEqual(amount(1), x4 / x4)
+ self.assertEqual(amount("2204585520061728377204585.517857"), x4 / y4)
+
+ self.assertValid(x1)
+ self.assertValid(y1)
+ self.assertValid(x4)
+ self.assertValid(y4)
+
+ def testFractionalDivision(self):
+ x1 = amount(123.123)
+ y1 = amount(456.456)
+
+ self.assertRaises(exceptions.ArithmeticError, self.divideByZero, x1)
+ self.assertEqual(amount("0.008121959"), amount(1.0) / x1)
+ self.assertEqual(amount("0.008121959"), 1.0 / x1)
+ self.assertEqual(x1, x1 / 1.0)
+ self.assertEqual(amount("0.008121959"), amount(1.0) / x1)
+ self.assertEqual(amount("0.008121959"), 1.0 / x1)
+ self.assertEqual(- x1, x1 / -1.0)
+ self.assertEqual(- amount("0.008121959"), amount(-1.0) / x1)
+ self.assertEqual(- amount("0.008121959"), -1.0 / x1)
+ self.assertEqual(amount("0.269736842105263"), x1 / y1)
+ self.assertEqual(amount("3.707317073170732"), y1 / x1)
+ self.assertEqual(amount("0.269736842105263"), x1 / 456.456)
+ self.assertEqual(amount("3.707317073170732"), amount(456.456) / x1)
+ self.assertEqual(amount("3.707317073170732"), 456.456 / x1)
+
+ x1 /= amount(456.456)
+ self.assertEqual(amount("0.269736842105263"), x1)
+ x1 /= 456.456
+ self.assertEqual(amount("0.000590937225286255411255411255411255411"), x1)
+ x1 /= 456
+ self.assertEqual(amount("0.000001295914967733016252753094858358016252192982456140350877192982456140350877192982"), x1)
+
+ x4 = amount("1234567891234567.89123456789")
+ y4 = amount("56.789")
+
+ self.assertEqual(amount(1.0), x4 / x4)
+ self.assertEqual(amount("21739560323910.7554497273748437197344556164046"),
+ x4 / y4)
+
+ self.assertValid(x1)
+ self.assertValid(y1)
+ self.assertValid(x4)
+ self.assertValid(y4)
+
+ def testIntegerConversion(self):
+ x1 = amount(123456)
+
+ self.assertTrue(x1)
+ self.assertEqual(123456, int(x1))
+ self.assertEqual(123456.0, float(x1))
+ self.assertEqual("123456", x1.to_string())
+ self.assertEqual("123456", x1.quantity_string())
+
+ self.assertValid(x1)
+
+ def testFractionalConversion(self):
+ x1 = amount(1234.56)
+
+ self.assertTrue(x1)
+ self.assertRaises(exceptions.ArithmeticError, amount.to_long, x1)
+ self.assertEqual(1234, x1.to_long(True))
+ self.assertEqual(1234.56, float(x1))
+ self.assertEqual("1234.56", x1.to_string())
+ self.assertEqual("1234.56", x1.quantity_string())
+
+ self.assertValid(x1)
+
+ def testFractionalRound(self):
+ x1 = amount("1234.567890")
+
+ self.assertEqual(amount("1234.56789"), x1.round(6))
+ self.assertEqual(amount("1234.56789"), x1.round(5))
+ self.assertEqual(amount("1234.5679"), x1.round(4))
+ self.assertEqual(amount("1234.568"), x1.round(3))
+ self.assertEqual(amount("1234.57"), x1.round(2))
+ self.assertEqual(amount("1234.6"), x1.round(1))
+ self.assertEqual(amount("1235"), x1.round(0))
+
+ x2 = amount("9876.543210")
+
+ self.assertEqual(amount("9876.543210"), x2.round(6))
+ self.assertEqual(amount("9876.54321"), x2.round(5))
+ self.assertEqual(amount("9876.5432"), x2.round(4))
+ self.assertEqual(amount("9876.543"), x2.round(3))
+ self.assertEqual(amount("9876.54"), x2.round(2))
+ self.assertEqual(amount("9876.5"), x2.round(1))
+ self.assertEqual(amount("9877"), x2.round(0))
+
+ x3 = amount("-1234.567890")
+
+ self.assertEqual(amount("-1234.56789"), x3.round(6))
+ self.assertEqual(amount("-1234.56789"), x3.round(5))
+ self.assertEqual(amount("-1234.5679"), x3.round(4))
+ self.assertEqual(amount("-1234.568"), x3.round(3))
+ self.assertEqual(amount("-1234.57"), x3.round(2))
+ self.assertEqual(amount("-1234.6"), x3.round(1))
+ self.assertEqual(amount("-1235"), x3.round(0))
+
+ x4 = amount("-9876.543210")
+
+ self.assertEqual(amount("-9876.543210"), x4.round(6))
+ self.assertEqual(amount("-9876.54321"), x4.round(5))
+ self.assertEqual(amount("-9876.5432"), x4.round(4))
+ self.assertEqual(amount("-9876.543"), x4.round(3))
+ self.assertEqual(amount("-9876.54"), x4.round(2))
+ self.assertEqual(amount("-9876.5"), x4.round(1))
+ self.assertEqual(amount("-9877"), x4.round(0))
+
+ self.assertValid(x1)
+ self.assertValid(x2)
+ self.assertValid(x3)
+ self.assertValid(x4)
+
+ def testTruth(self):
+ x0 = amount()
+ x1 = amount("1234")
+ x2 = amount("1234.56")
+
+ self.assertFalse(x0)
+ self.assertTrue(x1)
+ self.assertTrue(x2)
+
+ self.assertValid(x0)
+ self.assertValid(x1)
+ self.assertValid(x2)
+
+ def testForZero(self):
+ x0 = amount()
+ x1 = amount("0.000000000000000000001")
+
+ self.assertFalse(x0)
+ self.assertTrue(x1)
+ self.assertTrue(x0.is_zero())
+ self.assertTrue(x0.is_realzero())
+ self.assertFalse(x1.is_zero())
+ self.assertFalse(x1.is_realzero())
+
+ self.assertValid(x0)
+ self.assertValid(x1)
+
+ def testComparisons(self):
+ x0 = amount()
+ x1 = amount(-123)
+ x2 = amount(123)
+ x3 = amount(-123.45)
+ x4 = amount(123.45)
+ x5 = amount("-123.45")
+ x6 = amount("123.45")
+
+ self.assertTrue(x0 > x1)
+ self.assertTrue(x0 < x2)
+ self.assertTrue(x0 > x3)
+ self.assertTrue(x0 < x4)
+ self.assertTrue(x0 > x5)
+ self.assertTrue(x0 < x6)
+
+ self.assertTrue(x1 > x3)
+ self.assertTrue(x3 <= x5)
+ self.assertTrue(x3 >= x5)
+ self.assertTrue(x3 < x1)
+ self.assertTrue(x3 < x4)
+
+ self.assertTrue(x1 < 100)
+ self.assertTrue(x1 < 100.0)
+ self.assertTrue(100 > x1)
+ self.assertTrue(100.0 > x1)
+
+ self.assertValid(x0)
+ self.assertValid(x1)
+ self.assertValid(x2)
+ self.assertValid(x3)
+ self.assertValid(x4)
+ self.assertValid(x5)
+ self.assertValid(x6)
+
+ def testSign(self):
+ x0 = amount()
+ x1 = amount("0.0000000000000000000000000000000000001")
+ x2 = amount("-0.0000000000000000000000000000000000001")
+ x3 = amount("1")
+ x4 = amount("-1")
+
+ self.assertEqual(x0.sign(), 0)
+ self.assertTrue(x1.sign() > 0)
+ self.assertTrue(x2.sign() < 0)
+ self.assertTrue(x3.sign() > 0)
+ self.assertTrue(x4.sign() < 0)
+
+ self.assertValid(x0)
+ self.assertValid(x1)
+ self.assertValid(x2)
+ self.assertValid(x3)
+ self.assertValid(x4)
+
+ def testAbs(self):
+ x0 = amount()
+ x1 = amount(-1234)
+ x2 = amount(1234)
+
+ self.assertEqual(amount(), abs(x0))
+ self.assertEqual(amount(1234), abs(x1))
+ self.assertEqual(amount(1234), abs(x2))
+
+ self.assertValid(x0)
+ self.assertValid(x1)
+ self.assertValid(x2)
+
+ def testPrinting(self):
+ pass
+
+ def testCommodityConstructors(self):
x1 = amount("$123.45")
x2 = amount("-$123.45")
x3 = amount("$-123.45")
@@ -66,7 +586,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x9)
self.assertValid(x10)
- def testNegation(self):
+ def testCommodityNegation(self):
x1 = amount("$123.45")
x2 = amount("-$123.45")
x3 = amount("$-123.45")
@@ -119,7 +639,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x9)
self.assertValid(x10)
- def testAssignment(self):
+ def testCommodityAssignment(self):
x1 = amount("$123.45")
x2 = amount("-$123.45")
x3 = amount("$-123.45")
@@ -164,7 +684,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x9)
self.assertValid(x10)
- def testEquality(self):
+ def testCommodityEquality(self):
x0 = amount()
x1 = amount("$123.45")
x2 = amount("-$123.45")
@@ -207,7 +727,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x9)
self.assertValid(x10)
- def testAddition(self):
+ def testCommodityAddition(self):
x0 = amount()
x1 = amount("$123.45")
x2 = amount(internalAmount("$123.456789"))
@@ -259,7 +779,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x6)
self.assertValid(x7)
- def testSubtraction(self):
+ def testCommoditySubtraction(self):
x0 = amount()
x1 = amount("$123.45")
x2 = amount(internalAmount("$123.456789"))
@@ -336,7 +856,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x7)
self.assertValid(x8)
- def testMultiplication(self):
+ def testCommodityMultiplication(self):
x1 = amount("$123.12")
y1 = amount("$456.45")
x2 = amount(internalAmount("$123.456789"))
@@ -388,7 +908,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x5)
self.assertValid(x7)
- def testDivision(self):
+ def testCommodityDivision(self):
x1 = amount("$123.12")
y1 = amount("$456.45")
x2 = amount(internalAmount("$123.456789"))
@@ -445,7 +965,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x6)
self.assertValid(x7)
- def testConversion(self):
+ def testCommodityConversion(self):
x1 = amount("$1234.56")
self.assertEqual(True, bool(x1))
@@ -457,7 +977,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x1)
- def testRound(self):
+ def testCommodityRound(self):
x1 = amount(internalAmount("$1234.567890"))
self.assertEqual(internalAmount("$1234.56789"), x1.round(6))
@@ -503,7 +1023,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x3)
self.assertValid(x4)
- def testDisplayRound(self):
+ def testCommodityDisplayRound(self):
x1 = amount("$0.85")
x2 = amount("$0.1")
@@ -523,7 +1043,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertEqual(internalAmount("$1.1305"), x1)
self.assertEqual("$1.13", x1.to_string())
- def testTruth(self):
+ def testCommodityTruth(self):
x1 = amount("$1234")
x2 = amount("$1234.56")
@@ -540,7 +1060,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x1)
self.assertValid(x2)
- def testForZero(self):
+ def testCommodityForZero(self):
x1 = amount(internalAmount("$0.000000000000000000001"))
self.assertFalse(x1)
@@ -549,7 +1069,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x1)
- def testComparisons(self):
+ def testCommodityComparisons(self):
x0 = amount()
x1 = amount("$-123")
x2 = amount("$123.00")
@@ -581,7 +1101,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x5)
self.assertValid(x6)
- def testSign(self):
+ def testCommoditySign(self):
x0 = amount()
x1 = amount(internalAmount("$0.0000000000000000000000000000000000001"))
x2 = amount(internalAmount("$-0.0000000000000000000000000000000000001"))
@@ -600,7 +1120,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x3)
self.assertValid(x4)
- def testAbs(self):
+ def testCommodityAbs(self):
x0 = amount()
x1 = amount("$-1234.56")
x2 = amount("$1234.56")
@@ -613,12 +1133,12 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x1)
self.assertValid(x2)
- def testPrinting(self):
+ def testCommodityPrinting(self):
pass
def suite():
- return unittest.TestLoader().loadTestsFromTestCase(CommodityAmountTestCase)
+ return unittest.TestLoader().loadTestsFromTestCase(AmountTestCase)
if __name__ == '__main__':
unittest.main()
diff --git a/tests/python/numerics/values/__init__.py b/tests/python/numerics/values/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/numerics/values/__init__.py
+++ /dev/null
diff --git a/tests/python/parsers/__init__.py b/tests/python/parsers/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/parsers/__init__.py
+++ /dev/null
diff --git a/tests/python/parsers/binary/__init__.py b/tests/python/parsers/binary/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/parsers/binary/__init__.py
+++ /dev/null
diff --git a/tests/python/parsers/gnucash/__init__.py b/tests/python/parsers/gnucash/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/parsers/gnucash/__init__.py
+++ /dev/null
diff --git a/tests/python/parsers/ofx/__init__.py b/tests/python/parsers/ofx/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/parsers/ofx/__init__.py
+++ /dev/null
diff --git a/tests/python/parsers/qif/__init__.py b/tests/python/parsers/qif/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/parsers/qif/__init__.py
+++ /dev/null
diff --git a/tests/python/parsers/textual/__init__.py b/tests/python/parsers/textual/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/parsers/textual/__init__.py
+++ /dev/null
diff --git a/tests/python/python/__init__.py b/tests/python/python/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/python/__init__.py
+++ /dev/null
diff --git a/tests/python/reports/__init__.py b/tests/python/reports/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/reports/__init__.py
+++ /dev/null
diff --git a/tests/python/reports/balance/__init__.py b/tests/python/reports/balance/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/reports/balance/__init__.py
+++ /dev/null
diff --git a/tests/python/reports/emacs/__init__.py b/tests/python/reports/emacs/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/reports/emacs/__init__.py
+++ /dev/null
diff --git a/tests/python/reports/equity/__init__.py b/tests/python/reports/equity/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/reports/equity/__init__.py
+++ /dev/null
diff --git a/tests/python/reports/print/__init__.py b/tests/python/reports/print/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/reports/print/__init__.py
+++ /dev/null
diff --git a/tests/python/reports/register/__init__.py b/tests/python/reports/register/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/reports/register/__init__.py
+++ /dev/null
diff --git a/tests/python/transforms/__init__.py b/tests/python/transforms/__init__.py
deleted file mode 100644
index e69de29b..00000000
--- a/tests/python/transforms/__init__.py
+++ /dev/null