File tree 4 files changed +19
-12
lines changed
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:
11
11
>>> bin_to_decimal("0")
12
12
0
13
13
>>> bin_to_decimal("a")
14
+ Traceback (most recent call last):
15
+ ...
14
16
ValueError: Non-binary value was passed to the function
15
17
>>> 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
17
21
>>> bin_to_decimal("39")
22
+ Traceback (most recent call last):
23
+ ...
18
24
ValueError: Non-binary value was passed to the function
19
25
"""
20
26
bin_string = str (bin_string ).strip ()
@@ -28,9 +34,7 @@ def bin_to_decimal(bin_string: str) -> int:
28
34
decimal_number = 0
29
35
for char in bin_string :
30
36
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
34
38
35
39
36
40
if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -17,14 +17,20 @@ def hex_to_decimal(hex_string: str) -> int:
17
17
>>> hex_to_decimal("-Ff")
18
18
-255
19
19
>>> hex_to_decimal("F-f")
20
+ Traceback (most recent call last):
21
+ ...
20
22
ValueError: Non-hexadecimal value was passed to the function
21
23
>>> 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
23
27
>>> hex_to_decimal("12m")
28
+ Traceback (most recent call last):
29
+ ...
24
30
ValueError: Non-hexadecimal value was passed to the function
25
31
"""
26
32
hex_string = hex_string .strip ().lower ()
27
- if not hex_string:
33
+ if not hex_string :
28
34
raise ValueError ("Empty string was passed to the function" )
29
35
is_negative = hex_string [0 ] == "-"
30
36
if is_negative :
@@ -34,9 +40,7 @@ def hex_to_decimal(hex_string: str) -> int:
34
40
decimal_number = 0
35
41
for char in hex_string :
36
42
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
40
44
41
45
42
46
if __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
3
2
4
3
from file_transfer .send_file import send_file
5
4
Original file line number Diff line number Diff line change 1
1
"""Non recursive implementation of a DFS algorithm."""
2
2
3
- from typing import Set , Dict
3
+ from typing import Dict , Set
4
4
5
5
6
6
def depth_first_search (graph : Dict , start : str ) -> Set [int ]:
You can’t perform that action at this time.
0 commit comments