Commit 8b93e9ec authored by Robert Bradshaw's avatar Robert Bradshaw

Update tests for new abs semantics.

See discussion at https://github.com/cython/cython/issues/1837
parent f0bc3768
......@@ -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
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment