From 71aaf51e9e20f48a6199b78f0c883a9bab030b97 Mon Sep 17 00:00:00 2001 From: devam007 Date: Tue, 20 Oct 2026 00:08:47 +0530 Subject: [PATCH] test: cover palindrome edge cases with doctests --- strings/palindrome.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/strings/palindrome.py b/strings/palindrome.py index 77578cc2d80d..173254300444 100644 --- a/strings/palindrome.py +++ b/strings/palindrome.py @@ -24,6 +24,8 @@ def is_palindrome(s: str) -> bool: >>> all(is_palindrome(key) == value for key, value in test_data.items()) True + >>> is_palindrome("") + True """ start_i = 0 @@ -43,6 +45,8 @@ def is_palindrome_traversal(s: str) -> bool: >>> all(is_palindrome_traversal(key) == value for key, value in test_data.items()) True + >>> is_palindrome_traversal("") + True """ end = len(s) // 2 n = len(s) @@ -62,6 +66,8 @@ def is_palindrome_recursive(s: str) -> bool: >>> all(is_palindrome_recursive(key) == value for key, value in test_data.items()) True + >>> is_palindrome_recursive("") + True """ if len(s) <= 1: return True @@ -77,6 +83,8 @@ def is_palindrome_slice(s: str) -> bool: >>> all(is_palindrome_slice(key) == value for key, value in test_data.items()) True + >>> is_palindrome_slice("") + True """ return s == s[::-1] @@ -96,6 +104,10 @@ def is_palindrome_ignore_case_and_spaces(s: str) -> bool: True >>> is_palindrome_ignore_case_and_spaces("") True + >>> is_palindrome_ignore_case_and_spaces(" !?. ") + True + >>> is_palindrome_ignore_case_and_spaces("1a2") + False """ s = "".join(char.lower() for char in s if char.isalnum()) return s == s[::-1]