def test_non_string_objects_return_false(self): # noinspection PyTypeChecker self.assertFalse(is_palindrome(1)) # noinspection PyTypeChecker self.assertFalse(is_palindrome(['xx'])) # noinspection PyTypeChecker self.assertFalse(is_palindrome({})) # noinspection PyTypeChecker self.assertFalse(is_palindrome(False)) # noinspection PyTypeChecker self.assertFalse(is_palindrome((1, 2, 3))) # noinspection PyTypeChecker self.assertFalse(is_palindrome(object()))
import string_utils assert 'rento' == string_utils.remove_special_char( 'ren@to'), 'remove_special_char .... FAILED' print('remove_special_char .... SUCCESS') assert 'otaner' == string_utils.reverse('renato'), 'reverse .... FAILED' print('reverse .... SUCCESS') assert string_utils.is_palindrome('ana'), 'is_palindrome .... FAILED' print('is_palindrome .... SUCCESS')
def test_if_not_specified_case_matters(self): self.assertFalse(is_palindrome('Lol')) self.assertTrue(is_palindrome('Lol', ignore_case=True))
def test_if_not_specified_spaces_matter(self): self.assertFalse(is_palindrome('i topi non avevano nipoti')) self.assertTrue( is_palindrome('i topi non avevano nipoti', ignore_spaces=True))
def test_returns_true_if_palindrome_with_default_options(self): self.assertTrue(is_palindrome('LOL')) self.assertTrue(is_palindrome('otto'))
def test_returns_false_if_not_palindrome_with_default_options(self): self.assertFalse(is_palindrome('nope!')) self.assertFalse(is_palindrome('ROTFL'))
def test_empty_strings_are_not_palindromes(self): self.assertFalse(is_palindrome('')) self.assertFalse(is_palindrome(' ')) self.assertFalse(is_palindrome('\n\t\n'))
def test_not_a_palindrome_is_not_a_palindrome(self): s = 'Rats live on no evil sta G' self.assertFalse(string_utils.is_palindrome(s, ignore_spaces=False))
def test_unless_we_care_about_case(self): s = 'Rats live on no evil sta r' self.assertFalse(string_utils.is_palindrome(s, ignore_case=False))
def test_a_palindrome_is_a_palindrome_regardless_of_spaces_and_case(self): s = 'Rats live on no evil sta r' self.assertTrue(string_utils.is_palindrome(s))
def test_one_letter_is_a_palindrom(self): random_char = random.choice([c for c in string.ascii_lowercase]) self.assertTrue(string_utils.is_palindrome(random_char))