Skip to content

Renamed files and fixed Doctest #2421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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__":
Expand Down
3 changes: 1 addition & 2 deletions file_transfer/tests/test_send_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from unittest.mock import patch, Mock

from unittest.mock import Mock, patch

from file_transfer.send_file import send_file

Expand Down
2 changes: 1 addition & 1 deletion graphs/depth_first_search.py
Original file line number Diff line number Diff line change
@@ -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]:
Expand Down