home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / TEST_HASH.PY < prev    next >
Encoding:
Text File  |  2000-09-28  |  531 b   |  27 lines

  1. # test the invariant that
  2. #   iff a==b then hash(a)==hash(b)
  3. #
  4.  
  5. import test_support
  6.  
  7.  
  8. def same_hash(*objlist):
  9.     # hash each object given an raise TestFailed if
  10.     # the hash values are not all the same
  11.     hashed = map(hash, objlist)
  12.     for h in hashed[1:]:
  13.         if h != hashed[0]:
  14.             raise TestFailed, "hashed values differ: %s" % `objlist`
  15.  
  16.  
  17.  
  18. same_hash(1, 1L, 1.0, 1.0+0.0j)
  19. same_hash(int(1), long(1), float(1), complex(1))
  20.  
  21. same_hash(long(1.23e300), float(1.23e300))
  22.  
  23. same_hash(float(0.5), complex(0.5, 0.0))
  24.  
  25.  
  26.  
  27.