Skip to content

Commit 66ab2a1

Browse files
committed
#9943 : adding some coverage for string
1 parent 6e24935 commit 66ab2a1

8 files changed

+34
-1
lines changed

strings/barcode_validator.py

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def get_barcode(barcode: str) -> int:
5959
6060
>>> get_barcode("8718452538119")
6161
8718452538119
62+
>>> get_barcode("-367062129")
63+
Traceback (most recent call last):
64+
...
65+
ValueError: The entered barcode has a negative value. Try again.
6266
>>> get_barcode("dwefgiweuf")
6367
Traceback (most recent call last):
6468
...

strings/can_string_be_rearranged_as_palindrome.py

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def can_string_be_rearranged_as_palindrome_counter(
1414
"""
1515
A Palindrome is a String that reads the same forward as it does backwards.
1616
Examples of Palindromes mom, dad, malayalam
17+
>>> can_string_be_rearranged_as_palindrome("")
18+
True
1719
>>> can_string_be_rearranged_as_palindrome_counter("Momo")
1820
True
1921
>>> can_string_be_rearranged_as_palindrome_counter("Mother")

strings/check_anagrams.py

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def check_anagrams(first_str: str, second_str: str) -> bool:
99
"""
1010
Two strings are anagrams if they are made up of the same letters but are
1111
arranged differently (ignoring the case).
12+
>>> check_anagrams('This', 'These')
13+
False
1214
>>> check_anagrams('Silent', 'Listen')
1315
True
1416
>>> check_anagrams('This is a string', 'Is this a string')

strings/count_vowels.py

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ def count_vowels(s: str) -> int:
66
:return: Number of vowels in the input string.
77
88
Examples:
9+
>>> count_vowels(10)
10+
Traceback (most recent call last):
11+
...
12+
ValueError: Input must be a string
13+
>>> count_vowels(True)
14+
Traceback (most recent call last):
15+
...
16+
ValueError: Input must be a string
917
>>> count_vowels("hello world")
1018
3
1119
>>> count_vowels("HELLO WORLD")

strings/credit_card_validator.py

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def luhn_validation(credit_card_number: str) -> bool:
2727
True
2828
>>> luhn_validation('41111111111111')
2929
False
30+
>>> luhn_validation('4678001415')
31+
True
3032
"""
3133
cc_number = credit_card_number
3234
total = 0

strings/is_valid_email_address.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
),
3333
("i.like.underscores@but_its_not_allowed_in_this_part", False),
3434
("", False),
35+
(".startdot@example", False),
36+
("enddot.@example", False),
37+
("double..dot@example", False),
38+
("example@-dashstart", False),
39+
("example@dashend-", False),
3540
)
3641

3742
# 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:
97102
return False
98103

99104
# (6.) Validate the placement of "-" characters
100-
if domain.startswith("-") or domain.endswith("."):
105+
if domain.startswith("-") or domain.endswith("-"):
101106
return False
102107

103108
# (7.) Validate the placement of "." characters

strings/min_cost_string_conversion.py

+8
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ def assemble_transformation(ops: list[list[str]], i: int, j: int) -> list[str]:
9191
>>> y1 = len(ops1[0]) - 1
9292
>>> assemble_transformation(ops1, x1, y1)
9393
[]
94+
95+
>>> ops2 = [['0', 'Ic', 'Iu'],
96+
... ['Da', 'Da', 'Rau'],
97+
... ['Dt', 'Dt', 'Rtu']]
98+
>>> x2 = len(ops2) - 1
99+
>>> y2 = len(ops2[0]) - 1
100+
>>> assemble_transformation(ops2, x2, y2)
101+
['Ic', 'Da', 'Rtu']
94102
"""
95103
if i == 0 and j == 0:
96104
return []

strings/string_switch_case.py

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def to_pascal_case(text: str) -> str:
8888

8989
def to_camel_case(text: str) -> str:
9090
"""
91+
>>> to_camel_case("")
92+
'not valid string'
9193
>>> to_camel_case("one two 31235three4four")
9294
'oneTwo31235three4four'
9395
"""

0 commit comments

Comments
 (0)