]> granicus.if.org Git - python/commitdiff
Test the logic for int(d).
authorRaymond Hettinger <python@rcn.com>
Mon, 5 Jul 2004 18:49:38 +0000 (18:49 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 5 Jul 2004 18:49:38 +0000 (18:49 +0000)
Lib/test/test_decimal.py

index 7bfb13c385e0bc98a1f387c513279a3b0a1c8a5e..51b352802352ff2effa1bb5c8b0f5a430f11c448 100644 (file)
@@ -1058,6 +1058,16 @@ class DecimalPythonAPItests(unittest.TestCase):
         e = pickle.loads(p)
         self.assertEqual(d, e)
 
+    def test_int(self):
+        data = '1.0 1.1 1.9 2.0 0.0 -1.0 -1.1 -1.9 -2.0'.split()
+        for s in data:
+            # should work the same as for floats
+            self.assertEqual(int(Decimal(s)), int(float(s)))
+            # should work the same as ROUND_DOWN
+            d = Decimal(s)
+            r = Context(prec=1, rounding=ROUND_DOWN).create_decimal(s)
+            self.assertEqual(Decimal(int(d)), r)
+
 class ContextAPItests(unittest.TestCase):
 
     def test_pickle(self):