1# ticket: 203
2
3cdef int get_bound(int m):
4    print u"get_bound(%s)"%m
5    return m
6
7def for_from_range(a, b):
8    """
9    >>> for_from_range(5, 10)
10    range(5)
11    at 0
12    at 1
13    at 2
14    at 3
15    at 4
16    range(5, 10)
17    at 5
18    at 6
19    at 7
20    at 8
21    at 9
22    range(5, 10, 2)
23    at 5
24    at 7
25    at 9
26    9
27    >>> for_from_range(-5, -10)
28    range(-5)
29    range(-5, -10)
30    range(-5, -10, 2)
31    100
32    """
33    cdef int i = 100
34    print u"range(%s)" % a
35    for i in range(a):
36        print u"at", i
37    print u"range(%s, %s)" % (a, b)
38    for i in range(a, b):
39        print u"at", i
40    print u"range(%s, %s, %s)" % (a, b, 2)
41    for i in range(a, b, 2):
42        print u"at", i
43    return i
44
45def for_from_bound_reassignment(int bound, int fake_bound):
46    """
47    >>> for_from_bound_reassignment(5, 1)
48    at 0
49    at 1
50    at 2
51    at 3
52    at 4
53    5
54    """
55    cdef int i = 100
56    for i from 0 <= i < bound:
57        print u"at", i
58        bound = fake_bound
59    return i
60
61def for_from_step_reassignment(int bound, int step, int fake_step):
62    """
63    >>> for_from_step_reassignment(15, 5, 2)
64    at 0
65    at 5
66    at 10
67    15
68    """
69    cdef int i = 100
70    for i from 0 <= i < bound by step:
71        print u"at", i
72        step = fake_step
73    return i
74
75def for_from_target_reassignment(int bound, int factor):
76    """
77    >>> for_from_target_reassignment(10, 2)
78    at 0
79    at 1
80    at 3
81    at 7
82    15
83    """
84    cdef int i = 100
85    for i from 0 <= i < bound:
86        print u"at", i
87        i *= factor
88    return i
89
90def for_from_py_target_reassignment(int bound, int factor):
91    """
92    >>> for_from_py_target_reassignment(10, 2)
93    at 0
94    at 1
95    at 3
96    at 7
97    15
98    """
99    cdef object i
100    for i from 0 <= i < bound:
101        print u"at", i
102        i *= factor
103    return i
104
105def for_from_py_global_target_reassignment(int bound, int factor):
106    """
107    >>> for_from_py_global_target_reassignment(10, 2)
108    at 0
109    at 1
110    at 3
111    at 7
112    15
113    """
114    global g_var
115    for g_var from 0 <= g_var < bound:
116        print u"at", g_var
117        g_var *= factor
118    return g_var
119
120def for_in_target_reassignment(int bound, int factor):
121    """
122    >>> for_in_target_reassignment(10, 2)
123    at 0
124    at 1
125    at 2
126    at 3
127    at 4
128    at 5
129    at 6
130    at 7
131    at 8
132    at 9
133    18
134    """
135    cdef int i = 100
136    for i in range(bound):
137        print u"at", i
138        i *= factor
139    return i
140
141def test_func(int n):
142    """
143    >>> test_func(5)
144    get_bound(5)
145    at 0
146    at 1
147    at 2
148    at 3
149    at 4
150    5
151    """
152    cdef int i = 100
153    for i from 0 <= i < get_bound(n):
154        print u"at", i
155    return i
156