mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Added New Tests in Signum (#10724)
* Added new tests! * [ADD]: Inproved Tests * fixed * Removed spaces * Changed the file name * Added Changes * changed the code and kept the test cases * changed the code and kept the test cases * missed the line * removed spaces * Update power_using_recursion.py * Added new tests in Signum * Few things added * Removed few stuff and added few changes * Fixed few things * Reverted the function * Update maths/signum.py Co-authored-by: Christian Clauss <cclauss@me.com> * Added few things * Update maths/signum.py Co-authored-by: Christian Clauss <cclauss@me.com> * Added the type hint back * Update signum.py --------- Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
ce0ede6476
commit
579937613a
|
@ -7,12 +7,29 @@ def signum(num: float) -> int:
|
||||||
"""
|
"""
|
||||||
Applies signum function on the number
|
Applies signum function on the number
|
||||||
|
|
||||||
|
Custom test cases:
|
||||||
>>> signum(-10)
|
>>> signum(-10)
|
||||||
-1
|
-1
|
||||||
>>> signum(10)
|
>>> signum(10)
|
||||||
1
|
1
|
||||||
>>> signum(0)
|
>>> signum(0)
|
||||||
0
|
0
|
||||||
|
>>> signum(-20.5)
|
||||||
|
-1
|
||||||
|
>>> signum(20.5)
|
||||||
|
1
|
||||||
|
>>> signum(-1e-6)
|
||||||
|
-1
|
||||||
|
>>> signum(1e-6)
|
||||||
|
1
|
||||||
|
>>> signum("Hello")
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
TypeError: '<' not supported between instances of 'str' and 'int'
|
||||||
|
>>> signum([])
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
TypeError: '<' not supported between instances of 'list' and 'int'
|
||||||
"""
|
"""
|
||||||
if num < 0:
|
if num < 0:
|
||||||
return -1
|
return -1
|
||||||
|
@ -22,10 +39,17 @@ def signum(num: float) -> int:
|
||||||
def test_signum() -> None:
|
def test_signum() -> None:
|
||||||
"""
|
"""
|
||||||
Tests the signum function
|
Tests the signum function
|
||||||
|
>>> test_signum()
|
||||||
"""
|
"""
|
||||||
assert signum(5) == 1
|
assert signum(5) == 1
|
||||||
assert signum(-5) == -1
|
assert signum(-5) == -1
|
||||||
assert signum(0) == 0
|
assert signum(0) == 0
|
||||||
|
assert signum(10.5) == 1
|
||||||
|
assert signum(-10.5) == -1
|
||||||
|
assert signum(1e-6) == 1
|
||||||
|
assert signum(-1e-6) == -1
|
||||||
|
assert signum(123456789) == 1
|
||||||
|
assert signum(-123456789) == -1
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in New Issue
Block a user