2
# tag: all, builtins, werror
4
cdef class VerboseGetItem(object):
6
def __init__(self, seq):
8
def __getitem__(self, i):
10
return self.sequence[i] # may raise IndexError
15
@cython.test_assert_path_exists("//SimpleCallNode")
16
@cython.test_fail_if_path_exists("//ForInStatNode")
19
>>> all_item([1,1,1,1,1])
21
>>> all_item([1,1,1,1,0])
23
>>> all_item([0,1,1,1,0])
26
>>> all(VerboseGetItem([1,1,1,0,0]))
32
>>> all_item(VerboseGetItem([1,1,1,0,0]))
39
>>> all(VerboseGetItem([1,1,1,1,1]))
47
>>> all_item(VerboseGetItem([1,1,1,1,1]))
59
@cython.test_assert_path_exists(
61
"//InlinedGeneratorExpressionNode"
63
@cython.test_fail_if_path_exists(
67
def all_in_simple_gen(seq):
69
>>> all_in_simple_gen([1,1,1])
71
>>> all_in_simple_gen([1,1,0])
73
>>> all_in_simple_gen([1,0,1])
76
>>> all_in_simple_gen(VerboseGetItem([1,1,1,1,1]))
84
>>> all_in_simple_gen(VerboseGetItem([1,1,0,1,1]))
90
return all(x for x in seq)
93
@cython.test_assert_path_exists(
95
"//InlinedGeneratorExpressionNode"
97
@cython.test_fail_if_path_exists(
101
def all_in_simple_gen_scope(seq):
103
>>> all_in_simple_gen_scope([1,1,1])
105
>>> all_in_simple_gen_scope([1,1,0])
107
>>> all_in_simple_gen_scope([1,0,1])
110
>>> all_in_simple_gen_scope(VerboseGetItem([1,1,1,1,1]))
118
>>> all_in_simple_gen_scope(VerboseGetItem([1,1,0,1,1]))
125
result = all(x for x in seq)
130
@cython.test_assert_path_exists(
132
"//InlinedGeneratorExpressionNode"
134
@cython.test_fail_if_path_exists(
138
def all_in_conditional_gen(seq):
140
>>> all_in_conditional_gen([3,6,9])
142
>>> all_in_conditional_gen([0,3,7])
144
>>> all_in_conditional_gen([1,0,1])
147
>>> all_in_conditional_gen(VerboseGetItem([1,1,1,1,1]))
155
>>> all_in_conditional_gen(VerboseGetItem([1,1,0,1,1]))
164
return all(x%3 for x in seq if x%2 == 1)
167
mixed_ustring = u'AbcDefGhIjKlmnoP'
168
lower_ustring = mixed_ustring.lower()
169
upper_ustring = mixed_ustring.upper()
172
@cython.test_assert_path_exists(
173
'//PythonCapiCallNode',
176
@cython.test_fail_if_path_exists(
180
def all_lower_case_characters(unicode ustring):
182
>>> all_lower_case_characters(mixed_ustring)
184
>>> all_lower_case_characters(upper_ustring)
186
>>> all_lower_case_characters(lower_ustring)
189
return all(uchar.islower() for uchar in ustring)
192
@cython.test_assert_path_exists(
194
"//InlinedGeneratorExpressionNode",
195
"//InlinedGeneratorExpressionNode//IfStatNode"
197
@cython.test_fail_if_path_exists(
200
# "//IfStatNode//CoerceToBooleanNode"
202
def all_in_typed_gen(seq):
204
>>> all_in_typed_gen([1,1,1])
206
>>> all_in_typed_gen([1,0,0])
209
>>> all_in_typed_gen(VerboseGetItem([1,1,1,1,1]))
217
>>> all_in_typed_gen(VerboseGetItem([1,1,1,1,0]))
226
return all(x for x in seq)
229
@cython.test_assert_path_exists(
231
"//InlinedGeneratorExpressionNode",
232
"//InlinedGeneratorExpressionNode//IfStatNode"
234
@cython.test_fail_if_path_exists(
237
# "//IfStatNode//CoerceToBooleanNode"
239
def all_in_double_gen(seq):
241
>>> all(x for L in [[1,1,1],[1,1,1],[1,1,1]] for x in L)
243
>>> all_in_double_gen([[1,1,1],[1,1,1],[1,1,1]])
246
>>> all(x for L in [[1,1,1],[1,1,1],[1,1,0]] for x in L)
248
>>> all_in_double_gen([[1,1,1],[1,1,1],[1,1,0]])
251
>>> all(x for L in [[1,1,1],[0,1,1],[1,1,1]] for x in L)
253
>>> all_in_double_gen([[1,1,1],[0,1,1],[1,1,1]])
256
>>> all_in_double_gen([VerboseGetItem([1,1,1]), VerboseGetItem([1,1,1,1,1])])
268
>>> all_in_double_gen([VerboseGetItem([1,1,1]),VerboseGetItem([1,1]),VerboseGetItem([1,1,0])])
280
>>> all_in_double_gen([VerboseGetItem([1,1,1]),VerboseGetItem([1,0,1]),VerboseGetItem([1,1])])
290
return all(x for L in seq for x in L)