示例#1
0
 def testPodeConstruirUmAutomatoQueGeraApenasEpsilon(self): 
   afd = construirAFDQueGeraEpsilon()
   afd2 = util.gerar_automato_finito_epsilon()
   afd3 = util.gerar_automato_finito('a')
   
   self.assertTrue(util.sao_equivalentes_af(afd, afd2))
   self.assertFalse(util.sao_equivalentes_af(afd, afd3))
    def testModificacoesQueNaoAlteramLinguagem(self):
        exp1 = ExpressaoRegular("a*a*a*")
        exp2 = ExpressaoRegular("a*")
        self.assertTrue(util.sao_equivalentes_af(exp1.obterAFD(), exp2.obterAFD()))

        exp1 = ExpressaoRegular("a|b")
        exp2 = ExpressaoRegular("b|a")
        self.assertTrue(util.sao_equivalentes_af(exp1.obterAFD(), exp2.obterAFD()))
    def testModificacoesQueAlteramLinguagem(self):
        exp1 = ExpressaoRegular("a?a?a?")
        exp2 = ExpressaoRegular("a?")
        self.assertFalse(util.sao_equivalentes_af(exp1.obterAFD(), exp2.obterAFD()))

        exp1 = ExpressaoRegular("a.b")
        exp2 = ExpressaoRegular("b.a")
        self.assertFalse(util.sao_equivalentes_af(exp1.obterAFD(), exp2.obterAFD()))
    def testRobustezDaTransformacaoDaEREmAFD(self):
        automato = construirAFDComABOndeAsEhPar()
        exp_reg = ExpressaoRegular("(b*ab*a)*b*")
        afd_exp = exp_reg.obterAFD()
        self.assertTrue(util.sao_equivalentes_af(automato, afd_exp))

        automato = construirAFDComABOndeBsEhImpar()
        exp_reg = ExpressaoRegular("a*ba* (a*ba*ba*)*")
        afd_exp = exp_reg.obterAFD()
        self.assertTrue(util.sao_equivalentes_af(automato, afd_exp))
示例#5
0
 def testDadaUmaGramaticaRegularSabeQualEhOSeuAFDMinimoCorrespondente(self):
   afd1 = construirAFDComABOndeAsEhPar()
   afd2 = util.obter_afd(construirGRComABOndeAsEhPar())
   
   self.assertTrue(util.sao_equivalentes_af(afd1, afd2))
   self.assertTrue(afd2.ehDeterministico())
   self.assertTrue(afd2.ehMinimo())
    def clicouTestarEquivalencia(self):
        try:
            exp1 = ExpressaoRegular(str(self.__ui.exp_reg1.text()))
            exp2 = ExpressaoRegular(str(self.__ui.exp_reg2.text()))
            if util.sao_equivalentes_af(exp1.obterAFD(), exp2.obterAFD()):
                self.__ui.sao_equivalentes.setText("OK")
            else:
                self.__ui.sao_equivalentes.setText("NOK")

        except Exception as excecao:
            self._error.showMessage(str(excecao))
示例#7
0
 def testDadoUmAFPodeAplicarFechamentoPositivoNoMesmo(self):
   afd1 = construirAFDQueGeraOSimboloA()
   afd_pos = util.obter_fechamento_positivo_af(afd1)
   self.assertEqual(len(afd_pos.obterEstados()), len(afd1.obterEstados()))
   self.assertFalse(util.sao_equivalentes_af(afd1, afd_pos))
   
   self.assertTrue(afd1.reconhecePalavra('a'))
   self.assertFalse(afd1.reconhecePalavra('aa'))
   self.assertTrue(afd_pos.reconhecePalavra('aa'))
   self.assertTrue(afd_pos.reconhecePalavra('aaa'))
   self.assertTrue(afd_pos.reconhecePalavra('a'))
   self.assertFalse(afd_pos.reconhecePalavra(EPSILON))
    def testSabeQualEhOSeuAFDMinimoCorrespondente(self):
        estados = set()
        estados.add(Estado("q0", set([Transicao("a", "q1")]), True, False))
        estados.add(Estado("q1", set([Transicao("b", "q1"), Transicao("c", "q2")]), False, False))
        estados.add(Estado("q2", set(), False, True))
        alfabeto = set(["a", "b", "c"])

        automato_a_bEstrela_c = AutomatoFinito(alfabeto, estados)
        exp_reg = ExpressaoRegular("ab*c")
        afd_exp = exp_reg.obterAFD()
        self.assertTrue(util.sao_equivalentes_af(automato_a_bEstrela_c, afd_exp))
        self.assertTrue(afd_exp.ehDeterministico())
        self.assertTrue(afd_exp.ehMinimo())
 def testReconheceOOperadorInterrogacao(self):
     exp1 = ExpressaoRegular("a?")
     exp2 = ExpressaoRegular("a|" + EPSILON)
     self.assertTrue(util.sao_equivalentes_af(exp1.obterAFD(), exp2.obterAFD()))
 def testReconheceOOperadorFechamentoPosito(self):
     exp1 = ExpressaoRegular("a+")
     exp2 = ExpressaoRegular("aa*")
     self.assertTrue(util.sao_equivalentes_af(exp1.obterAFD(), exp2.obterAFD()))
示例#11
0
 def testDadoUmAFDSabeQualEhASuaGramaticaRegularCorrespondenteQuandoAFDNaoProduzEpsilon(self):
   gr1 = util.obter_gramatica_regular(construirAFDComABOndeBsEhImpar())
   afd1  = util.obter_afd(gr1)
   afd2 = construirAFDComABOndeBsEhImpar()
   
   self.assertTrue(util.sao_equivalentes_af(afd1, afd2))
 def testReconheceOEpsilonComoCaracterEspecialEGeraUmAutomatoMinimoQueGeraEpsilon(self):
     exp = ExpressaoRegular(EPSILON)
     self.assertTrue(util.sao_equivalentes_af(exp.obterAFD(), construirAFDQueGeraEpsilon()))
示例#13
0
 def testDadosDoisAFSabeSeElesNaoSaoEquivalentes(self):
   afd1 = construirAFDComABOndeAsEhPar()
   afd2 = construirAFDComABOndeBsEhImpar()
   self.assertFalse(util.sao_equivalentes_af(afd1, afd2)) 
 def testDefineEscopoDosParentesisCorretamente(self):
     exp1 = ExpressaoRegular("(a) | (b)")
     exp2 = ExpressaoRegular("a|b")
     self.assertTrue(util.sao_equivalentes_af(exp1.obterAFD(), exp2.obterAFD()))
示例#15
0
 def testDadosDoisAFSabeSeElesSaoEquivalentes(self):
   afd1 = construirAFDComABOndeAsEhPar()
   afd2 = construirEquivalenteDoAFDComABOndeAsEhPar()
   self.assertTrue(util.sao_equivalentes_af(afd1, afd2))
示例#16
0
 def testSeTodosOsEstadosSaoVivosNaoRemoveEstadoAlgum(self):
   afd_novo = util.remover_estados_mortos_afd(construirAFDSemEstadosMortosOuInalcancaveis())
   self.assertEqual(len(afd_novo.obterEstados()), len(construirAFDSemEstadosMortosOuInalcancaveis().obterEstados()))
   self.assertTrue(util.sao_equivalentes_af(afd_novo,construirAFDSemEstadosMortosOuInalcancaveis()))
示例#17
0
 def testDadoUmAFNDRetornaUmAFDEquivalente(self):
   self.assertFalse(self.afnd.ehDeterministico())
   afd = util.determinizar_af(self.afnd)
   self.assertTrue(afd.ehDeterministico())
   self.assertTrue(util.sao_equivalentes_af(self.afnd, afd))
示例#18
0
 def testDadoUmAFDPodeRemoveTodosOsEstadosInalcancaveis(self):
   afd_novo = util.remover_estados_inalcancaveis_afd(self.afd_um_estado_inalcancavel)
   self.assertEqual(3, len(self.afd_um_estado_inalcancavel.obterEstados()))
   self.assertEqual(2, len(afd_novo.obterEstados()))
   self.assertTrue(util.sao_equivalentes_af(self.afd_um_estado_inalcancavel, afd_novo))
示例#19
0
 def testPodeSalvarECarregarUmAutomatoFinitoDoDisco(self):
   afd1 = construirAFDComABOndeBsEhImpar()
   util.salvar(afd1, os.path.join(os.getcwd(), 'teste.af'))
   afd2 = util.carregar(os.path.join(os.getcwd(), 'teste.af'))
   self.assertTrue(util.sao_equivalentes_af(afd1, afd2))
示例#20
0
 def testPodeSalvarECarregarUmaGramaticaRegularDoDisco(self):
   gr1 = util.obter_gramatica_regular(construirAFDComABOndeBsEhImpar())
   util.salvar(gr1, os.path.join(os.getcwd(), 'teste.gr'))
   gr2 = util.carregar(os.path.join(os.getcwd(), 'teste.gr'))
   self.assertTrue(util.sao_equivalentes_af(util.obter_afd(gr1), util.obter_afd(gr2)))
示例#21
0
 def testPodeSalvarECarregarUmaExpressaoRegularDoDisco(self):
   exp = ExpressaoRegular('a*b?.(ab)')
   util.salvar(exp, os.path.join(os.getcwd(), 'teste.exp'))
   exp2 = util.carregar(os.path.join(os.getcwd(), 'teste.exp'))
   self.assertTrue(util.sao_equivalentes_af(exp.obterAFD(), exp2.obterAFD()))
示例#22
0
 def testUnirDoisAutomatosQueGeramEpsilonGeraOMesmoAutomato(self):
   afd = util.gerar_automato_finito_epsilon()
   afd2 = util.unir_af(util.gerar_automato_finito_epsilon(), util.gerar_automato_finito_epsilon())
   self.assertTrue(util.sao_equivalentes_af(afd, afd2))
示例#23
0
 def testDadoUmAFDImcompletoPodeGerarUmNovoAFDCompletoEquivalente(self):
   afd_imcompleto = construirAFDImcompleto()
   self.assertFalse(afd_imcompleto.ehCompleto())
   afd_completo = util.completar_af(afd_imcompleto)
   self.assertTrue(afd_completo.ehCompleto())
   self.assertTrue(util.sao_equivalentes_af(afd_imcompleto,afd_completo))
示例#24
0
 def testPodeConstruirOAutomatoQueGeraUmDadoSimbolo(self):
   afd = construirAFDQueGeraOSimboloA()
   afd2 = util.gerar_automato_finito('a')
   afd3 = util.gerar_automato_finito('b')
   self.assertTrue(util.sao_equivalentes_af(afd, afd2))
   self.assertFalse(util.sao_equivalentes_af(afd, afd3)) 
示例#25
0
 def testDadoUmAFDNaoMinimoGeraUmAFDMinimoEquivalente(self):
   afd_nao_minimo = construirAFDNaoMinimo()
   self.assertFalse(afd_nao_minimo.ehMinimo())
   afd_minimo = util.minimizar_afd(afd_nao_minimo)
   self.assertTrue(afd_minimo.ehMinimo())
   self.assertTrue(util.sao_equivalentes_af(afd_nao_minimo,afd_minimo))
 def testNaoImportaAQuantidadeDeParentesis(self):
     exp1 = ExpressaoRegular("((( a* b((ab))* b )))")
     exp2 = ExpressaoRegular(" a* b(ab)* b ")
     self.assertTrue(util.sao_equivalentes_af(exp1.obterAFD(), exp2.obterAFD()))
 def testExpressaoRegPodeEstarTodaEmglobadaEmParenteses(self):
     exp1 = ExpressaoRegular("( a* b(ab)* b )")
     exp2 = ExpressaoRegular(" a* b(ab)* b ")
     self.assertTrue(util.sao_equivalentes_af(exp1.obterAFD(), exp2.obterAFD()))
示例#28
0
 def testDadoUmAFDPodeRemoverTodosOsEstadosMortos(self):
   afd_novo = util.remover_estados_mortos_afd(self.afd_um_estado_morto)
   self.assertEqual(3, len(self.afd_um_estado_morto.obterEstados()))
   self.assertEqual(2, len(afd_novo.obterEstados()))
   self.assertTrue(util.sao_equivalentes_af(afd_novo,self.afd_um_estado_morto))
示例#29
0
 def testDadoUmAFDQueGeraApenasUmSimboloSabeQualEhASuaGramaticaRegularCorrespondente(self):
   gr1 = util.obter_gramatica_regular(construirAFDQueGeraOSimboloA())
   afd1  = util.obter_afd(gr1)
   afd2 = construirAFDQueGeraOSimboloA()
   
   self.assertTrue(util.sao_equivalentes_af(afd1, afd2))