cython

Форк
0
/
for_in_range_T372.pyx 
146 строк · 2.6 Кб
1
# mode: run
2
# ticket: t372
3

4
cimport cython
5

6
@cython.test_assert_path_exists("//ForFromStatNode")
7
@cython.test_fail_if_path_exists("//ForInStatNode")
8
def test_modify():
9
    """
10
    >>> test_modify()
11
    0
12
    1
13
    2
14
    3
15
    4
16
    <BLANKLINE>
17
    (4, 0)
18
    """
19
    cdef int i, n = 5
20
    for i in range(n):
21
        print i
22
        n = 0
23
    print
24
    return i,n
25

26

27
@cython.test_assert_path_exists("//ForFromStatNode")
28
@cython.test_fail_if_path_exists("//ForInStatNode")
29
def test_negindex():
30
    """
31
    >>> test_negindex()
32
    6
33
    5
34
    4
35
    3
36
    2
37
    (2, 0)
38
    """
39
    cdef int i, n = 5
40
    for i in range(n+1, 1, -1):
41
        print i
42
        n = 0
43
    return i,n
44

45

46
@cython.test_assert_path_exists("//ForFromStatNode",
47
                                "//ForFromStatNode//PrintStatNode//CoerceToPyTypeNode")
48
@cython.test_fail_if_path_exists("//ForInStatNode")
49
def test_negindex_inferred():
50
    """
51
    >>> test_negindex_inferred()
52
    5
53
    4
54
    3
55
    2
56
    (2, 0)
57
    """
58
    cdef int n = 5
59
    for i in range(n, 1, -1):
60
        print i
61
        n = 0
62
    return i,n
63

64

65
@cython.test_assert_path_exists("//ForFromStatNode")
66
@cython.test_fail_if_path_exists("//ForInStatNode")
67
def test_fix():
68
    """
69
    >>> test_fix()
70
    0
71
    1
72
    2
73
    3
74
    4
75
    <BLANKLINE>
76
    4
77
    """
78
    cdef int i
79
    for i in range(5):
80
        print i
81
    print
82
    return i
83

84

85
@cython.test_assert_path_exists("//ForFromStatNode")
86
@cython.test_fail_if_path_exists("//ForInStatNode")
87
def test_break():
88
    """
89
    >>> test_break()
90
    0
91
    1
92
    2
93
    <BLANKLINE>
94
    (2, 0)
95
    """
96
    cdef int i, n = 5
97
    for i in range(n):
98
        print i
99
        n = 0
100
        if i == 2:
101
            break
102
    else:
103
        print "FAILED!"
104
    print
105
    return i,n
106

107

108
@cython.test_assert_path_exists("//ForFromStatNode")
109
@cython.test_fail_if_path_exists("//ForInStatNode")
110
def test_return():
111
    """
112
    >>> test_return()
113
    0
114
    1
115
    2
116
    (2, 0)
117
    """
118
    cdef int i, n = 5
119
    for i in range(n):
120
        print i
121
        n = 0
122
        if i == 2:
123
            return i,n
124
    print
125
    return "FAILED!"
126

127

128
ctypedef enum RangeEnum:
129
    EnumValue1
130
    EnumValue2
131
    EnumValue3
132

133

134
@cython.test_assert_path_exists("//ForFromStatNode")
135
@cython.test_fail_if_path_exists("//ForInStatNode")
136
def test_enum_range():
137
    """
138
    # NOTE: it's not entirely clear that this is the expected behaviour, but that's how it currently is.
139
    >>> test_enum_range()
140
    'RangeEnum'
141
    """
142
    cdef RangeEnum n = EnumValue3
143
    for i in range(n):
144
        assert 0 <= <int>i < <int>n
145
        assert cython.typeof(i) == "RangeEnum", cython.typeof(i)
146
    return cython.typeof(i)
147

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.