[pypy-commit] pypy SpecialisedTuples: (mwp) add tests and code for some specialised 3-tuples + add slice multimethod
mwp
noreply at buildbot.pypy.org
Thu Nov 10 10:47:55 CET 2011
Author: Mark Pearse <mark.pearse at skynet.be>
Branch: SpecialisedTuples
Changeset: r49107:8cbac70700fc
Date: 2011-11-07 19:30 +0100
http://bitbucket.org/pypy/pypy/changeset/8cbac70700fc/
Log: (mwp) add tests and code for some specialised 3-tuples + add slice
multimethod
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
@@ -2,6 +2,7 @@
from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.tupleobject import W_TupleObject
+from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
from pypy.rlib.rarithmetic import intmask
from pypy.rlib.objectmodel import compute_hash
from pypy.rlib.unroll import unrolling_iterable
@@ -127,8 +128,10 @@
W_SpecialisedTupleObjectIntInt = make_specialised_class('W_SpecialisedTupleObjectIntInt', (int,int))
+W_SpecialisedTupleObjectIntIntInt = make_specialised_class('W_SpecialisedTupleObjectFloatFloat', (int,int,int))
W_SpecialisedTupleObjectFloatFloat = make_specialised_class('W_SpecialisedTupleObjectFloatFloat', (float,float))
W_SpecialisedTupleObjectStrStr = make_specialised_class('W_SpecialisedTupleObjectStrStr', (str, str))
+W_SpecialisedTupleObjectIntFloatStr= make_specialised_class('W_SpecialisedTupleObjectStrStr', (int, float, str))
registerimplementation(W_SpecialisedTupleObject)
@@ -148,6 +151,16 @@
raise OperationError(space.w_IndexError,
space.wrap("tuple index out of range"))
+def getitem__SpecialisedTuple_Slice(space, w_tuple, w_slice):
+ length = w_tuple.length()
+ start, stop, step, slicelength = w_slice.indices4(space, length)
+ assert slicelength >= 0
+ subitems = [None] * slicelength
+ for i in range(slicelength):
+ subitems[i] = w_tuple.getitem(start)
+ start += step
+ return space.newtuple(subitems)
+
def eq__SpecialisedTuple_SpecialisedTuple(space, w_tuple1, w_tuple2):
return w_tuple1.eq(space, w_tuple2)
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
@@ -75,7 +75,7 @@
assert len(t) == 2
def test_notspecialisedtuple(self):
- assert not self.isspecialised((42,43,44))
+ assert not self.isspecialised((42,43,44,45))
assert not self.isspecialised((1,1.5))
assert not self.isspecialised((1,1.0))
@@ -92,7 +92,7 @@
def test_slicing_from_specialised(self):
assert (1,2,3)[0:2:1] == (1,2)
- def test_eq(self):
+ def test_eq_no_delegation(self):
a = self.forbid_delegation((1,2))
b = (1,2)
assert a == b
@@ -110,7 +110,7 @@
a = (1,2)
b = (1,3,2)
assert not a == b
-
+
values = [2, 2L, 2.0, 1, 1L, 1.0]
for x in values:
for y in values:
@@ -145,7 +145,7 @@
def test_hash(self):
a = (1,2)
- b = (1,2)
+ b = (1,) + (2,) # else a and b refer to same constant
assert hash(a) == hash(b)
c = (2,4)
@@ -159,8 +159,26 @@
assert (t)[-2] == 5
raises(IndexError, "t[2]")
+ def test_three_tuples(self):
+ if not self.isspecialised((1,2,3)):
+ skip('3-tuples of ints are not specialised, so skip specific tests on them')
+ a = self.forbid_delegation((1,2))
+ b = self.forbid_delegation((1,2,3))
+ c = (1,)
+ d = c + (2,3)
+ assert not a == b
+ assert not b == a
+ assert a < b
+ assert b > a
+ assert self.isspecialised(d)
+ assert b == d
+ assert b <= d
-
-
-
-
+ def test_mongrel(self):
+ a = self.forbid_delegation((1, 2.2, '333'))
+ if not self.isspecialised(a):
+ skip('my chosen kind of mixed type tuple is not specialised, so skip specific tests on them')
+ assert len(a) == 3
+ assert a[0] == 1 and a[1] == 2.2 and a[2] == '333'
+ assert a == (1,) + (2.2,) + ('333',)
+ assert a < (1, 2.2, '334')
More information about the pypy-commit
mailing list