[pypy-svn] r10092 - in pypy/dist/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Tue Mar 22 22:06:58 CET 2005


Author: arigo
Date: Tue Mar 22 22:06:58 2005
New Revision: 10092

Modified:
   pypy/dist/pypy/objspace/std/sliceobject.py
   pypy/dist/pypy/objspace/std/test/test_sliceobject.py
Log:
slice.__lt__()


Modified: pypy/dist/pypy/objspace/std/sliceobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/sliceobject.py	(original)
+++ pypy/dist/pypy/objspace/std/sliceobject.py	Tue Mar 22 22:06:58 2005
@@ -42,6 +42,17 @@
     else:
         return space.w_False
 
+def lt__Slice_Slice(space, w_slice1, w_slice2):
+    if space.is_w(w_slice1, w_slice2):
+        return space.w_False   # see comments in eq__Slice_Slice()
+    if space.eq_w(w_slice1.w_start, w_slice2.w_start):
+        if space.eq_w(w_slice1.w_stop, w_slice2.w_stop):
+            return space.lt(w_slice1.w_step, w_slice2.w_step)
+        else:
+            return space.lt(w_slice1.w_stop, w_slice2.w_stop)
+    else:
+        return space.lt(w_slice1.w_start, w_slice2.w_start)
+
 def hash__Slice(space, w_slice):
     """slices are not hashables but they must have a __hash__ method"""
     raise OperationError(space.w_TypeError,

Modified: pypy/dist/pypy/objspace/std/test/test_sliceobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_sliceobject.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_sliceobject.py	Tue Mar 22 22:06:58 2005
@@ -61,3 +61,12 @@
         assert slice1 == slice2
         slice2 = slice(1, 2)
         assert slice1 != slice2
+
+    def test_lt(self):
+        assert slice(0, 2, 3) < slice(1, 0, 0)
+        assert slice(0, 1, 3) < slice(0, 2, 0)
+        assert slice(0, 1, 2) < slice(0, 1, 3)
+        assert not (slice(1, 2, 3) < slice(0, 0, 0))
+        assert not (slice(1, 2, 3) < slice(1, 0, 0))
+        assert not (slice(1, 2, 3) < slice(1, 2, 0))
+        assert not (slice(1, 2, 3) < slice(1, 2, 3))



More information about the Pypy-commit mailing list