Skip to content

Commit 6e03a48

Browse files
authored
test: cover palindrome edge cases with doctests (#15609)
1 parent f7109c5 commit 6e03a48

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎strings/palindrome.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def is_palindrome(s: str) -> bool:
2424
2525
>>> all(is_palindrome(key) == value for key, value in test_data.items())
2626
True
27+
>>> is_palindrome("")
28+
True
2729
"""
2830

2931
start_i = 0
@@ -43,6 +45,8 @@ def is_palindrome_traversal(s: str) -> bool:
4345
4446
>>> all(is_palindrome_traversal(key) == value for key, value in test_data.items())
4547
True
48+
>>> is_palindrome_traversal("")
49+
True
4650
"""
4751
end = len(s) // 2
4852
n = len(s)
@@ -62,6 +66,8 @@ def is_palindrome_recursive(s: str) -> bool:
6266
6367
>>> all(is_palindrome_recursive(key) == value for key, value in test_data.items())
6468
True
69+
>>> is_palindrome_recursive("")
70+
True
6571
"""
6672
if len(s) <= 1:
6773
return True
@@ -77,6 +83,8 @@ def is_palindrome_slice(s: str) -> bool:
7783
7884
>>> all(is_palindrome_slice(key) == value for key, value in test_data.items())
7985
True
86+
>>> is_palindrome_slice("")
87+
True
8088
"""
8189
return s == s[::-1]
8290

@@ -96,6 +104,10 @@ def is_palindrome_ignore_case_and_spaces(s: str) -> bool:
96104
True
97105
>>> is_palindrome_ignore_case_and_spaces("")
98106
True
107+
>>> is_palindrome_ignore_case_and_spaces(" !?. ")
108+
True
109+
>>> is_palindrome_ignore_case_and_spaces("1a2")
110+
False
99111
"""
100112
s = "".join(char.lower() for char in s if char.isalnum())
101113
return s == s[::-1]

0 commit comments

Comments
 (0)