Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
8b93e9ec
Commit
8b93e9ec
authored
Aug 24, 2017
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests for new abs semantics.
See discussion at
https://github.com/cython/cython/issues/1837
parent
f0bc3768
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
18 deletions
+37
-18
tests/run/builtin_abs.pyx
tests/run/builtin_abs.pyx
+37
-18
No files found.
tests/run/builtin_abs.pyx
View file @
8b93e9ec
...
...
@@ -31,25 +31,38 @@ def py_abs(a):
return
abs
(
a
)
@
cython
.
test_assert_path_exists
(
"//ReturnStatNode//NameNode[@entry.name = 'abs']"
,
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_int']"
)
"//ReturnStatNode//NameNode[@entry.cname = 'abs']"
)
def
sub_abs
(
int
a
):
"""
>>> sub_abs(5)
(-5, 95)
>>> sub_abs(105)
(-105, -5)
"""
return
-
abs
(
a
),
100
-
abs
(
a
)
@
cython
.
test_assert_path_exists
(
"//ReturnStatNode//NameNode[@entry.name = 'abs']"
,
"//ReturnStatNode//NameNode[@entry.cname = 'abs']"
)
def
int_abs
(
int
a
):
"""
>>> int_abs(-5) == 5
True
>>> int_abs(-5.1) == 5
True
>>> int_abs(-max_int-1) > 0
True
>>> int_abs(-max_int-1) == abs(-max_int-1) or (max_int, int_abs(-max_int-1), abs(-max_int-1))
True
"""
# >>> int_abs(-max_int-1) > 0
# True
# >>> int_abs(-max_int-1) == abs(-max_int-1) or (max_int, int_abs(-max_int-1), abs(-max_int-1))
# True
"""
>>> int_abs(max_int) == abs(max_int) or (max_int, int_abs(max_int), abs(max_int))
True
"""
return
abs
(
a
)
@
cython
.
test_assert_path_exists
(
"//ReturnStatNode//NameNode[@entry.name = 'abs']"
)
@
cython
.
test_fail_if_path_exists
(
"//ReturnStatNode//NameNode[@entry.cname = '
__Pyx_abs_int
']"
,
"//ReturnStatNode//NameNode[@entry.cname = '
__Pyx_abs_long
']"
)
@
cython
.
test_fail_if_path_exists
(
"//ReturnStatNode//NameNode[@entry.cname = '
abs
']"
,
"//ReturnStatNode//NameNode[@entry.cname = '
labs
']"
)
def
uint_abs
(
unsigned
int
a
):
"""
>>> uint_abs(max_int) == abs(max_int) or (max_int, uint_abs(max_int), abs(max_int))
...
...
@@ -58,29 +71,33 @@ def uint_abs(unsigned int a):
return
abs
(
a
)
@
cython
.
test_assert_path_exists
(
"//ReturnStatNode//NameNode[@entry.name = 'abs']"
,
"//ReturnStatNode//NameNode[@entry.cname = '
__Pyx_abs_long
']"
)
"//ReturnStatNode//NameNode[@entry.cname = '
labs
']"
)
def
long_abs
(
long
a
):
"""
>>> long_abs(-5) == 5
True
>>> long_abs(-5.1) == 5
True
>>> long_abs(-max_long-1) > 0
True
>>> long_abs(-max_long-1) == abs(-max_long-1) or (max_long, long_abs(-max_long-1), abs(-max_long-1))
True
"""
# >>> long_abs(-max_long-1) > 0
# True
# >>> long_abs(-max_long-1) == abs(-max_long-1) or (max_long, long_abs(-max_long-1), abs(-max_long-1))
# True
"""
>>> long_abs(max_long) == abs(max_long) or (max_long, long_abs(max_long), abs(max_long))
True
"""
return
abs
(
a
)
@
cython
.
test_assert_path_exists
(
"//ReturnStatNode//NameNode[@entry.name = 'abs']"
)
@
cython
.
test_fail_if_path_exists
(
"//ReturnStatNode//NameNode[@entry.cname = '
__Pyx_abs_int
']"
,
"//ReturnStatNode//NameNode[@entry.cname = '
__Pyx_abs_long
']"
)
@
cython
.
test_fail_if_path_exists
(
"//ReturnStatNode//NameNode[@entry.cname = '
abs
']"
,
"//ReturnStatNode//NameNode[@entry.cname = '
labs
']"
)
def
ulong_abs
(
unsigned
long
a
):
"""
>>> ulong_abs(max_long) == abs(max_long) or (max_int, ulong_abs(max_long), abs(max_long))
True
>>> ulong_abs(max_long + 5) == abs(max_long + 5) or (max_long + 5, ulong_abs(max_long + 5), abs(max_long + 5))
True
"""
return
abs
(
a
)
...
...
@@ -90,10 +107,12 @@ def long_long_abs(long long a):
"""
>>> long_long_abs(-(2**33)) == 2**33
True
>>> long_long_abs(-max_long_long-1) > 0
True
>>> long_long_abs(-max_long_long-1) == abs(-max_long_long-1) or (max_long_long, long_long_abs(-max_long_long-1), abs(-max_long_long-1))
True
"""
# >>> long_long_abs(-max_long_long-1) > 0
# True
# >>> long_long_abs(-max_long_long-1) == abs(-max_long_long-1) or (max_long_long, long_long_abs(-max_long_long-1), abs(-max_long_long-1))
# True
"""
>>> long_long_abs(max_long_long) == abs(max_long_long) or (max_long_long, long_long_abs(max_long_long), abs(max_long_long))
True
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment