PyXR

c:\python24\lib \ test \ test_hash.py



0001 # test the invariant that
0002 #   iff a==b then hash(a)==hash(b)
0003 #
0004 
0005 import unittest
0006 from test import test_support
0007 
0008 
0009 class HashEqualityTestCase(unittest.TestCase):
0010 
0011     def same_hash(self, *objlist):
0012         # Hash each object given and fail if
0013         # the hash values are not all the same.
0014         hashed = map(hash, objlist)
0015         for h in hashed[1:]:
0016             if h != hashed[0]:
0017                 self.fail("hashed values differ: %r" % (objlist,))
0018 
0019     def test_numeric_literals(self):
0020         self.same_hash(1, 1L, 1.0, 1.0+0.0j)
0021 
0022     def test_coerced_integers(self):
0023         self.same_hash(int(1), long(1), float(1), complex(1),
0024                        int('1'), float('1.0'))
0025 
0026     def test_coerced_floats(self):
0027         self.same_hash(long(1.23e300), float(1.23e300))
0028         self.same_hash(float(0.5), complex(0.5, 0.0))
0029 
0030 
0031 def test_main():
0032     test_support.run_unittest(HashEqualityTestCase)
0033 
0034 
0035 if __name__ == "__main__":
0036     test_main()
0037 

Generated by PyXR 0.9.4
SourceForge.net Logo