From: Robert Bradshaw Date: Wed, 25 Mar 2009 11:17:25 +0000 (-0700) Subject: loop semantics are STILL wrong, as were some T203 doctests X-Git-Tag: 0.12.alpha0~368 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a0057c6f500f3dcfce151ab594257bcc86b8a8dc;p=cython.git loop semantics are STILL wrong, as were some T203 doctests --- diff --git a/tests/run/range_optimisation_T203.pyx b/tests/run/range_optimisation_T203.pyx index 5ae5e951..3e31bae3 100644 --- a/tests/run/range_optimisation_T203.pyx +++ b/tests/run/range_optimisation_T203.pyx @@ -1,11 +1,58 @@ __doc__ = u""" ->>> test_var(10, 5) +>>> for_from_range(5, 10) +range(5) +at 0 +at 1 +at 2 +at 3 +at 4 +range(5, 10) +at 5 +at 6 +at 7 +at 8 +at 9 +range(5, 10, 2) +at 5 +at 7 +at 9 +9 +>>> for_from_bound_reassignment(5, 1) at 0 at 1 at 2 at 3 at 4 5 +>>> for_from_step_reassignment(15, 5, 2) +at 0 +at 5 +at 10 +15 +>>> for_from_target_reassignment(10, 2) +at 0 +at 1 +at 3 +at 7 +15 +>>> for_from_py_target_reassignment(10, 2) +at 0 +at 1 +at 3 +at 7 +15 +>>> for_in_target_reassignment(10, 2) +at 0 +at 1 +at 2 +at 3 +at 4 +at 5 +at 6 +at 7 +at 8 +at 9 +18 >>> test_func(5) get_bound(5) at 0 @@ -14,47 +61,61 @@ at 2 at 3 at 4 5 ->>> test_f() -9 ->>> f() -g called -0 -1 -2 -2 """ +def for_from_range(a, b): + cdef int i + print "range(%s)" % a + for i in range(a): + print "at", i + print "range(%s, %s)" % (a, b) + for i in range(a, b): + print "at", i + print "range(%s, %s, %s)" % (a, b, 2) + for i in range(a, b, 2): + print "at", i + return i cdef int get_bound(int m): print "get_bound(%s)"%m return m -def test_var(int n, int m): +def for_from_bound_reassignment(int bound, int fake_bound): cdef int i - for i from 0 <= i < n: + for i from 0 <= i < bound: print "at", i - n = m + bound = fake_bound return i -def test_func(int n): +def for_from_step_reassignment(int bound, int step, int fake_step): cdef int i - for i from 0 <= i < get_bound(n): + for i from 0 <= i < bound by step: print "at", i + step = fake_step return i -def test_f(): - cdef int i,n - n = 10 - for i in range(n): - if i == 5: n *= 2 - print i +def for_from_target_reassignment(int bound, int factor): + cdef int i + for i from 0 <= i < bound: + print "at", i + i *= factor + return i -cdef int g(): - print "g called" - return 3 +def for_from_py_target_reassignment(int bound, int factor): + cdef object i + for i from 0 <= i < bound: + print "at", i + i *= factor + return i -def f(): - cdef int i = -1 - for i in range(g()): - print i - print i +def for_in_target_reassignment(int bound, int factor): + cdef int i + for i in range(bound): + print "at", i + i *= factor + return i +def test_func(int n): + cdef int i + for i from 0 <= i < get_bound(n): + print "at", i + return i