mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
#9943 : adding some coverage for string
This commit is contained in:
parent
6e24935f88
commit
66ab2a1f61
|
@ -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):
|
||||
...
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 []
|
||||
|
|
|
@ -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'
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user