From 66ab2a1f615aa9d6524d117072c2d454f8a4b816 Mon Sep 17 00:00:00 2001 From: Scarfinos Date: Sun, 27 Oct 2024 23:35:36 +0100 Subject: [PATCH 1/2] #9943 : adding some coverage for string --- strings/barcode_validator.py | 4 ++++ strings/can_string_be_rearranged_as_palindrome.py | 2 ++ strings/check_anagrams.py | 2 ++ strings/count_vowels.py | 8 ++++++++ strings/credit_card_validator.py | 2 ++ strings/is_valid_email_address.py | 7 ++++++- strings/min_cost_string_conversion.py | 8 ++++++++ strings/string_switch_case.py | 2 ++ 8 files changed, 34 insertions(+), 1 deletion(-) diff --git a/strings/barcode_validator.py b/strings/barcode_validator.py index b4f3864e2..95aa495fa 100644 --- a/strings/barcode_validator.py +++ b/strings/barcode_validator.py @@ -59,6 +59,10 @@ def get_barcode(barcode: str) -> int: >>> get_barcode("8718452538119") 8718452538119 + >>> get_barcode("-367062129") + Traceback (most recent call last): + ... + ValueError: The entered barcode has a negative value. Try again. >>> get_barcode("dwefgiweuf") Traceback (most recent call last): ... diff --git a/strings/can_string_be_rearranged_as_palindrome.py b/strings/can_string_be_rearranged_as_palindrome.py index 95cda8b72..eb85ac2ed 100644 --- a/strings/can_string_be_rearranged_as_palindrome.py +++ b/strings/can_string_be_rearranged_as_palindrome.py @@ -14,6 +14,8 @@ def can_string_be_rearranged_as_palindrome_counter( """ A Palindrome is a String that reads the same forward as it does backwards. Examples of Palindromes mom, dad, malayalam + >>> can_string_be_rearranged_as_palindrome("") + True >>> can_string_be_rearranged_as_palindrome_counter("Momo") True >>> can_string_be_rearranged_as_palindrome_counter("Mother") diff --git a/strings/check_anagrams.py b/strings/check_anagrams.py index d747368b2..1cbfac070 100644 --- a/strings/check_anagrams.py +++ b/strings/check_anagrams.py @@ -9,6 +9,8 @@ def check_anagrams(first_str: str, second_str: str) -> bool: """ Two strings are anagrams if they are made up of the same letters but are arranged differently (ignoring the case). + >>> check_anagrams('This', 'These') + False >>> check_anagrams('Silent', 'Listen') True >>> check_anagrams('This is a string', 'Is this a string') diff --git a/strings/count_vowels.py b/strings/count_vowels.py index 8a52b331c..ac20f94d8 100644 --- a/strings/count_vowels.py +++ b/strings/count_vowels.py @@ -6,6 +6,14 @@ def count_vowels(s: str) -> int: :return: Number of vowels in the input string. Examples: + >>> count_vowels(10) + Traceback (most recent call last): + ... + ValueError: Input must be a string + >>> count_vowels(True) + Traceback (most recent call last): + ... + ValueError: Input must be a string >>> count_vowels("hello world") 3 >>> count_vowels("HELLO WORLD") diff --git a/strings/credit_card_validator.py b/strings/credit_card_validator.py index b8da1c745..716531cd0 100644 --- a/strings/credit_card_validator.py +++ b/strings/credit_card_validator.py @@ -27,6 +27,8 @@ def luhn_validation(credit_card_number: str) -> bool: True >>> luhn_validation('41111111111111') False + >>> luhn_validation('4678001415') + True """ cc_number = credit_card_number total = 0 diff --git a/strings/is_valid_email_address.py b/strings/is_valid_email_address.py index c3bf7df73..a92a45986 100644 --- a/strings/is_valid_email_address.py +++ b/strings/is_valid_email_address.py @@ -32,6 +32,11 @@ email_tests: tuple[tuple[str, bool], ...] = ( ), ("i.like.underscores@but_its_not_allowed_in_this_part", False), ("", False), + (".startdot@example", False), + ("enddot.@example", False), + ("double..dot@example", False), + ("example@-dashstart", False), + ("example@dashend-", False), ) # The maximum octets (one character as a standard unicode character is one byte) @@ -97,7 +102,7 @@ def is_valid_email_address(email: str) -> bool: return False # (6.) Validate the placement of "-" characters - if domain.startswith("-") or domain.endswith("."): + if domain.startswith("-") or domain.endswith("-"): return False # (7.) Validate the placement of "." characters diff --git a/strings/min_cost_string_conversion.py b/strings/min_cost_string_conversion.py index a5a3c4a4e..ca210d11f 100644 --- a/strings/min_cost_string_conversion.py +++ b/strings/min_cost_string_conversion.py @@ -91,6 +91,14 @@ def assemble_transformation(ops: list[list[str]], i: int, j: int) -> list[str]: >>> y1 = len(ops1[0]) - 1 >>> assemble_transformation(ops1, x1, y1) [] + + >>> ops2 = [['0', 'Ic', 'Iu'], + ... ['Da', 'Da', 'Rau'], + ... ['Dt', 'Dt', 'Rtu']] + >>> x2 = len(ops2) - 1 + >>> y2 = len(ops2[0]) - 1 + >>> assemble_transformation(ops2, x2, y2) + ['Ic', 'Da', 'Rtu'] """ if i == 0 and j == 0: return [] diff --git a/strings/string_switch_case.py b/strings/string_switch_case.py index c16d9fa55..3d1f79b87 100644 --- a/strings/string_switch_case.py +++ b/strings/string_switch_case.py @@ -88,6 +88,8 @@ def to_pascal_case(text: str) -> str: def to_camel_case(text: str) -> str: """ + >>> to_camel_case("") + 'not valid string' >>> to_camel_case("one two 31235three4four") 'oneTwo31235three4four' """ From 23fac3c479d99eb79f4d3b9f5f0e9f101fc2eee9 Mon Sep 17 00:00:00 2001 From: Scarfinos Date: Wed, 30 Oct 2024 09:55:48 +0100 Subject: [PATCH 2/2] #9943 : improve coverage of average_mode.py --- maths/average_mode.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maths/average_mode.py b/maths/average_mode.py index 40f88f41f..7a2ed1827 100644 --- a/maths/average_mode.py +++ b/maths/average_mode.py @@ -7,6 +7,8 @@ def mode(input_list: list) -> list[Any]: The input list may contain any Datastructure or any Datatype. + >>> mode([]) + [] >>> mode([2, 3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 2, 2, 2]) [2] >>> mode([3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 4, 2, 2, 2])