summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_decimal.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-07-05 22:53:03 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-07-05 22:53:03 (GMT)
commit0aeac107cadd1472e5ea109f7f29e6a6527ae1ec (patch)
tree4d0d33fdc1199cdc32794cdfcc20b2f90a44f4b9 /Lib/test/test_decimal.py
parent10959b1c2acb48ebcdc909421354543043cfd671 (diff)
downloadcpython-0aeac107cadd1472e5ea109f7f29e6a6527ae1ec.zip
cpython-0aeac107cadd1472e5ea109f7f29e6a6527ae1ec.tar.gz
cpython-0aeac107cadd1472e5ea109f7f29e6a6527ae1ec.tar.bz2
* Add __eq__ and __ne__ so that things like list.index() work properly
for lists of mixed types. * Test that sort works.
Diffstat (limited to 'Lib/test/test_decimal.py')
-rw-r--r--Lib/test/test_decimal.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index 51b3528..a03b784 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -33,6 +33,7 @@ import pickle, copy
from decimal import *
from test.test_support import TestSkipped, run_unittest, run_doctest, is_resource_enabled
import threading
+import random
# Tests are built around these assumed context defaults
DefaultContext.prec=9
@@ -841,17 +842,17 @@ class DecimalUsabilityTest(unittest.TestCase):
self.assertEqual(cmp(dc,45), 0)
#a Decimal and uncomparable
- try: da == 'ugly'
- except TypeError: pass
- else: self.fail('Did not raised an error!')
-
- try: da == '32.7'
- except TypeError: pass
- else: self.fail('Did not raised an error!')
-
- try: da == object
- except TypeError: pass
- else: self.fail('Did not raised an error!')
+ self.assertNotEqual(da, 'ugly')
+ self.assertNotEqual(da, 32.7)
+ self.assertNotEqual(da, object())
+ self.assertNotEqual(da, object)
+
+ # sortable
+ a = map(Decimal, xrange(100))
+ b = a[:]
+ random.shuffle(a)
+ a.sort()
+ self.assertEqual(a, b)
def test_copy_and_deepcopy_methods(self):
d = Decimal('43.24')
@@ -1078,6 +1079,10 @@ class ContextAPItests(unittest.TestCase):
v2 = vars(e)[k]
self.assertEqual(v1, v2)
+ def test_equality_with_other_types(self):
+ self.assert_(Decimal(10) in ['a', 1.0, Decimal(10), (1,2), {}])
+ self.assert_(Decimal(10) not in ['a', 1.0, (1,2), {}])
+
def test_main(arith=False, verbose=None):
""" Execute the tests.