Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions maths/signum.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@ def signum(num: float) -> int:
"""
Applies signum function on the number

Custom test cases:
>>> signum(-10)
Comment thread
cclauss marked this conversation as resolved.
-1
>>> signum(10)
Comment thread
cclauss marked this conversation as resolved.
1
>>> signum(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:
return -1
Expand All @@ -22,10 +39,17 @@ def signum(num: float) -> int:
def test_signum() -> None:
"""
Tests the signum function
>>> test_signum()
"""
assert signum(5) == 1
assert signum(-5) == -1
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
Comment thread
cclauss marked this conversation as resolved.


if __name__ == "__main__":
Expand Down