1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
# mode: run
# cython:infer_types=True
cimport cython
from libc.stdint cimport int64_t
### Tests for external typedefs.
@cython.test_assert_path_exists(
"//SimpleCallNode//NameNode[@entry.name = 'divmod']",
"//SimpleCallNode//NameNode[@entry.cname = '__Pyx_divmod_int_td_int64_t']",
"//ReturnStatNode//CoerceToPyTypeNode",
)
def divmod_typedef(a: int64_t, b: cython.int):
"""
>>> divmod_typedef(10, 5)
(2, 0)
>>> divmod_typedef(9191, 4096)
(2, 999)
>>> divmod_typedef(-420000000000, 1000)
(-420000000, 0)
>>> divmod_typedef(33, 0) #doctest: +ELLIPSIS
Traceback (most recent call last):
ZeroDivisionError: ...
>>> divmod_typedef(0, 0) #doctest: +ELLIPSIS
Traceback (most recent call last):
ZeroDivisionError: ...
"""
result = divmod(a, b)
return result
@cython.test_assert_path_exists(
"//SimpleCallNode//NameNode[@entry.name = 'divmod']",
"//SimpleCallNode//NameNode[@entry.cname = '__Pyx_divmod_int_td_int64_t']",
"//ReturnStatNode//CoerceToPyTypeNode",
)
def divmod_typedef_const(a: int64_t):
"""
>>> divmod_typedef_const(10)
(0, 10)
>>> divmod_typedef_const(9191)
(9, 191)
>>> divmod_typedef_const(-420000000000)
(-420000000, 0)
"""
result = divmod(a, 1000)
return result
### Tests for internal and mixed typedefs.
ctypedef long my_long_type
ctypedef int64_t my_int64_type
@cython.test_assert_path_exists(
"//SimpleCallNode//NameNode[@entry.name = 'divmod']",
"//SimpleCallNode//NameNode[@entry.cname = '__Pyx_divmod_int_td_int64_t']",
"//ReturnStatNode//CoerceToPyTypeNode",
)
def divmod_typedef_mixed(a: my_int64_type, b: cython.int):
"""
>>> divmod_typedef_mixed(10, 5)
(2, 0)
>>> divmod_typedef_mixed(9191, 4096)
(2, 999)
>>> divmod_typedef_mixed(-420000000000, 1000)
(-420000000, 0)
>>> divmod_typedef_mixed(33, 0) #doctest: +ELLIPSIS
Traceback (most recent call last):
ZeroDivisionError: ...
>>> divmod_typedef_mixed(0, 0) #doctest: +ELLIPSIS
Traceback (most recent call last):
ZeroDivisionError: ...
"""
result = divmod(a, b)
return result
@cython.test_assert_path_exists(
"//SimpleCallNode//NameNode[@entry.name = 'divmod']",
"//SimpleCallNode//NameNode[@entry.cname = '__Pyx_divmod_int_long']",
"//ReturnStatNode//CoerceToPyTypeNode",
)
def divmod_typedef_internal(a: my_long_type, b: cython.int):
"""
>>> divmod_typedef_internal(10, 5)
(2, 0)
>>> divmod_typedef_internal(9191, 4096)
(2, 999)
>>> divmod_typedef_internal(33, 0) #doctest: +ELLIPSIS
Traceback (most recent call last):
ZeroDivisionError: ...
>>> divmod_typedef_internal(0, 0) #doctest: +ELLIPSIS
Traceback (most recent call last):
ZeroDivisionError: ...
"""
result = divmod(a, b)
return result
|