Пример #1
0
    def test010_test_output(self):
        '''is_palindrome: testing output of function is a boolean

        Your is_palindrome function not returning a boolean

        '''
        self.assertEqual(type(lab5.is_palindrome('asdf')), bool)
Пример #2
0
    def test010_test_output(self):
        '''is_palindrome: testing output of function is a boolean

        Your is_palindrome function not returning a boolean

        '''
        self.assertEqual(type(lab5.is_palindrome('asdf')), bool)
Пример #3
0
    def test016_test_output(self):
        '''is_palindrome: testing output of function is correct

        Your is_palindrome function should return True for the
        argument: 'bananab'

        '''
        self.assertEqual(lab5.is_palindrome('bananab'), True)
Пример #4
0
    def test015_test_output(self):
        '''is_palindrome: testing output of function is correct

        Your is_palindrome function should return False for the
        argument: 'hello'

        '''
        self.assertEqual(lab5.is_palindrome('hello'), False)
Пример #5
0
    def test016_test_output(self):
        '''is_palindrome: testing output of function is correct

        Your is_palindrome function should return True for the
        argument: 'bananab'

        '''
        self.assertEqual(lab5.is_palindrome('bananab'), True)
Пример #6
0
    def test015_test_output(self):
        '''is_palindrome: testing output of function is correct

        Your is_palindrome function should return False for the
        argument: 'hello'

        '''
        self.assertEqual(lab5.is_palindrome('hello'),False)
Пример #7
0
    def test020_test_output(self):
        '''is_palindrome: testing output of function is correct

        Your is_palindrome function is not returning the correct
        output

        '''
        p = lambda v: ''.join(reversed(v)) == v
        for a0 in ['aaaa', 'asdf', 'abcddcba', 'hello', 'olbbbblo']:
            self.assertEqual(lab5.is_palindrome(a0), p(a0))
Пример #8
0
    def test020_test_output(self):
        '''is_palindrome: testing output of function is correct

        Your is_palindrome function is not returning the correct
        output

        '''
        p = lambda v: ''.join(reversed(v))==v
        for a0 in ['aaaa','asdf','abcddcba','hello','olbbbblo']:
            self.assertEqual(lab5.is_palindrome(a0), p(a0))
Пример #9
0
def main():

    while True:
        print("\nPlease type an option from the menu, or press anything "
              "else to quit:")
        print("\t h: Calculate the Hamming distance between two strings "
              "of equal length.")
        print("\t h2: Hamming distance between two strings of any length")
        print("\t p: Check if a string is a palindrome.")
        choice = input("\t ")

        if choice == "p":
            input_str = input("Please type the string that you would "
                              "like to check: ")
            if l.is_palindrome(input_str):
                print(input_str, " is a palindrome")
            else:
                print(input_str, "is not a palindrome")

        elif choice == "h":
            input_str1 = input("Please enter the first string: ")
            input_str2 = input("Please enter the second git sstring: ")
            #check inputs
            if len(input_str1) == len(input_str2):
                hamming_dist = l.hamming_distance(input_str1, input_str2)
                print("The hamming distance between '{}' and '{}' is {}."\
                    .format(input_str1, input_str2, hamming_dist))
            else:
                print("Please enter two strings of same length.")

        if choice == "h2":
            input_str1 = input("Please enter the first string: ")
            input_str2 = input("Please enter the second string: ")
            hamming_dist = l.hamming_distance2(input_str1, input_str2)
            print("The hamming distance between",input_str1," and ",\
                  input_str2," is ",hamming_dist)

        else:
            print("Goodbye!")
            break