예제 #1
0
 def test_lps_expansion(self):
     p = Palindrome()
     assert_equal(p.longest_palindrome_substring('', LPS_EXPANSION), '')
     assert_equal(p.longest_palindrome_substring('a', LPS_EXPANSION), 'a')
     assert_equal(p.longest_palindrome_substring('ab', LPS_EXPANSION), 'a')
     assert_equal(p.longest_palindrome_substring('abc', LPS_EXPANSION), 'a')
     assert_equal(p.longest_palindrome_substring('ababa', LPS_EXPANSION), 'ababa')
     assert_equal(p.longest_palindrome_substring('abaaba', LPS_EXPANSION), 'abaaba')
     assert_equal(p.longest_palindrome_substring('abcfgcba', LPS_EXPANSION), 'a')
     assert_equal(p.longest_palindrome_substring(s, LPS_EXPANSION), 'ranynar')
     assert_equal(p.longest_palindrome_substring(r, LPS_EXPANSION), r)
예제 #2
0
 def test_lps_lcs(self):
     p = Palindrome()
     assert_equal(p.longest_palindrome_substring('', LPS_LCS), '')
     assert_equal(p.longest_palindrome_substring('a', LPS_LCS), 'a')
     assert_equal(p.longest_palindrome_substring('ab', LPS_LCS), 'a')
     assert_equal(p.longest_palindrome_substring('abc', LPS_LCS), 'a')
     assert_equal(p.longest_palindrome_substring('ababa', LPS_LCS), 'ababa')
     assert_equal(p.longest_palindrome_substring('abaaba', LPS_LCS), 'abaaba')
     assert_equal(p.longest_palindrome_substring('abcfgcba', LPS_LCS), 'a')
     assert_equal(p.longest_palindrome_substring(s, LPS_LCS), 'ranynar')
     assert_equal(p.longest_palindrome_substring(r, LPS_LCS), r)
예제 #3
0
 def test_lps_manacher(self):
     p = Palindrome()
     assert_equal(p.longest_palindrome_substring('', LPS_MANACHER), '')
     assert_equal(p.longest_palindrome_substring('a', LPS_MANACHER), 'a')
     assert_equal(p.longest_palindrome_substring('ab', LPS_MANACHER), 'a')
     assert_equal(p.longest_palindrome_substring('abc', LPS_MANACHER), 'a')
     assert_equal(p.longest_palindrome_substring('ababa', LPS_MANACHER), 'ababa')
     assert_equal(p.longest_palindrome_substring('abaaba', LPS_MANACHER), 'abaaba')
     assert_equal(p.longest_palindrome_substring('abcfgcba', LPS_MANACHER), 'a')
     assert_equal(p.longest_palindrome_substring(s, LPS_MANACHER), 'ranynar')
     assert_equal(p.longest_palindrome_substring(r, LPS_MANACHER), r)
예제 #4
0
def normal():
    try:
        if args.in_file:
            with open(args.in_file) as file_in:
                text = file_in.read()
        else:
            text = input('Enter the text for constructing palindromes:\n')

        palindrome = Palindrome(text)
        list_pal = palindrome.create_list_pal()

        if args.out_file:
            with open(args.out_file, 'w') as file_out:
                file_out.write('\n'.join(list_pal))
        else:
            print('Constructed palindromes:')
            for i in list_pal:
                print(i)
    except Exception as e:
        sys.exit("Error: {0}".format(e))
import pytest
from palindrome import Palindrome

p1 = Palindrome()


def test_true():
    assert p1.palindrome('abba') == True
    assert p1.palindrome('abcba') == True
    assert p1.palindrome('1234321') == True
    assert p1.palindrome('123321') == True
    assert p1.palindrome(')(*&*()') == True
    assert p1.palindrome(')(**()') == True


def test_false():
    assert p1.palindrome('ab') == False
    assert p1.palindrome('abca') == False
    assert p1.palindrome('1234') == False
    assert p1.palindrome('!@#$%^') == False


def test_typeerror():
    with pytest.raises(TypeError) as e_info:
        p1.palindrome(1)
        p1.palindrome(1.0)
        p1.palindrome(123456789010)
예제 #6
0
def test():
    lever = Palindrome.test()
    if not lever:
        print("Test is passed")
    else:
        print("Test fails")
예제 #7
0
 def setUp(self):
     self.p1 = Palindrome('abcd')
     self.p2 = Palindrome('abcdedcba')
 def setUp(self):
     '''
     Set up method to run before each test case
     '''
     self.new_palindrome = Palindrome("Madam")
 def test_save_multiple_palindromes(self):
     self.new_palindrome.save_palindrome()
     test_palindrome = Palindrome("level")
     test_palindrome.save_palindrome()
     self.assertEqual(len(Palindrome.palindrome_list), 2)
예제 #10
0
 def setUp(self):
     print("SETUP")
     self.palindrome = Palindrome("344")
예제 #11
0
class TestTestCase(unittest.TestCase):
    def setUp(self):
        self.pal = Palindrome()

    def test_generate_permutations(self):
        result = self.pal.generate_permutations("a b")
        self.assertTrue(result == ["a","b","ab","ba"])
        result = self.pal.generate_permutations("a b c")
        self.assertTrue(result == ['a', 'b', 'c', 'ab', 'ac', 'ba', 'bc', 'ca',
        'cb', 'abc', 'acb', 'bac', 'bca', 'cab', 'cba'])

    def test_check_palindromes(self):
        self.assertTrue(self.pal.check_palindrome("a"))
        self.assertTrue(self.pal.check_palindrome("9"))
        self.assertTrue(self.pal.check_palindrome("aa"))
        self.assertTrue(self.pal.check_palindrome("aba"))
        self.assertTrue(self.pal.check_palindrome("abba"))
        self.assertTrue(self.pal.check_palindrome("1234321"))
        self.assertFalse(self.pal.check_palindrome("ab"))
        self.assertFalse(self.pal.check_palindrome("98"))
        self.assertFalse(self.pal.check_palindrome("abca"))
        self.assertFalse(self.pal.check_palindrome("abcda"))
        self.assertFalse(self.pal.check_palindrome("1234521"))

    def test_look_for_palindromes(self):
        result = self.pal.look_for_palindromes(["ab","aba","abcb","abcba"])
        self.assertTrue(result == ["aba","abcba"])
예제 #12
0
 def setUp(self):
     self.palindrome = Palindrome()
예제 #13
0
 def test_palindrome_palindromeTrue(self):
     p = Palindrome()
     self.assertTrue(p.is_palindrome(121))
     self.assertTrue(p.is_palindrome(11))
     self.assertTrue(p.is_palindrome(12521))
     self.assertTrue(p.is_palindrome(1))
예제 #14
0
 def test_types(self):
     p = Palindrome()
     self.assertRaises(TypeError, p.is_palindrome, '121')
     self.assertRaises(TypeError, p.is_palindrome, [123])
     self.assertRaises(TypeError, p.is_palindrome, 12.21)
예제 #15
0
 def test_palindrome_Zero(self):
     p = Palindrome()
     self.assertTrue(p.is_palindrome(0))
예제 #16
0
 def test_palindrome_notPalindromeNeg(self):
     p = Palindrome()
     self.assertFalse(p.is_palindrome(-121))
예제 #17
0
 def test_palindrome_palindromeFalse(self):
     p = Palindrome()
     self.assertFalse(p.is_palindrome(12))
     self.assertFalse(p.is_palindrome(11222))
예제 #18
0
from armstrong import Armstrong
from factor import Factor
from factorial import Factorial
from fibonacci import Fibonacci
from palindrome import Palindrome
from prime import Prime

print("Armstrong", bool(Armstrong(153)))

print("Fibonacci", [i for i in Fibonacci(5)])

print("Palindrome", bool(Palindrome(12321)))

print("Prime", bool(Prime(10007)))

print("Factors", [i for i in Factor(23)])

print("Factorial", Factorial(6)())
예제 #19
0
파일: 004.py 프로젝트: hogejiro/peppy
def main():
    P = Palindrome()
    ans = P.get_largest_palindrome_product_of_two_numbers_by_keta(3)
    print ans