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): ...@@ -31,25 +31,38 @@ def py_abs(a):
return abs(a) return abs(a)
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']", @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): def int_abs(int a):
""" """
>>> int_abs(-5) == 5 >>> int_abs(-5) == 5
True True
>>> int_abs(-5.1) == 5 >>> int_abs(-5.1) == 5
True True
>>> int_abs(-max_int-1) > 0 """
True # >>> int_abs(-max_int-1) > 0
>>> int_abs(-max_int-1) == abs(-max_int-1) or (max_int, int_abs(-max_int-1), abs(-max_int-1)) # True
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)) >>> int_abs(max_int) == abs(max_int) or (max_int, int_abs(max_int), abs(max_int))
True True
""" """
return abs(a) return abs(a)
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']") @cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']")
@cython.test_fail_if_path_exists("//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_int']", @cython.test_fail_if_path_exists("//ReturnStatNode//NameNode[@entry.cname = 'abs']",
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_long']") "//ReturnStatNode//NameNode[@entry.cname = 'labs']")
def uint_abs(unsigned int a): def uint_abs(unsigned int a):
""" """
>>> uint_abs(max_int) == abs(max_int) or (max_int, uint_abs(max_int), abs(max_int)) >>> 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): ...@@ -58,29 +71,33 @@ def uint_abs(unsigned int a):
return abs(a) return abs(a)
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']", @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): def long_abs(long a):
""" """
>>> long_abs(-5) == 5 >>> long_abs(-5) == 5
True True
>>> long_abs(-5.1) == 5 >>> long_abs(-5.1) == 5
True True
>>> long_abs(-max_long-1) > 0 """
True # >>> long_abs(-max_long-1) > 0
>>> long_abs(-max_long-1) == abs(-max_long-1) or (max_long, long_abs(-max_long-1), abs(-max_long-1)) # True
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)) >>> long_abs(max_long) == abs(max_long) or (max_long, long_abs(max_long), abs(max_long))
True True
""" """
return abs(a) return abs(a)
@cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']") @cython.test_assert_path_exists("//ReturnStatNode//NameNode[@entry.name = 'abs']")
@cython.test_fail_if_path_exists("//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_int']", @cython.test_fail_if_path_exists("//ReturnStatNode//NameNode[@entry.cname = 'abs']",
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_long']") "//ReturnStatNode//NameNode[@entry.cname = 'labs']")
def ulong_abs(unsigned long a): def ulong_abs(unsigned long a):
""" """
>>> ulong_abs(max_long) == abs(max_long) or (max_int, ulong_abs(max_long), abs(max_long)) >>> ulong_abs(max_long) == abs(max_long) or (max_int, ulong_abs(max_long), abs(max_long))
True 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) return abs(a)
...@@ -90,10 +107,12 @@ def long_long_abs(long long a): ...@@ -90,10 +107,12 @@ def long_long_abs(long long a):
""" """
>>> long_long_abs(-(2**33)) == 2**33 >>> long_long_abs(-(2**33)) == 2**33
True True
>>> long_long_abs(-max_long_long-1) > 0 """
True # >>> long_long_abs(-max_long_long-1) > 0
>>> 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
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)) >>> 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 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