class UserInterface:
    def __init__(self):
        self.__ctrl = Controller()

    def print_menu(self):
        print('0. Exit')
        print('1. Add DNA')
        print('2. Filter DNA')
        print('3. Nu stiu ce scrie pe tabla da stiu ce face')

    def run(self):
        while True:
            self.print_menu()

            inp = input('>> ')
            if inp == '0':
                exit()
            elif inp == '1':
                dna_string = input('Input DNA sequence: ')
                if not self.__ctrl.add_dna(dna_string):
                    print('Invalid DNA sequence entered')
            elif inp == '2':
                dna_substring = input('Input DNA subsequence: ')
                filtered_dna_list = self.__ctrl.filter_dna_by_subseq(
                    dna_substring)
                print(filtered_dna_list)
            elif inp == '3':
                filtered_dna_list = self.__ctrl.filter_punct3()
                print(filtered_dna_list)
            else:
                print('Invalid command entered!')
Example #2
0
class TestDNA(unittest.TestCase):
    def run(self):
        self.__ctrl = Controller()

        self.assertFalse(self.__ctrl.add_dna('GATAX'))
        self.assertFalse(self.__ctrl.add_dna(''))

        # 101 de caractere - invalid
        self.assertFalse(
            self.__ctrl.add_dna(
                'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
            ))

        # 100 caractere - valid
        self.assertTrue(
            self.__ctrl.add_dna(
                'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
            ))

        self.assertTrue(self.__ctrl.add_dna('GATCAGGCTAGCTAGTCA'))
        self.assertTrue(self.__ctrl.add_dna('GGGGGGGGGGGGGGGGAT'))

        self.__ctrl.clear_repo()
        self.__ctrl.add_dna('GATA')
        self.__ctrl.add_dna('GTAAA')
        self.__ctrl.add_dna('GTTTTTTT')

        self.assertEqual(self.__ctrl.filter_dna_by_subseq('GA'), ['GATA'])
        self.assertEqual(self.__ctrl.filter_punct3(),
                         ['GTTTTTTT', 'GTAAA', 'GATA'])

        self.__repo = Repository()
        self.assertEqual(self.__repo.get_data(), [])
        self.__repo.append('GATA')
        self.assertEqual(self.__repo.length(), 1)
        self.assertEqual(self.__repo.get_data(), ['GATA'])
        self.__repo.clear()
        self.assertEqual(self.__repo.get_data(), [])