示例#1
0
 def test_is_palindrome_with_mixed_casing_and_punctuation(self):
     # palindromes with whitespace, punctuation and mixed letter casing
     assert is_palindrome('No, On!') is True
     assert is_palindrome('Dog God?') is True
     assert is_palindrome('Taco? Cat.') is True
     assert is_palindrome('Race-Car!!!') is True
     assert is_palindrome('Race Fast, Safe Car...') is True
     assert is_palindrome('Was it a car or a cat I saw?') is True
     assert is_palindrome("Go hang a salami, I'm a lasagna hog.") is True
     assert is_palindrome('A man, a plan, a canal - Panama!') is True
     assert is_palindrome('Lisa Bonet, ate no basil!') is True
     assert is_palindrome(
         'Marge let a mooDy baby dooM... a telegram. :(') is True
示例#2
0
 def test_is_palindrome_with_mirrored_strings(self):
     # palindromes that are perfectly mirrored strings
     assert is_palindrome('') is True  # base case
     assert is_palindrome('A') is True  # base case
     assert is_palindrome('BB') is True  # even length
     assert is_palindrome('LOL') is True  # odd length
     assert is_palindrome('noon') is True
     assert is_palindrome('radar') is True
     assert is_palindrome('doggod') is True
     assert is_palindrome('racecar') is True
     assert is_palindrome('!@#$%^') is True
示例#3
0
 def test_is_palindrome_with_mixed_casing_and_punctuation(self):
     # palindromes with whitespace, punctuation and mixed letter casing
     assert is_palindrome('No, On!') is True
     assert is_palindrome('Dog God?') is True
     assert is_palindrome('Taco? Cat.') is True
     assert is_palindrome('Race-Car!!!') is True
     assert is_palindrome('Race Fast, Safe Car...') is True
     assert is_palindrome('Was it a car or a cat I saw?') is True
     assert is_palindrome("Go hang a salami, I'm a lasagna hog.") is True
     assert is_palindrome('A man, a plan, a canal - Panama!') is True
     assert is_palindrome('Ko, Ok!') is True
 def test_character_repetition(self):
     bees = ['b' * x for x in xrange(1, 10)]
     for b in bees:
         self.assert_(
             palindromes.is_palindrome(b),
             "Says %d of the same character in a row isn't a palindrome" %
             len(b)
         )
示例#5
0
 def test_is_palindrome_with_mixed_casing(self):
     # palindromes with mixed letter casing
     assert is_palindrome('Bb') is True
     assert is_palindrome('Lol') is True
     assert is_palindrome('NoOn') is True
     assert is_palindrome('Radar') is True
     assert is_palindrome('DogGod') is True
     assert is_palindrome('DOgGod') is True
     assert is_palindrome('DOgbOd') is False
     assert is_palindrome('RaceCar') is True
def is_likely_lychrel(n):
    def reverse_int(n):
        return int(str(n)[::-1])

    for _ in range(LIKELY_LYCHREL_ITERATIONS):
        n = n + reverse_int(n)
        if is_palindrome(n):
            return False
    return True
 def test_is_palindrome_with_mirrored_strings(self):
     # simple palindromes that are mirrored strings
     assert is_palindrome('') is True  # base case
     assert is_palindrome('A') is True  # base case
     assert is_palindrome('BB') is True
     assert is_palindrome('LOL') is True
     assert is_palindrome('noon') is True
     assert is_palindrome('radar') is True
     assert is_palindrome('racecar') is True
示例#8
0
 def test_is_palindrome_with_whitespace_and_punctuation(self):
     # palindromes with whitespace and punctuation
     assert is_palindrome('B-B') is True
     assert is_palindrome('no, on!') is True
     assert is_palindrome('dog god?') is True
     assert is_palindrome('taco? cat.') is True
     assert is_palindrome('race-car!!!') is True
     assert is_palindrome('race fast, safe car...') is True
     assert is_palindrome('N-N') is True
示例#9
0
 def test_is_palindrome_with_whitespace(self):
     # palindromes with whitespace
     assert is_palindrome('B B') is True
     assert is_palindrome('no on') is True
     assert is_palindrome('dog god') is True
     assert is_palindrome('taco cat') is True
     assert is_palindrome('race car') is True
     assert is_palindrome('race fast safe car') is True
     assert is_palindrome('A A') is True
示例#10
0
 def test_is_palindrome_with_whitespace_and_punctuation(self):
     # palindromes with whitespace and punctuation
     assert is_palindrome('B-B') is True
     assert is_palindrome('no, on!') is True
     assert is_palindrome('dog god?') is True
     assert is_palindrome('taco? cat.') is True
     assert is_palindrome('race-car!!!') is True
     assert is_palindrome('race fast, safe car...') is True
     assert is_palindrome('marge let a moody baby doom a telegram.') is True
示例#11
0
 def test_is_palindrome_with_whitespace_and_mixed_casing(self):
     # palindromes with whitespace and mixed letter casing
     assert is_palindrome('B b') is True
     assert is_palindrome('No On') is True
     assert is_palindrome('Dog God') is True
     assert is_palindrome('Taco Cat') is True
     assert is_palindrome('Race Car') is True
     assert is_palindrome('Race Fast Safe Car') is True
     assert is_palindrome('K K') is True
 def test_is_palindrome_with_non_palindromic_strings(self):
     assert is_palindrome('AB') is False  # even length
     assert is_palindrome('ABC') is False  # odd length
     assert is_palindrome('doge') is False
     assert is_palindrome('monkey') is False
     assert is_palindrome('chicken, monkey!') is False
     assert is_palindrome('ABBCA') is False
示例#13
0
def largest_palindromic_for_digits(digits, limit=None):
    top = int('9' * digits)
    bot = int('9' * (digits - 1))
    best = 0
    for a in range(top, bot, -1):
        for b in range(top, bot, -1):
            n = a * b
            if limit and n >= limit:
                continue
            if n < best:
                break
            if is_palindrome(n):
                best = n
    return best
 def test_is_palindrome_with_mixed_casing_and_punctuation(self):
     # palindromes with whitespace, punctuation and mixed letter casing
     assert is_palindrome('Race fast, safe car.') is True
     assert is_palindrome('Was it a car or a cat I saw?') is True
     assert is_palindrome("Go hang a salami, I'm a lasagna hog.") is True
     assert is_palindrome('A man, a plan, a canal - Panama!') is True
示例#15
0
 def test_EmptyPalindrome(self):
     self.assertTrue(is_palindrome(""))
示例#16
0
 def test_is_palindrome_with_numbers_and_letters(self):
     # palindromes with mixed letter casing
     assert is_palindrome('4Lol4') is True
     assert is_palindrome('34NoOn43') is True
     assert is_palindrome('34NoOn34') is False
示例#17
0
 def test_is_palindrome_with_mixed_casing_and_punctuation(self):
     # palindromes with whitespace, punctuation and mixed letter casing
     assert is_palindrome('No, On!') is True
     assert is_palindrome('Dog God?') is True
     assert is_palindrome('Taco? Cat.') is True
     assert is_palindrome('Race-Car!!!') is True
     assert is_palindrome('Race Fast, Safe Car...') is True
     assert is_palindrome('Was it a car or a cat I saw?') is True
     assert is_palindrome("Go hang a salami, I'm a lasagna hog.") is True
     assert is_palindrome('A man, a plan, a canal - Panama!') is True
     assert is_palindrome('No lemon, no melon!') is True
     assert is_palindrome('Eva, can I see bees in a cave?') is True
     assert is_palindrome('Red rum, sir, is murder!') is True
     assert is_palindrome('Step on no pets.') is True
示例#18
0
 def test_NonPalindrome2(self):
     self.assertFalse(is_palindrome("ZoE.,EoZ"))
示例#19
0
 def test_OneLetterPalindrome(self):
     self.assertTrue(is_palindrome("W"))
示例#20
0
    def test_CaseResitance2(self):

        self.assertTrue(is_palindrome("Se0Es"))
示例#21
0
 def test_identifies_palindromes(self):
     for word, expectation in cases:
         self.assertEqual(is_palindrome(word), expectation)
 def test_is_palindrome_with_whitespace_and_punctuation(self):
     # palindromes with whitespace and punctuation
     assert is_palindrome('taco cat!') is True
     assert is_palindrome('race, car!!') is True
     assert is_palindrome('race fast, safe car.') is True
 def test_is_palindrome_with_mixed_casing(self):
     # palindromes with mixed leter casing
     assert is_palindrome('Bb') is True
     assert is_palindrome('NoOn') is True
     assert is_palindrome('Radar') is True
     assert is_palindrome('RaceCar') is True
    def test_is_palindrome(self):
        for s in palindrome_strings:
            self.assertTrue(is_palindrome(s), "{} should be a palindrome".format(s))

        for s in random_strings:
            self.assertFalse(is_palindrome(s), "{} should not be a palindrome".format(s))
示例#25
0
def disable_print(*args):
    raise Exception("You must not call print anywhere in your code!")


def disable_input(*args):
    raise Exception("You must not call input anywhere in your code!")


builtins.print = disable_print
builtins.input = disable_input

import palindromes

# palindromes.is_palindrome
result = palindromes.is_palindrome('aba')
assert isinstance(result, bool), \
    '''palindromes.is_palindrome should return a bool, but returned {0}
       '''.format(type(result))

# palindromes.is_palindromic_phrase
result = palindromes.is_palindromic_phrase('ab.a')
assert isinstance(result, bool), \
    '''palindromes.is_palindromic_phrase should return a bool, but returned {0}
       '''.format(type(result))

# palindromes.get_odd_palindrome_at
result = palindromes.get_odd_palindrome_at('aba', 1)
assert isinstance(result, str), \
    '''palindromes.get_odd_palindrome_at should return a str, but returned {0}
       '''.format(type(result))
示例#26
0
 def test_CaseResistance1(self):
     self.assertTrue(is_palindrome("SaAs"))
 def test_empty_string(self):
     self.assert_(palindromes.is_palindrome(''),
                  "Says the empty string isn't a palindrome.")
示例#28
0
 def test_BasicPalindrome3(self):
     self.assertTrue(is_palindrome("So|163361|Os"))
示例#29
0
def test():
    assert is_palindrome(585) and is_palindrome(to_binary(585))
示例#30
0
 def test_is_palindrome(self):
     self.assertTrue(is_palindrome('1'))
     self.assertTrue(is_palindrome('101'))
     self.assertFalse(is_palindrome('100'))
     self.assertFalse(is_palindrome('10'))
示例#31
0
def dec_and_bin_palindromes(m):
    for n in range(1, m):
        if is_palindrome(n) and is_palindrome(to_binary(n)):
            yield n
示例#32
0
 def test_NonPalindrome1(self):
     self.assertFalse(is_palindrome("Soze"))
示例#33
0
 def test_is_palindrome_with_non_palindromic_strings(self):
     # examples of non-palindromic strings that should be rejected
     assert is_palindrome('AB') is False  # even length
     assert is_palindrome('ABC') is False  # odd length
     assert is_palindrome('AAB') is False
     assert is_palindrome('AABB') is False
     assert is_palindrome('AAABB') is False
     assert is_palindrome('AAABBB') is False
     assert is_palindrome('ABCZBA') is False
     assert is_palindrome('ABCCZA') is False
     assert is_palindrome('ABCCBZ') is False
     assert is_palindrome('ABCDZCBA') is False
     assert is_palindrome('ABCDDZBA') is False
     assert is_palindrome('ABCDDCZA') is False
     assert is_palindrome('ABCDDCBZ') is False
     assert is_palindrome('AAAAZAAA') is False
     assert is_palindrome('AAAAAAAZ') is False
示例#34
0
 def test_is_palindrome(self):
     self.assertEqual(palindromes.is_palindrome(12321), True);
     self.assertEqual(palindromes.is_palindrome(12345678987654321), True);
     self.assertEqual(palindromes.is_palindrome(12332), False);
     self.assertEqual(palindromes.is_palindrome(100101), False);