Last change
on this file since 1269 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
|
Rev | Line | |
---|
[1055] | 1 | import unittest
|
---|
| 2 | from tudelft.utilities.tools.safehash import safehash
|
---|
| 3 |
|
---|
[1075] | 4 |
|
---|
| 5 | class A:
|
---|
| 6 | def __hash__(self):
|
---|
| 7 | return 1
|
---|
| 8 |
|
---|
| 9 | class B(A):
|
---|
| 10 | def __hash__(self):
|
---|
| 11 | return safehash(super())+1
|
---|
| 12 |
|
---|
| 13 |
|
---|
[1055] | 14 | class 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 |
|
---|
| 37 | |
---|
Note:
See
TracBrowser
for help on using the repository browser.