File tree Expand file tree Collapse file tree 4 files changed +19
-12
lines changed
Expand file tree Collapse file tree 4 files changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -11,10 +11,16 @@ def bin_to_decimal(bin_string: str) -> int:
1111 >>> bin_to_decimal("0")
1212 0
1313 >>> bin_to_decimal("a")
14+ Traceback (most recent call last):
15+ ...
1416 ValueError: Non-binary value was passed to the function
1517 >>> bin_to_decimal("")
16- ValueError: Empty string value was passed to the function
18+ Traceback (most recent call last):
19+ ...
20+ ValueError: Empty string was passed to the function
1721 >>> bin_to_decimal("39")
22+ Traceback (most recent call last):
23+ ...
1824 ValueError: Non-binary value was passed to the function
1925 """
2026 bin_string = str (bin_string ).strip ()
@@ -28,9 +34,7 @@ def bin_to_decimal(bin_string: str) -> int:
2834 decimal_number = 0
2935 for char in bin_string :
3036 decimal_number = 2 * decimal_number + int (char )
31- if is_negative:
32- decimal_number = -decimal_number
33- return decimal_number
37+ return - decimal_number if is_negative else decimal_number
3438
3539
3640if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -17,14 +17,20 @@ def hex_to_decimal(hex_string: str) -> int:
1717 >>> hex_to_decimal("-Ff")
1818 -255
1919 >>> hex_to_decimal("F-f")
20+ Traceback (most recent call last):
21+ ...
2022 ValueError: Non-hexadecimal value was passed to the function
2123 >>> hex_to_decimal("")
22- ValueError: Empty string value was passed to the function
24+ Traceback (most recent call last):
25+ ...
26+ ValueError: Empty string was passed to the function
2327 >>> hex_to_decimal("12m")
28+ Traceback (most recent call last):
29+ ...
2430 ValueError: Non-hexadecimal value was passed to the function
2531 """
2632 hex_string = hex_string .strip ().lower ()
27- if not hex_string:
33+ if not hex_string :
2834 raise ValueError ("Empty string was passed to the function" )
2935 is_negative = hex_string [0 ] == "-"
3036 if is_negative :
@@ -34,9 +40,7 @@ def hex_to_decimal(hex_string: str) -> int:
3440 decimal_number = 0
3541 for char in hex_string :
3642 decimal_number = 16 * decimal_number + hex_table [char ]
37- if is_negative:
38- decimal_number = -decimal_number
39- return decimal_number
43+ return - decimal_number if is_negative else decimal_number
4044
4145
4246if __name__ == "__main__" :
Original file line number Diff line number Diff line change 1- from unittest .mock import patch , Mock
2-
1+ from unittest .mock import Mock , patch
32
43from file_transfer .send_file import send_file
54
Original file line number Diff line number Diff line change 11"""Non recursive implementation of a DFS algorithm."""
22
3- from typing import Set , Dict
3+ from typing import Dict , Set
44
55
66def depth_first_search (graph : Dict , start : str ) -> Set [int ]:
You can’t perform that action at this time.
0 commit comments