mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Renamed files and fixed Doctest (#2421)
* * Renamed files * Fiexed doctest * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
20e98fcded
commit
d6bff5c133
|
@ -11,10 +11,16 @@ def bin_to_decimal(bin_string: str) -> int:
|
|||
>>> bin_to_decimal("0")
|
||||
0
|
||||
>>> bin_to_decimal("a")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-binary value was passed to the function
|
||||
>>> bin_to_decimal("")
|
||||
ValueError: Empty string value was passed to the function
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Empty string was passed to the function
|
||||
>>> bin_to_decimal("39")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-binary value was passed to the function
|
||||
"""
|
||||
bin_string = str(bin_string).strip()
|
||||
|
@ -28,9 +34,7 @@ def bin_to_decimal(bin_string: str) -> int:
|
|||
decimal_number = 0
|
||||
for char in bin_string:
|
||||
decimal_number = 2 * decimal_number + int(char)
|
||||
if is_negative:
|
||||
decimal_number = -decimal_number
|
||||
return decimal_number
|
||||
return -decimal_number if is_negative else decimal_number
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
|
@ -17,14 +17,20 @@ def hex_to_decimal(hex_string: str) -> int:
|
|||
>>> hex_to_decimal("-Ff")
|
||||
-255
|
||||
>>> hex_to_decimal("F-f")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-hexadecimal value was passed to the function
|
||||
>>> hex_to_decimal("")
|
||||
ValueError: Empty string value was passed to the function
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Empty string was passed to the function
|
||||
>>> hex_to_decimal("12m")
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Non-hexadecimal value was passed to the function
|
||||
"""
|
||||
hex_string = hex_string.strip().lower()
|
||||
if not hex_string:
|
||||
if not hex_string:
|
||||
raise ValueError("Empty string was passed to the function")
|
||||
is_negative = hex_string[0] == "-"
|
||||
if is_negative:
|
||||
|
@ -34,9 +40,7 @@ def hex_to_decimal(hex_string: str) -> int:
|
|||
decimal_number = 0
|
||||
for char in hex_string:
|
||||
decimal_number = 16 * decimal_number + hex_table[char]
|
||||
if is_negative:
|
||||
decimal_number = -decimal_number
|
||||
return decimal_number
|
||||
return -decimal_number if is_negative else decimal_number
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
|
@ -1,5 +1,4 @@
|
|||
from unittest.mock import patch, Mock
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from file_transfer.send_file import send_file
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Non recursive implementation of a DFS algorithm."""
|
||||
|
||||
from typing import Set, Dict
|
||||
from typing import Dict, Set
|
||||
|
||||
|
||||
def depth_first_search(graph: Dict, start: str) -> Set[int]:
|
||||
|
|
Loading…
Reference in New Issue
Block a user