Example #1
0
 def testNaUniaoSeNenhumAFTemEstadoInicialFinalOEstadoInicialNovoNaoEhFinal(self):
   afd1 = construirAFDComABOndeBsEhImpar()
   afd2 = construirAFDComABOndeBsEhImpar()
   self.assertFalse(afd1.obterEstadoInicial().ehFinal())
   self.assertFalse(afd2.obterEstadoInicial().ehFinal())
   afd1Uafd2 = util.unir_af(afd1, afd2)
   self.assertFalse(afd1Uafd2.obterEstadoInicial().ehFinal())
Example #2
0
 def testDadoAConcatenacaoDeDoisAFSeOInicialDoSegundoNaoEhFinalOsFinaisDoPrimeiroDeixamDeSerFinais(self):
   afd1 = construirAFDComABOndeAsEhPar()
   afd2 = construirAFDComABOndeBsEhImpar()
   self.assertFalse(afd2.obterEstadoInicial().ehFinal())
   afd1afd2 = util.concatenar_af(afd1, afd2)
   finais_antigos_len = len(afd1.obterEstadosFinais()) + len(afd2.obterEstadosFinais())
   self.assertTrue(finais_antigos_len > len(afd1afd2.obterEstadosFinais()))
Example #3
0
 def testNaoUniaoSeUmDosAFTemEstadoInicialFinalOEstadoInicialNovoTbEhFinal(self):
   afd1 = construirAFDComABOndeAsEhPar()
   afd2 = construirAFDComABOndeBsEhImpar()
   self.assertTrue(afd1.obterEstadoInicial().ehFinal())
   self.assertFalse(afd2.obterEstadoInicial().ehFinal())
   afd1Uafd2 = util.unir_af(afd1, afd2)
   self.assertTrue(afd1Uafd2.obterEstadoInicial().ehFinal())
    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))
Example #5
0
 def testDadoUmAFAposAplicarFechamentoPositivoNoMesmoOEstadoInicialSohEhFinalSeJaEraFinalAntes(self):
   afd1 = construirAFDComABOndeBsEhImpar()
   afd2 = construirAFDComABOndeAsEhPar()
   self.assertFalse(afd1.obterEstadoInicial().ehFinal())
   self.assertTrue(afd2.obterEstadoInicial().ehFinal())
   
   afd_pos1 = util.obter_fechamento_positivo_af(afd1)
   afd_pos2 = util.obter_fechamento_positivo_af(afd2)
   self.assertFalse(afd_pos1.obterEstadoInicial().ehFinal())
   self.assertTrue(afd_pos2.obterEstadoInicial().ehFinal())
Example #6
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))
Example #7
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)))
Example #8
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))
Example #9
0
 def testDadosDoisAFSabeSeElesNaoSaoEquivalentes(self):
   afd1 = construirAFDComABOndeAsEhPar()
   afd2 = construirAFDComABOndeBsEhImpar()
   self.assertFalse(util.sao_equivalentes_af(afd1, afd2)) 
Example #10
0
 def testDadosDoisAFSabeSeAF1NaoEstaContidoEmAF2(self):
   afd1 = construirAFDComABOndeAsEhPar()
   afd2 = construirAFDComABOndeBsEhImpar()
   self.assertFalse(util.esta_contido_af(afd1, afd2)) 
Example #11
0
 def testDadoUmAFAposAplicarFechamentoReflexivoNoMesmoOEstadoInicialSempreEhFinal(self):
   afd1 = construirAFDComABOndeBsEhImpar()
   self.assertFalse(afd1.obterEstadoInicial().ehFinal())
   afd_reflex = util.obter_fechamento_reflexivo_af(afd1)
   self.assertTrue(afd_reflex.obterEstadoInicial().ehFinal())
Example #12
0
 def testDadoDoisAFPodeConcatenalos(self):
   afd1 = construirAFDComABOndeAsEhPar()
   afd2 = construirAFDComABOndeBsEhImpar()
   afd1afd2 = util.concatenar_af(afd1, afd2)
   estados_antigos = len(afd1.obterEstados()) + len(afd2.obterEstados())
   self.assertEqual(len(afd1afd2.obterEstados()), estados_antigos)
Example #13
0
 def testDadoDoisAFPodeUnilos(self):
   afd1 = construirAFDComABOndeAsEhPar()
   afd2 = construirAFDComABOndeBsEhImpar()
   afd1Uafd2 = util.unir_af(afd1, afd2)
   estados_antigos = len(afd1.obterEstados()) + len(afd2.obterEstados())
   self.assertEqual(len(afd1Uafd2.obterEstados()) - 1, estados_antigos)
 def testSabeSeNaoReconheceEpsilon(self):
   afd = construirAFDComABOndeBsEhImpar()
   self.assertFalse(afd.reconhecePalavra(EPSILON))