source: utilitiespy/test/tools/safehashtest.py@ 1206

Last change on this file since 1206 was 1075, checked in by wouter, 4 months ago

#357 fix in safehash making it compatible with super() as argument -- just use hash instead of hash()

File size: 610 bytes
Line 
1import unittest
2from tudelft.utilities.tools.safehash import safehash
3
4
5class A:
6 def __hash__(self):
7 return 1
8
9class B(A):
10 def __hash__(self):
11 return safehash(super())+1
12
13
14class SafeHashTest(unittest.TestCase):
15
16
17 def tests(self):
18 lst=[1,2,3]
19 safehash(lst)
20 safehash({'a':1})
21 safehash( set(lst))
22 safehash({'a':set(lst)})
23
24 h1= safehash({'a':1})
25 h2= safehash({'a':2})
26 self.assertNotEqual(h1,h2)
27
28 h1= safehash({'a':1,'b':2})
29 h2= safehash({'b':2,'a':1})
30 self.assertEqual(h1,h2)
31
32 self.assertEqual(2, safehash(B()))
33
34 # you can a set in a set...
35 #safehash(set([set(lst)]))
36
37
Note: See TracBrowser for help on using the repository browser.