summaryrefslogtreecommitdiff
path: root/tests/python
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-04-17 07:33:36 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:35:36 -0400
commit0f2cad4cab7ef99e1ad33be34ea813213da7288d (patch)
tree0dbd64dfdb1022d811d2dfdc5f3693f5faafafb8 /tests/python
parent2e3082e734362fb934ff8f308fe9fd9f85c35032 (diff)
downloadfork-ledger-0f2cad4cab7ef99e1ad33be34ea813213da7288d.tar.gz
fork-ledger-0f2cad4cab7ef99e1ad33be34ea813213da7288d.tar.bz2
fork-ledger-0f2cad4cab7ef99e1ad33be34ea813213da7288d.zip
Got most of the commodity tests working, save multiplication and division.
Diffstat (limited to 'tests/python')
-rw-r--r--tests/python/UnitTests.py2
-rw-r--r--tests/python/corelib/numerics/BasicAmount.py101
-rw-r--r--tests/python/corelib/numerics/CommodityAmount.py4
3 files changed, 104 insertions, 3 deletions
diff --git a/tests/python/UnitTests.py b/tests/python/UnitTests.py
index 981d2827..7a10c9e6 100644
--- a/tests/python/UnitTests.py
+++ b/tests/python/UnitTests.py
@@ -1,9 +1,11 @@
from unittest import TextTestRunner, TestSuite
import tests.python.corelib.numerics.BasicAmount as BasicAmount
+import tests.python.corelib.numerics.CommodityAmount as CommodityAmount
suites = [
BasicAmount.suite(),
+ CommodityAmount.suite(),
]
TextTestRunner().run(TestSuite(suites))
diff --git a/tests/python/corelib/numerics/BasicAmount.py b/tests/python/corelib/numerics/BasicAmount.py
index ce6479a2..38cfacca 100644
--- a/tests/python/corelib/numerics/BasicAmount.py
+++ b/tests/python/corelib/numerics/BasicAmount.py
@@ -3,7 +3,6 @@ import exceptions
from ledger import amount
-
class BasicAmountTestCase(unittest.TestCase):
def testConstructors(self):
x0 = amount()
@@ -53,6 +52,14 @@ class BasicAmountTestCase(unittest.TestCase):
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)
@@ -90,6 +97,16 @@ class BasicAmountTestCase(unittest.TestCase):
self.assertEqual(amount(1), x4)
self.assertEqual(x10, x9)
+ 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())
+ self.assertTrue(x9.valid())
+ self.assertTrue(x10.valid())
+
def testEquality(self):
x1 = amount(123456)
x2 = amount(456789)
@@ -103,6 +120,12 @@ class BasicAmountTestCase(unittest.TestCase):
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)
@@ -126,6 +149,12 @@ class BasicAmountTestCase(unittest.TestCase):
self.assertEqual(amount("246913578246913578246913578"), x4 + x4)
+ self.assertTrue(x1.valid())
+ self.assertTrue(y1.valid())
+ self.assertTrue(x3.valid())
+ self.assertTrue(y3.valid())
+ self.assertTrue(x4.valid())
+
def testFractionalAddition(self):
x1 = amount(123.123)
y1 = amount(456.456)
@@ -145,6 +174,10 @@ class BasicAmountTestCase(unittest.TestCase):
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)
@@ -170,6 +203,13 @@ class BasicAmountTestCase(unittest.TestCase):
self.assertEqual(amount("123456789115218063137220803"), x4 - y4)
self.assertEqual(amount("-123456789115218063137220803"), y4 - x4)
+ self.assertTrue(x1.valid())
+ self.assertTrue(y1.valid())
+ self.assertTrue(x3.valid())
+ self.assertTrue(y3.valid())
+ self.assertTrue(x4.valid())
+ self.assertTrue(y4.valid())
+
def testFractionalSubtraction(self):
x1 = amount(123.123)
y1 = amount(456.456)
@@ -190,6 +230,11 @@ class BasicAmountTestCase(unittest.TestCase):
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)
@@ -224,6 +269,12 @@ class BasicAmountTestCase(unittest.TestCase):
self.assertEqual(amount("15241578780673678546105778281054720515622620750190521"),
x4 * x4)
+ self.assertTrue(x1.valid())
+ self.assertTrue(y1.valid())
+ self.assertTrue(x3.valid())
+ self.assertTrue(y3.valid())
+ self.assertTrue(x4.valid())
+
def testFractionalMultiplication(self):
x1 = amount(123.123)
y1 = amount(456.456)
@@ -255,6 +306,10 @@ class BasicAmountTestCase(unittest.TestCase):
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
@@ -288,6 +343,11 @@ class BasicAmountTestCase(unittest.TestCase):
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)
@@ -321,6 +381,11 @@ class BasicAmountTestCase(unittest.TestCase):
self.assertEqual(amount("21739560323910.7554497273748437197344556164"),
x4 / y4)
+ self.assertTrue(x1.valid())
+ self.assertTrue(y1.valid())
+ self.assertTrue(x4.valid())
+ self.assertTrue(y4.valid())
+
def testIntegerConversion(self):
x1 = amount(123456)
@@ -330,6 +395,8 @@ class BasicAmountTestCase(unittest.TestCase):
self.assertEqual("123456", x1.to_string())
self.assertEqual("123456", x1.quantity_string())
+ self.assertTrue(x1.valid())
+
def testFractionalConversion(self):
x1 = amount(1234.56)
@@ -339,6 +406,8 @@ class BasicAmountTestCase(unittest.TestCase):
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")
@@ -380,6 +449,11 @@ class BasicAmountTestCase(unittest.TestCase):
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")
@@ -389,6 +463,10 @@ class BasicAmountTestCase(unittest.TestCase):
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")
@@ -400,6 +478,9 @@ class BasicAmountTestCase(unittest.TestCase):
self.assertTrue(not x1.zero())
self.assertTrue(not x1.realzero())
+ self.assertTrue(x0.valid())
+ self.assertTrue(x1.valid())
+
def testComparisons(self):
x0 = amount()
x1 = amount(-123)
@@ -422,6 +503,14 @@ class BasicAmountTestCase(unittest.TestCase):
self.assertTrue(x3 < x1)
self.assertTrue(x3 < x4)
+ 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")
@@ -435,6 +524,12 @@ class BasicAmountTestCase(unittest.TestCase):
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)
@@ -452,6 +547,10 @@ class BasicAmountTestCase(unittest.TestCase):
self.assertEqual(amount(1234), x1)
self.assertEqual(amount(1234), x2)
+ self.assertTrue(x0.valid())
+ self.assertTrue(x1.valid())
+ self.assertTrue(x2.valid())
+
def testPrinting(self):
pass
diff --git a/tests/python/corelib/numerics/CommodityAmount.py b/tests/python/corelib/numerics/CommodityAmount.py
index ce6479a2..1a32243f 100644
--- a/tests/python/corelib/numerics/CommodityAmount.py
+++ b/tests/python/corelib/numerics/CommodityAmount.py
@@ -4,7 +4,7 @@ import exceptions
from ledger import amount
-class BasicAmountTestCase(unittest.TestCase):
+class CommodityAmountTestCase(unittest.TestCase):
def testConstructors(self):
x0 = amount()
x1 = amount(123456)
@@ -457,7 +457,7 @@ class BasicAmountTestCase(unittest.TestCase):
def suite():
- return unittest.TestLoader().loadTestsFromTestCase(BasicAmountTestCase)
+ return unittest.TestLoader().loadTestsFromTestCase(CommodityAmountTestCase)
if __name__ == '__main__':
unittest.main()