[pypy-svn] r13684 - in pypy/dist/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Wed Jun 22 12:11:41 CEST 2005


Author: arigo
Date: Wed Jun 22 12:11:39 2005
New Revision: 13684

Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/rpython/rrange.py
   pypy/dist/pypy/rpython/test/test_rrange.py
Log:
More tests for rrange.
Supports floordiv and truediv in llinterp.


Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Wed Jun 22 12:11:39 2005
@@ -259,8 +259,8 @@
 
 for typ in (float, int):
     typname = typ.__name__
-    for opname in ('add', 'sub', 'mul', 'div', 'gt', 'lt',
-                   'ge', 'ne', 'le', 'eq'):
+    for opname in ('add', 'sub', 'mul', 'div', 'floordiv', 'truediv',
+                   'gt', 'lt', 'ge', 'ne', 'le', 'eq'):
         assert opname in opimpls
         exec py.code.Source("""
             def %(typname)s_%(opname)s(x, y):

Modified: pypy/dist/pypy/rpython/rrange.py
==============================================================================
--- pypy/dist/pypy/rpython/rrange.py	(original)
+++ pypy/dist/pypy/rpython/rrange.py	Wed Jun 22 12:11:39 2005
@@ -59,12 +59,7 @@
 
 def ll_rangeitem(l, i, step):
     if i<0:
-        # XXX ack. cannot call ll_rangelen() here for now :-(
-        if step > 0:
-            length = (l.stop - l.start + (step-1)) // step
-        else:
-            length = (l.start - l.stop - (step+1)) // (-step)
-        #assert length >= 0
+        length = ll_rangelen(l, step)
         i += length
     return l.start + i*step
 

Modified: pypy/dist/pypy/rpython/test/test_rrange.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rrange.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rrange.py	Wed Jun 22 12:11:39 2005
@@ -1,6 +1,6 @@
 from pypy.translator.translator import Translator
-from pypy.rpython.rtyper import RPythonTyper
 from pypy.rpython.rrange import *
+from pypy.rpython.test.test_llinterp import interpret
 
 def test_rlist_range():
     def test1(start, stop, step):
@@ -22,20 +22,31 @@
 
 # ____________________________________________________________
 
-def rtype(fn, argtypes=[]):
-    t = Translator(fn)
-    t.annotate(argtypes)
-    typer = RPythonTyper(t.annotator)
-    typer.specialize()
-    #t.view()
-    t.checkgraphs()
-    return t
-
-
 def test_range():
     def dummyfn(N):
         total = 0
         for i in range(N):
             total += i
         return total
-    rtype(dummyfn, [int])
+    res = interpret(dummyfn, [10])
+    assert res == 45
+
+def test_range_is_lazy():
+    def dummyfn(N, M):
+        total = 0
+        for i in range(M):
+            if i == N:
+                break
+            total += i
+        return total
+    res = interpret(dummyfn, [10, 2147418112])
+    assert res == 45
+
+def test_range_item():
+    def dummyfn(start, stop, i):
+        r = range(start, stop)
+        return r[i]
+    res = interpret(dummyfn, [10, 17, 4])
+    assert res == 14
+    res = interpret(dummyfn, [10, 17, -2])
+    assert res == 15



More information about the Pypy-commit mailing list