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

Last change on this file since 1355 was 1286, checked in by wouter, 3 weeks ago

#404 fix safehash

File size: 621 bytes
RevLine 
[1055]1import unittest
2from tudelft.utilities.tools.safehash import safehash
3
[1075]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
[1055]14class SafeHashTest(unittest.TestCase):
[1075]15
[1055]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)})
[1057]23
24 h1= safehash({'a':1})
25 h2= safehash({'a':2})
26 self.assertNotEqual(h1,h2)
[1059]27
28 h1= safehash({'a':1,'b':2})
29 h2= safehash({'b':2,'a':1})
30 self.assertEqual(h1,h2)
31
[1075]32 self.assertEqual(2, safehash(B()))
[1059]33
[1055]34 # you can a set in a set...
35 #safehash(set([set(lst)]))
36
[1286]37 safehash(A)
Note: See TracBrowser for help on using the repository browser.