4
## def range_tuple_genexp(int N):
6
## >>> range_tuple_genexp(5)
9
## return tuple(i for i in range(N))
12
@cython.test_assert_path_exists('//ForFromStatNode',
13
"//InlinedGeneratorExpressionNode")
14
@cython.test_fail_if_path_exists('//SimpleCallNode',
23
result = sum(i for i in range(N))
27
@cython.test_assert_path_exists('//ForFromStatNode',
28
"//InlinedGeneratorExpressionNode")
29
@cython.test_fail_if_path_exists('//SimpleCallNode',
30
'//CoerceFromPyTypeNode//InlinedGeneratorExpressionNode',
32
def range_sum_typed(int N):
36
>>> range_sum_typed(10)
39
cdef int result = sum(i for i in range(N))
43
@cython.test_assert_path_exists('//ForFromStatNode',
44
"//InlinedGeneratorExpressionNode",
45
"//ReturnStatNode//InlinedGeneratorExpressionNode",
46
"//ReturnStatNode//CoerceToPyTypeNode//InlinedGeneratorExpressionNode")
47
@cython.test_fail_if_path_exists('//SimpleCallNode',
48
'//CoerceFromPyTypeNode//InlinedGeneratorExpressionNode',
49
'//TypecastNode//InlinedGeneratorExpressionNode',
51
def return_range_sum_cast(int N):
55
>>> return_range_sum_cast(10)
58
return <int>sum(i for i in range(N))
61
@cython.test_assert_path_exists('//ForFromStatNode',
62
"//InlinedGeneratorExpressionNode")
63
@cython.test_fail_if_path_exists('//SimpleCallNode',
65
def return_range_sum(int N):
69
>>> return_range_sum(10)
72
return sum(i for i in range(N))
75
@cython.test_assert_path_exists('//ForFromStatNode',
76
"//InlinedGeneratorExpressionNode")
77
@cython.test_fail_if_path_exists('//SimpleCallNode',
79
def return_range_sum_squares(int N):
81
>>> sum([i*i for i in range(10)])
83
>>> return_range_sum_squares(10)
86
>>> print(sum([i*i for i in range(10000)]))
88
>>> print(return_range_sum_squares(10000))
91
return sum(i*i for i in range(N))
94
@cython.test_assert_path_exists('//ForInStatNode',
95
"//InlinedGeneratorExpressionNode")
96
@cython.test_fail_if_path_exists('//SimpleCallNode')
97
def return_sum_squares(seq):
99
>>> sum([i*i for i in range(10)])
101
>>> return_sum_squares(range(10))
104
>>> print(sum([i*i for i in range(10000)]))
106
>>> print(return_sum_squares(range(10000)))
109
return sum(i*i for i in seq)
112
@cython.test_assert_path_exists('//ForInStatNode',
113
"//InlinedGeneratorExpressionNode")
114
@cython.test_fail_if_path_exists('//SimpleCallNode')
115
def return_sum_squares_start(seq, int start):
117
>>> sum([i*i for i in range(10)], -1)
119
>>> return_sum_squares_start(range(10), -1)
122
>>> print(sum([i*i for i in range(10000)], 9))
124
>>> print(return_sum_squares_start(range(10000), 9))
127
return sum((i*i for i in seq), start)
130
@cython.test_assert_path_exists(
132
"//InlinedGeneratorExpressionNode")
133
@cython.test_fail_if_path_exists(
135
"//InlinedGeneratorExpressionNode//CoerceToPyTypeNode")
136
def return_typed_sum_squares_start(seq, int start):
138
>>> sum([i*i for i in range(10)], -1)
140
>>> return_typed_sum_squares_start(range(10), -1)
143
>>> print(sum([i*i for i in range(1000)], 9))
145
>>> print(return_typed_sum_squares_start(range(1000), 9))
149
return <int>sum((i*i for i in seq), start)
152
@cython.test_assert_path_exists('//ForInStatNode',
153
"//InlinedGeneratorExpressionNode")
154
@cython.test_fail_if_path_exists('//SimpleCallNode')
155
def return_sum_of_listcomp_consts_start(seq, int start):
157
>>> sum([1 for i in range(10) if i > 3], -1)
159
>>> return_sum_of_listcomp_consts_start(range(10), -1)
162
>>> print(sum([1 for i in range(10000) if i > 3], 9))
164
>>> print(return_sum_of_listcomp_consts_start(range(10000), 9))
167
return sum([1 for i in seq if i > 3], start)
170
@cython.test_assert_path_exists('//ForInStatNode',
171
"//InlinedGeneratorExpressionNode",
172
# the next test is for a deficiency
173
# (see InlinedGeneratorExpressionNode.coerce_to()),
174
# hope this breaks one day
175
"//CoerceFromPyTypeNode//InlinedGeneratorExpressionNode")
176
@cython.test_fail_if_path_exists('//SimpleCallNode')
177
def return_typed_sum_of_listcomp_consts_start(seq, int start):
179
>>> sum([1 for i in range(10) if i > 3], -1)
181
>>> return_typed_sum_of_listcomp_consts_start(range(10), -1)
184
>>> print(sum([1 for i in range(10000) if i > 3], 9))
186
>>> print(return_typed_sum_of_listcomp_consts_start(range(10000), 9))
189
return <int>sum([1 for i in seq if i > 3], start)
192
@cython.test_assert_path_exists(
194
"//InlinedGeneratorExpressionNode")
195
@cython.test_fail_if_path_exists(
197
"//InlinedGeneratorExpressionNode//CoerceToPyTypeNode")
198
def return_typed_sum_cond_exp(seq):
200
>>> return_typed_sum_cond_exp([1,2,3,4])
204
return <int>sum( 0 if i%2 else 1
208
@cython.test_assert_path_exists(
210
"//InlinedGeneratorExpressionNode")
211
@cython.test_fail_if_path_exists(
213
"//InlinedGeneratorExpressionNode//CoerceToPyTypeNode")
214
def return_typed_sum_cond_exp_in(seq):
216
>>> return_typed_sum_cond_exp_in([1,2,3,4,5,6,7,8,9])
220
return <int>sum( 0 if i%3 in (0,1) else 1