summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-04-17 07:33:56 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:35:36 -0400
commitf63ce064612b0fb98b21ff3e36203c56fb081a7c (patch)
tree93765cc9138df581e5f0e879f2aa1a813782e0d2 /tests
parentf5956311af0425b6d1fd76752e84bd81a4c8ccd1 (diff)
downloadfork-ledger-f63ce064612b0fb98b21ff3e36203c56fb081a7c.tar.gz
fork-ledger-f63ce064612b0fb98b21ff3e36203c56fb081a7c.tar.bz2
fork-ledger-f63ce064612b0fb98b21ff3e36203c56fb081a7c.zip
Added stubs for several more commodity tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/corelib/numerics/CommodityAmount.cc53
-rw-r--r--tests/corelib/numerics/CommodityAmount.h8
-rw-r--r--tests/python/corelib/numerics/CommodityAmount.py22
3 files changed, 83 insertions, 0 deletions
diff --git a/tests/corelib/numerics/CommodityAmount.cc b/tests/corelib/numerics/CommodityAmount.cc
index b2429fc3..0eca3140 100644
--- a/tests/corelib/numerics/CommodityAmount.cc
+++ b/tests/corelib/numerics/CommodityAmount.cc
@@ -91,6 +91,10 @@ void CommodityAmountTestCase::testNegation()
assertEqual(amount_t("-123.45€"), - x9);
assertEqual(amount_t("123.45€"), - x10);
+ assertEqual(amount_t("$-123.45"), x1.negated());
+ assertEqual(amount_t("$123.45"), x2.negated());
+ assertEqual(amount_t("$123.45"), x3.negated());
+
assertEqual(std::string("$-123.45"), (- x1).to_string());
assertEqual(std::string("$123.45"), (- x2).to_string());
assertEqual(std::string("$123.45"), (- x3).to_string());
@@ -102,6 +106,14 @@ void CommodityAmountTestCase::testNegation()
assertEqual(std::string("-123.45€"), (- x9).to_string());
assertEqual(std::string("123.45€"), (- x10).to_string());
+ x1.negate();
+ x2.negate();
+ x3.negate();
+
+ assertEqual(amount_t("$-123.45"), x1);
+ assertEqual(amount_t("$123.45"), x2);
+ assertEqual(amount_t("$123.45"), x3);
+
assertValid(x1);
assertValid(x2);
assertValid(x3);
@@ -163,6 +175,7 @@ void CommodityAmountTestCase::testAssignment()
void CommodityAmountTestCase::testEquality()
{
+ amount_t x0;
amount_t x1 = "$123.45";
amount_t x2 = "-$123.45";
amount_t x3 = "$-123.45";
@@ -174,6 +187,14 @@ void CommodityAmountTestCase::testEquality()
amount_t x9 = "123.45€";
amount_t x10 = "-123.45€";
+ assertTrue(x0.null());
+ assertTrue(x0.zero());
+ assertTrue(x0.realzero());
+ assertTrue(x0.sign() == 0);
+ assertTrue(x0.compare(x1) < 0);
+ assertTrue(x0.compare(x2) > 0);
+ assertTrue(x0.compare(x0) == 0);
+
assertTrue(x1 != x2);
assertTrue(x1 != x4);
assertTrue(x1 != x7);
@@ -184,6 +205,7 @@ void CommodityAmountTestCase::testEquality()
assertTrue(x7 == - x8);
assertTrue(x9 == - x10);
+ assertValid(x0);
assertValid(x1);
assertValid(x2);
assertValid(x3);
@@ -497,10 +519,20 @@ void CommodityAmountTestCase::testRound()
assertEqual(amount_t("$-9876.5"), x4.round(1));
assertEqual(amount_t("$-9877"), x4.round(0));
+ amount_t x5("$123.45");
+
+ x5 *= 100.12;
+
+ assertEqual(internalAmount("$12359.814"), x5);
+ assertEqual(std::string("$12359.81"), x5.to_string());
+ assertEqual(std::string("$12359.814"), x5.to_fullstring());
+ assertEqual(std::string("$12359.814"), x5.unround().to_string());
+
assertValid(x1);
assertValid(x2);
assertValid(x3);
assertValid(x4);
+ assertValid(x5);
}
void CommodityAmountTestCase::testDisplayRound()
@@ -633,6 +665,26 @@ void CommodityAmountTestCase::testAbs()
assertValid(x2);
}
+void CommodityAmountTestCase::testPriceHistory()
+{
+ // jww (2007-04-17): tbd
+}
+
+void CommodityAmountTestCase::testLots()
+{
+ // jww (2007-04-17): tbd
+}
+
+void CommodityAmountTestCase::testScalingBase()
+{
+ // jww (2007-04-17): tbd
+}
+
+void CommodityAmountTestCase::testReduction()
+{
+ // jww (2007-04-17): tbd
+}
+
void CommodityAmountTestCase::testPrinting()
{
amount_t x0;
@@ -673,3 +725,4 @@ void CommodityAmountTestCase::testPrinting()
assertValid(x1);
assertValid(x2);
}
+
diff --git a/tests/corelib/numerics/CommodityAmount.h b/tests/corelib/numerics/CommodityAmount.h
index 5ffa7810..70d55de4 100644
--- a/tests/corelib/numerics/CommodityAmount.h
+++ b/tests/corelib/numerics/CommodityAmount.h
@@ -24,6 +24,10 @@ class CommodityAmountTestCase : public CPPUNIT_NS::TestCase
CPPUNIT_TEST(testSign);
CPPUNIT_TEST(testAbs);
CPPUNIT_TEST(testPrinting);
+ CPPUNIT_TEST(testPriceHistory);
+ CPPUNIT_TEST(testLots);
+ CPPUNIT_TEST(testScalingBase);
+ CPPUNIT_TEST(testReduction);
CPPUNIT_TEST_SUITE_END();
@@ -51,6 +55,10 @@ public:
void testSign();
void testAbs();
void testPrinting();
+ void testPriceHistory();
+ void testLots();
+ void testScalingBase();
+ void testReduction();
private:
CommodityAmountTestCase(const CommodityAmountTestCase &copy);
diff --git a/tests/python/corelib/numerics/CommodityAmount.py b/tests/python/corelib/numerics/CommodityAmount.py
index 286418eb..417652e4 100644
--- a/tests/python/corelib/numerics/CommodityAmount.py
+++ b/tests/python/corelib/numerics/CommodityAmount.py
@@ -90,6 +90,10 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertEqual(amount("-123.45€"), - x9)
self.assertEqual(amount("123.45€"), - x10)
+ self.assertEqual(amount("$-123.45"), x1.negated())
+ self.assertEqual(amount("$123.45"), x2.negated())
+ self.assertEqual(amount("$123.45"), x3.negated())
+
self.assertEqual("$-123.45", (- x1).to_string())
self.assertEqual("$123.45", (- x2).to_string())
self.assertEqual("$123.45", (- x3).to_string())
@@ -101,6 +105,14 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertEqual("-123.45€", (- x9).to_string())
self.assertEqual("123.45€", (- x10).to_string())
+ x1.negate()
+ x2.negate()
+ x3.negate()
+
+ self.assertEqual(amount("$-123.45"), x1)
+ self.assertEqual(amount("$123.45"), x2)
+ self.assertEqual(amount("$123.45"), x3)
+
self.assertValid(x1)
self.assertValid(x2)
self.assertValid(x3)
@@ -158,6 +170,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertValid(x10)
def testEquality(self):
+ x0 = amount()
x1 = amount("$123.45")
x2 = amount("-$123.45")
x3 = amount("$-123.45")
@@ -169,6 +182,14 @@ class CommodityAmountTestCase(unittest.TestCase):
x9 = amount("123.45€")
x10 = amount("-123.45€")
+ self.assertTrue(x0.null())
+ self.assertTrue(x0.zero())
+ self.assertTrue(x0.realzero())
+ self.assertTrue(x0.sign() == 0)
+ self.assertTrue(x0.compare(x1) < 0)
+ self.assertTrue(x0.compare(x2) > 0)
+ self.assertTrue(x0.compare(x0) == 0)
+
self.assertTrue(x1 != x2)
self.assertTrue(x1 != x4)
self.assertTrue(x1 != x7)
@@ -179,6 +200,7 @@ class CommodityAmountTestCase(unittest.TestCase):
self.assertTrue(x7 == - x8)
self.assertTrue(x9 == - x10)
+ self.assertValid(x0)
self.assertValid(x1)
self.assertValid(x2)
self.assertValid(x3)