示例#1
0
 def testLangAcceptor_2Lines(self):
     Tape = ''
     try:
         LA = machine.LanguageAcceptor(os.path.join(os.path.dirname(__file__), 'TestFiles/two_lines.txt'))
         self.assertTrue(False)
     except:
         self.assertTrue(True)
示例#2
0
 def testLangAcceptor_goofedTrans(self):
     Tape = 'aabbcc'
     try:
         LA = machine.LanguageAcceptor(os.path.join(os.path.dirname(__file__), 'TestFiles/goofedTrans.txt'))
         self.assertTrue(False)
     except:
         self.assertTrue(True)
示例#3
0
 def testLangAcceptor_a_and_b(self):
     Tape1 = 'ababab'
     Tape2 = 'aaaaa'
     Tape3 = 'bbbbb'
     Tape4 = 'bbaabb'
     Tape5 = 'aacdbb'
     Tape6 = ''
     LA1 = machine.LanguageAcceptor(os.path.join(os.path.dirname(__file__), 'TestFiles/a_and_b.txt'))
     LA2 = machine.LanguageAcceptor(os.path.join(os.path.dirname(__file__), 'TestFiles/a_and_b.txt'))
     LA3 = machine.LanguageAcceptor(os.path.join(os.path.dirname(__file__), 'TestFiles/a_and_b.txt'))
     LA4 = machine.LanguageAcceptor(os.path.join(os.path.dirname(__file__), 'TestFiles/a_and_b.txt'))
     LA5 = machine.LanguageAcceptor(os.path.join(os.path.dirname(__file__), 'TestFiles/a_and_b.txt'))
     LA6 = machine.LanguageAcceptor(os.path.join(os.path.dirname(__file__), 'TestFiles/a_and_b.txt'))
     self.assertTrue(LA1.run(Tape1,False))
     self.assertTrue(LA2.run(Tape2,False))
     self.assertTrue(LA3.run(Tape3,False))
     self.assertTrue(LA4.run(Tape4,False))
     self.assertFalse(LA5.run(Tape5,False))
     self.assertTrue(LA6.run(Tape6,False))
示例#4
0
 def langAcceptorMenu(self) -> int:
     print('')
     print('-------------------- Language Acceptors ----------------------')
     print('1.  L = {(a^n)(b^n)(c^n), n > 0}')
     print('2.  L = {w w^R, |w w^R| is even, \u03A3 = (a,b)}')
     print('3.  Import custom language acceptor from file')
     print('4.  Back to Main Menu')
     print('')
     UserIn = input('Selection:  ')
     try:
         int(UserIn)
     except:
         print('Invalid selection.')
         return 1
     if (int(UserIn) < 1) or (int(UserIn) > 4):
         print('Invalid selection.')
         return 1
     elif int(UserIn) == 1:
         LA = machine.LanguageAcceptor(
             os.path.join(os.path.dirname(__file__),
                          'machDescriptions/anbncn.txt'))
         Tape = input('Enter the comparing string:  ')
         InLang = LA.run(Tape, VIEW_PROCESS)
         if InLang:
             print(Tape, 'is in the language!')
         else:
             print(Tape, 'is not in the language!')
         del LA
         return 1
     elif int(UserIn) == 2:
         LA = machine.LanguageAcceptor(
             os.path.join(os.path.dirname(__file__),
                          'machDescriptions/wwR.txt'))
         Tape = input('Enter the comparing string:  ')
         InLang = LA.run(Tape, VIEW_PROCESS)
         if InLang:
             print(Tape, 'is in the language!')
         else:
             print(Tape, 'is not in the language!')
         del LA
         return 1
     elif int(UserIn) == 3:
         self.__describeUserFile()
         FileLoc = input(
             'Enter the name of the file, including it\'s relative path from \nthis working directory:  '
         )
         try:
             LA = machine.LanguageAcceptor(
                 os.path.join(os.path.dirname(__file__), FileLoc))
             Tape = input('\nEnter the comparing string:  ')
             InLang = LA.run(Tape, VIEW_PROCESS)
             if InLang:
                 print(Tape, 'is in the language!')
             else:
                 print(Tape, 'is not in the language!')
             del LA
         except:
             print(
                 '\nCould not locate file!  Please check path and/or file name and try again.'
             )
         return 1
     else:
         return 0