Author: Mark Pearse <[email protected]>
Branch: SpecialisedTuples
Changeset: r49081:79188abd9668
Date: 2011-11-04 18:02 +0100
http://bitbucket.org/pypy/pypy/changeset/79188abd9668/

Log:    (antocuni, mwp) test_hash_against_normal_tuple passes

diff --git a/pypy/objspace/std/specialisedtupleobject.py 
b/pypy/objspace/std/specialisedtupleobject.py
--- a/pypy/objspace/std/specialisedtupleobject.py
+++ b/pypy/objspace/std/specialisedtupleobject.py
@@ -55,7 +55,18 @@
         return [self.space.wrap(self.intval0), self.space.wrap(self.intval1)]
         
     def hash(self, space):
-        return space.wrap(0)
+        mult = 1000003
+        x = 0x345678
+        z = 2
+        for intval in [self.intval0, self.intval1]:
+            # we assume that hash value of an intger is the integer itself
+            # look at intobject.py hash__Int to check this!
+            y = intval         
+            x = (x ^ y) * mult
+            z -= 1
+            mult += 82520 + z + z
+        x += 97531
+        return space.wrap(intmask(x))
 
     def eq(self, space, w_other):
         if w_other.length() != 2:
diff --git a/pypy/objspace/std/test/test_specialisedtupleobject.py 
b/pypy/objspace/std/test/test_specialisedtupleobject.py
--- a/pypy/objspace/std/test/test_specialisedtupleobject.py
+++ b/pypy/objspace/std/test/test_specialisedtupleobject.py
@@ -21,12 +21,11 @@
         assert not isinstance(w_tuple, W_SpecialisedTupleObject)
         
     def test_hash_against_normal_tuple(self):
-        py.test.skip('in progress')
         normalspace = gettestobjspace(**{"objspace.std.withspecialisedtuple": 
False})
-        w_tuple = normalspace.newtuple([self.space.wrap(1)])
+        w_tuple = normalspace.newtuple([self.space.wrap(1), 
self.space.wrap(2)])
 
         specialisedspace = 
gettestobjspace(**{"objspace.std.withspecialisedtuple": True})
-        w_specialisedtuple = specialisedspace.newtuple([self.space.wrap(1)])
+        w_specialisedtuple = specialisedspace.newtuple([self.space.wrap(1), 
self.space.wrap(2)])
 
         assert isinstance(w_specialisedtuple, W_SpecialisedTupleObject)
         assert isinstance(w_tuple, W_TupleObject)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to