Skip to content

Commit d6bff5c

Browse files
realDuYuanChaogithub-actions
and
github-actions
authored
Renamed files and fixed Doctest (TheAlgorithms#2421)
* * Renamed files * Fiexed doctest * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 20e98fc commit d6bff5c

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

conversions/binary_to_decimal renamed to conversions/binary_to_decimal.py

+8-4
Original file line numberDiff line numberDiff 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

3640
if __name__ == "__main__":

conversions/hexadecimal_to_decimal renamed to conversions/hexadecimal_to_decimal.py

+9-5
Original file line numberDiff line numberDiff 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

4246
if __name__ == "__main__":

file_transfer/tests/test_send_file.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from unittest.mock import patch, Mock
2-
1+
from unittest.mock import Mock, patch
32

43
from file_transfer.send_file import send_file
54

graphs/depth_first_search.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Non recursive implementation of a DFS algorithm."""
22

3-
from typing import Set, Dict
3+
from typing import Dict, Set
44

55

66
def depth_first_search(graph: Dict, start: str) -> Set[int]:

0 commit comments

Comments
 (0)