From d2d5f346eb057f9ac8572f13bd0c7172018e0eb1 Mon Sep 17 00:00:00 2001 From: shellhub Date: Sun, 13 Sep 2020 18:21:16 +0800 Subject: [PATCH 1/2] * Renamed files * Fiexed doctest --- .../{binary_to_decimal => binary_to_decimal.py} | 14 +++++++++----- ...ecimal_to_decimal => hexadecimal_to_decimal.py} | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) rename conversions/{binary_to_decimal => binary_to_decimal.py} (78%) rename conversions/{hexadecimal_to_decimal => hexadecimal_to_decimal.py} (81%) diff --git a/conversions/binary_to_decimal b/conversions/binary_to_decimal.py similarity index 78% rename from conversions/binary_to_decimal rename to conversions/binary_to_decimal.py index 1f223daf825f..b08cb4221a03 100644 --- a/conversions/binary_to_decimal +++ b/conversions/binary_to_decimal.py @@ -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,12 +34,10 @@ 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__": from doctest import testmod - testmod() + testmod() \ No newline at end of file diff --git a/conversions/hexadecimal_to_decimal b/conversions/hexadecimal_to_decimal.py similarity index 81% rename from conversions/hexadecimal_to_decimal rename to conversions/hexadecimal_to_decimal.py index e87caa0f4787..beb1c2c3ded6 100644 --- a/conversions/hexadecimal_to_decimal +++ b/conversions/hexadecimal_to_decimal.py @@ -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__": From db109e32ffbd43de069928958ef78c639cb9c20f Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 13 Sep 2020 10:23:17 +0000 Subject: [PATCH 2/2] fixup! Format Python code with psf/black push --- conversions/binary_to_decimal.py | 2 +- file_transfer/tests/test_send_file.py | 3 +-- graphs/depth_first_search.py | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/conversions/binary_to_decimal.py b/conversions/binary_to_decimal.py index b08cb4221a03..a7625e475bdc 100644 --- a/conversions/binary_to_decimal.py +++ b/conversions/binary_to_decimal.py @@ -40,4 +40,4 @@ def bin_to_decimal(bin_string: str) -> int: if __name__ == "__main__": from doctest import testmod - testmod() \ No newline at end of file + testmod() diff --git a/file_transfer/tests/test_send_file.py b/file_transfer/tests/test_send_file.py index 170c2c0aed09..2a6008448362 100644 --- a/file_transfer/tests/test_send_file.py +++ b/file_transfer/tests/test_send_file.py @@ -1,5 +1,4 @@ -from unittest.mock import patch, Mock - +from unittest.mock import Mock, patch from file_transfer.send_file import send_file diff --git a/graphs/depth_first_search.py b/graphs/depth_first_search.py index fee9ea07728d..43f2eaaea19a 100644 --- a/graphs/depth_first_search.py +++ b/graphs/depth_first_search.py @@ -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]: