def test_non_empty_string(self):
        """Test for palindrome in non empty string"""

        store = []
        expected_store = ["madam", "Level", "Brian"]
        arg1 = "madam"
        actual = is_palindrome(arg1, store)
        expected = True
        message = "Expected {}, but returned {}".format(expected, actual)
        self.assertEqual(actual, expected, message)

        arg2 = "Level"
        actual = is_palindrome(arg2, store)
        expected = True
        message = "Expected {}, but returned {}".format(expected, actual)
        self.assertEqual(actual, expected, message)

        arg3 = "Brian"
        actual = is_palindrome(arg3, store)
        expected = False
        message = "Expected {}, but returned {}".format(expected, actual)
        self.assertEqual(actual, expected)
        message = "Expected {} as record, but returned {}".format(
            expected_store, store)
        self.assertEqual(store, expected_store, message)
Exemplo n.º 2
0
def sum_double_base_palindrome(num):
    sum = 0
    for i in range(num+1):
        if palindrome.is_palindrome(i,10) and palindrome.is_palindrome(i,2):
           sum += i

    return sum
    def test_return_true_if_palindrome(self):
        expected = True

        result1 = p.is_palindrome(self.example2)
        result2 = p.is_palindrome(self.example1)

        self.assertEqual(expected, result1)
        self.assertEqual(expected, result2)
    def test_palindromes(self):
        otto = 'otto'
        hannah = 'hannah'
        tacocat = 'tacocat'

        self.assertTrue(is_palindrome(otto))
        self.assertTrue(is_palindrome(hannah))
        self.assertTrue(is_palindrome(tacocat))
Exemplo n.º 5
0
def test_is_string():
    """
    Test Requirement: `is_palindrome` raises a `ValueError` when not provided with a value
      that is  an instance of `str`.
    """

    with pytest.raises(ValueError):
        is_palindrome(1881)
Exemplo n.º 6
0
def p_score(n):
    score = 1
    if is_palindrome(n):
        return score
    else:
        while is_palindrome(n) == False:
            score += 1
            n = int(reverse_obj(n)) + n
    return score
Exemplo n.º 7
0
def ans():
    sum_ = 0
    for i in range(1000000):
        if (
            is_palindrome(str(i)) and
            is_palindrome("{0:b}".format(i))
        ):
            sum_ += i
    return sum_
Exemplo n.º 8
0
def test_basic():
    """ Basic test for palindrome """

    # True positives
    for test in ('Rotator','bob','madam','mAlAyAlam', '1'):
        assert palindrome.is_palindrome(test)==True

    # True negatives
    for test in ('xyz','elephant', 'Country'):
        assert palindrome.is_palindrome(test)==False        
    def test_last_five_records(self):
        """Test for keeping of record of last five entries
        """

        store = ["a", "b", "Hello", "try", "level"]
        expected_store = ["b", "Hello", "try", "level", "bayesian nets"]
        arg1 = "bayesian nets"
        is_palindrome(arg1, store)
        message = "Expected {} as record, but returned {}".format(
            expected_store, store)
        self.assertEqual(store, expected_store, message)
Exemplo n.º 10
0
def test_with_spaces():
    """ Testing palindrome strings with extra spaces """

    # True positives
    for test in ('Able was I ere I saw Elba', 'Madam Im Adam',
                 'Step on no pets', 'Top spot'):
        assert palindrome.is_palindrome(test) == True

    # True negatives
    for test in ('Top post', 'Wonderful fool', 'Wild Imagination'):
        assert palindrome.is_palindrome(test) == False
Exemplo n.º 11
0
def test_with_punctuations():
    """ Testing palindrome strings with extra punctuations """

    # True positives
    for test in ('Able was I, ere I saw Elba',
                 "Madam I'm Adam",
                 'Step on no pets.',
                 'Top spot!'):
        assert palindrome.is_palindrome(test)==True

    # True negatives
    for test in ('Top . post','Wonderful-fool','Wild Imagination!!'):
        assert palindrome.is_palindrome(test)==False            
Exemplo n.º 12
0
def next_hack(n):
    while True:
        n += 1
        binary = bin_num_to_str(n)
        if is_palindrome(binary) and is_odd_one(n):
            break
    return n
Exemplo n.º 13
0
    def test_with_palindromes_and_non_palindromes(self):
        """is_palindrome returns True for a palindrome and False for a non-palindrome. (1p)"""
        palindromes = ("dad", "121", "GAATTCCTTAAG",
                       "rats live on no evil star")
        for palindrome in palindromes:
            self.assertTrue(
                is_palindrome(palindrome),
                "{0!r} is a palindrome but your function says it is not.".
                format(palindrome))

        not_palindromes = ("aabb", "12", "da", "certainly not a palindrome")
        for not_palindrome in not_palindromes:
            self.assertFalse(
                is_palindrome(not_palindrome),
                "{0!r} is not a palindrome but your function says it is.".
                format(not_palindrome))
Exemplo n.º 14
0
def test_this_sentence_is_looooong():
    """
    `(/1)` `is_palindrome` returns `True` when called with `"Able was I ere I saw
      Elba"`.
    """

    assert is_palindrome("Able was I ere I saw Elba") is True
Exemplo n.º 15
0
def main():
	for line in open('words.txt'):
		#remove whitespace from the beginning and end
		word = line.strip()
		#only print palindromes
		if is_palindrome(word):
			print word
Exemplo n.º 16
0
def ans():
    largest = 0
    for x in range(100, 999):
        for y in range(x, 999):
            product = x * y
            if is_palindrome(str(product)) and largest < product:
                largest = product
    return largest
Exemplo n.º 17
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
Exemplo n.º 18
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
Exemplo n.º 19
0
def test_is_palindrome_ShouldRetrunFalseIfEmpty():
    # arrange
    sut = LinkedList()

    # act
    result = is_palindrome(sut)

    # assert
    assert result == False
Exemplo n.º 20
0
def problem004(digits=3):
    """Brute force the search space."""
    answers = set()
    for i in range(10 ** (digits - 1), 10 ** digits):
        for j in range(i, 10 ** digits):
            answers.add(i * j)
    for i in sorted(list(answers), key=lambda score: -score):
        if is_palindrome(i):
            return i
Exemplo n.º 21
0
def main():
    for line in open('words.txt'):

        # remove whitespace from the beginning and end
        word = line.strip()

        # only print palindromes
        if is_palindrome(word):
            print word
Exemplo n.º 22
0
def is_lychrel(n):
    iterations = 0
    while True:
        n += int(''.join(reversed(str(n))))
        iterations += 1
        if is_palindrome(str(n)):
            return False
        if 50 < iterations:
            return True
Exemplo n.º 23
0
def lar_3_palindrome():
    d3 = list(range(100, 1000))
    d3 = list(permutations(d3, 2))
    a = 0
    for elem in d3:
        n = elem[0] * elem[1]
        if is_palindrome(n):
            if n > a:
                a = n
    return a
Exemplo n.º 24
0
def lar_3_palindrome():
	d3 = list(range(100,1000))
	d3 = list(permutations(d3,2))
	a = 0
	for elem in d3:
		n = elem[0] * elem[1]
		if is_palindrome(n):
			if n>a:
				a = n
	return a
Exemplo n.º 25
0
    def test_palindrome(self):
        strings = {
            'dovod': True,
            'nedovod': False,
            'parrap': True,
            'neparrap': False
        }

        for string, prediction in strings.items():
            self.assertEqual(is_palindrome(string), prediction)
 def test_is_palindrome(self):
     test_cases = [("redivider", True), ("deified", True), ("civic", True),
                   ("radar", True), ("level", True),
                   ("Mr Owl ate my metal worm", True),
                   ("Do geese see God", True),
                   ("Was it a car or a cat I saw", True),
                   ("Murder for a jar of red rum", True),
                   ("palindrome", False), ("Python", False)]
     for str_in, expected in test_cases:
         with self.subTest(f"{str_in} -> {expected}"):
             self.assertEqual(expected, palindrome.is_palindrome(str_in))
 def test_Test_Cases_From_File(self):
     f = open(currentdir + '/PalindromesToTest.txt', 'r')
     TestCasesForPalindromes = MakeTestCaseList(f.read())
     f.close()
     for TestCaseForPalindrome in TestCasesForPalindromes:
         with self.subTest():
             self.assertEqual(
                 is_palindrome(TestCaseForPalindrome[0]),
                 TestCaseForPalindrome[1].lower() == "true", '---' +
                 TestCaseForPalindrome[0] + '--- does not test: ---' +
                 TestCaseForPalindrome[1] + '---')
Exemplo n.º 28
0
def test_palindrome():
  assert palindrome.is_palindrome("sagas") == True
  assert palindrome.is_palindrome("saga") == False
  assert palindrome.is_palindrome("Sagas") == True
  assert palindrome.is_palindrome("salt an ATLAS") == True
  assert palindrome.is_palindrome("Satan oscillate my metallic sonatas") == True
  assert palindrome.is_palindrome("Satan oscillate my wooden sonatas") == False
def test_palindrome():
    assert(is_palindrome("safdasffsadfas"))
    assert(not is_palindrome("safdasffsadfaq"))
    assert(not is_palindrome("safdasfqsadfas"))
    assert(is_palindrome("s"))
    assert(is_palindrome("asa"))
    assert(not is_palindrome("sa"))
Exemplo n.º 30
0
 def test_palindrome(self):
     self.assertTrue(is_palindrome("safdasffsadfas"))
     self.assertFalse(is_palindrome("safdasffsadfaq"))
     self.assertFalse(is_palindrome("safdasfqsadfas"))
     self.assertTrue(is_palindrome("s"))
     self.assertTrue(is_palindrome("asa"))
     self.assertFalse(is_palindrome("sa"))
Exemplo n.º 31
0
def test_is_palindrome_ShouldRetrunTrueIfPalindromeEvenLength():
    # arrange
    sut = LinkedList()
    sut.add_first("a")
    sut.add_first("b")
    sut.add_first("b")
    sut.add_first("a")

    # act
    result = is_palindrome(sut)

    # assert
    assert result == True
Exemplo n.º 32
0
def test_is_palindrome_ShoulRetrunFalseIfNotPalindrome():
    # arrange
    sut = LinkedList()
    sut.add_first("a")
    sut.add_first("b")
    sut.add_first("b")
    sut.add_first("d")

    # act
    result = is_palindrome(sut)

    # assert
    assert result == False
Exemplo n.º 33
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
Exemplo n.º 34
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
Exemplo n.º 35
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
Exemplo n.º 36
0
 def tweeted(self, screen_name, tweet):
     """Called with each screen name and tweet"""
     palindrome = is_palindrome_sentence(tweet)
     if(not palindrome is False):
         print("palindrome sentence: %s" %tweet)
         return
     
     words = [word.strip() for word in tweet.split()]
     for word in words:
         palindrome = is_palindrome(word)
         if(palindrome):
             print("palindrome: %s" % palindrome)
             break
         
         palindrome = is_sarahpalindrome(word)
         if(palindrome):
             print("sarahpalindrome: %s" % palindrome)
             break
Exemplo n.º 37
0
 def test_palindrome_is_palindrome(self):
     """is_palindrome should recognize a palindrome"""
     expected = True
     self.assertEqual(expected, is_palindrome('racecar'))
Exemplo n.º 38
0
 def test_non_palindrome_is_not_palindrome(self):
     """is_palindrome should not think a non-palindrome is a palindrome"""
     expected = False
     self.assertEqual(expected, is_palindrome('not a palindrome'))
 def test4(self):
     self.assertEqual(False, is_palindrome('My name is Keith.'))
Exemplo n.º 40
0
 def test_one_english_quotes(self):
     self.assertTrue(is_palindrome('Madam, I’m Adam'))
Exemplo n.º 41
0
 def test_one_int_non(self):
     self.assertFalse(is_palindrome(543))
Exemplo n.º 42
0
from palindrome import is_palindrome

print sorted([m * n for n in xrange(1, 1000) for m in xrange(1, 1000) if is_palindrome(str(m * n))])[-1]
 def test3(self):
     self.assertEqual(True, is_palindrome('Madam, I\'m Adam'))
Exemplo n.º 44
0
 def test_one_word2(self):
     self.assertTrue(is_palindrome('Коллок'))
Exemplo n.º 45
0
 def test_simple_values(self):
     self.assertTrue(is_palindrome('stunt nuts'))
 def test2(self):
     self.assertEqual(True, is_palindrome('A man, a plan, a canal - Panama!'))
Exemplo n.º 47
0
import palindrome
import prime
import itertools
import sys
from functools import reduce

P = prime.Prime()


for n in range(999*999,100*100,-1) :
    if palindrome.is_palindrome(n) :
        #print(n)
        fac = P.factorization(n)
        if fac[-1] > 1000 :
            continue
        for i in range(1,int(len(fac)/2)+1) :
            for comb in itertools.combinations(fac,i) :
                mul = reduce(lambda x,y:x*y,comb)
                remain = n/mul
                if mul>100 and mul<1000 and remain>100 and remain<1000 :
                    print(n)
                    sys.exit(0)
                
                

Exemplo n.º 48
0
 def test_one_prase_non(self):
     self.assertFalse(is_palindrome('А роза упала 1на лапу Азора'))
 def test1(self):
     self.assertEqual(True, is_palindrome('Able was I ere I saw Elba'))
Exemplo n.º 50
0
 def test_one_prase1(self):
     self.assertTrue(is_palindrome('А роза упала на лапу Азора'))
Exemplo n.º 51
0
 def test_non_palindromes(self):
     self.assertFalse(is_palindrome('i am not a palindrome'))
Exemplo n.º 52
0
 def test_one_non(self):
     self.assertFalse(is_palindrome('Просто'))
Exemplo n.º 53
0
 def test_even_numbers(self):
     self.assertTrue(is_palindrome('toot'))
Exemplo n.º 54
0
 def test_one_word1(self):
     self.assertTrue(is_palindrome('Шалаш'))
Exemplo n.º 55
0
 def test_odd_numbers(self):
     self.assertTrue(is_palindrome('tot'))
Exemplo n.º 56
0
 def test_one_int(self):
     self.assertTrue(is_palindrome(404))
Exemplo n.º 57
0
 def test_complex_sentences(self):
     self.assertTrue(is_palindrome('A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal: Panama!'))
Exemplo n.º 58
0
 def test_complete_sentences(self):
     self.assertTrue(is_palindrome('Lisa Bonet ate no basil.'))
Exemplo n.º 59
0
 def test_multiple_sentences(self):
     self.assertTrue(is_palindrome('Doc, note, I dissent. A fast never prevents a fatness. I diet on cod.'))