Skip to content

Commit 276d499

Browse files
imSankocclauss
authored andcommitted
Added New Tests in Signum (TheAlgorithms#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 <[email protected]> * Added few things * Update maths/signum.py Co-authored-by: Christian Clauss <[email protected]> * Added the type hint back * Update signum.py --------- Co-authored-by: Christian Clauss <[email protected]>
1 parent b23fa2d commit 276d499

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: maths/signum.py

+24
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,29 @@ def signum(num: float) -> int:
77
"""
88
Applies signum function on the number
99
10+
Custom test cases:
1011
>>> signum(-10)
1112
-1
1213
>>> signum(10)
1314
1
1415
>>> signum(0)
1516
0
17+
>>> signum(-20.5)
18+
-1
19+
>>> signum(20.5)
20+
1
21+
>>> signum(-1e-6)
22+
-1
23+
>>> signum(1e-6)
24+
1
25+
>>> signum("Hello")
26+
Traceback (most recent call last):
27+
...
28+
TypeError: '<' not supported between instances of 'str' and 'int'
29+
>>> signum([])
30+
Traceback (most recent call last):
31+
...
32+
TypeError: '<' not supported between instances of 'list' and 'int'
1633
"""
1734
if num < 0:
1835
return -1
@@ -22,10 +39,17 @@ def signum(num: float) -> int:
2239
def test_signum() -> None:
2340
"""
2441
Tests the signum function
42+
>>> test_signum()
2543
"""
2644
assert signum(5) == 1
2745
assert signum(-5) == -1
2846
assert signum(0) == 0
47+
assert signum(10.5) == 1
48+
assert signum(-10.5) == -1
49+
assert signum(1e-6) == 1
50+
assert signum(-1e-6) == -1
51+
assert signum(123456789) == 1
52+
assert signum(-123456789) == -1
2953

3054

3155
if __name__ == "__main__":

0 commit comments

Comments
 (0)