Exemplo n.º 1
0
 def test_afw_to_nfa_conversion_language_bis(self):
     """ Test a correct afw conversion to nfa comparing the language read 
     by the two automaton.
         Here we take a nfa, we covert it to afw and back to nfa,
         then the original and final nfa are compared trough the language 
         read.
     """
     original_nfa_to_afw = AFW.nfa_to_afw_conversion(
         self.nfa_afw_to_nfa_test_01)
     nfa_01 = AFW.afw_to_nfa_conversion(original_nfa_to_afw)
     i = 0
     last = 7
     while i <= last:
         base = list(itertools.repeat('a', i))
         base += list(itertools.repeat('b', i))
         # build all permutation of 'a' and 'b' till length i
         word_set = set(itertools.permutations(base, i))
         for word in word_set:
             word = list(word)
             # print(word)
             original_nfa_acceptance = NFA.nfa_word_acceptance(
                 self.nfa_afw_to_nfa_test_01, word)
             nfa_acceptance = NFA.nfa_word_acceptance(nfa_01, word)
             self.assertEqual(original_nfa_acceptance, nfa_acceptance)
         i += 1
Exemplo n.º 2
0
 def test_nfa_to_afw_conversion_empty_states(self):
     """ Tests converting an empty nfa """
     expected_solution = {
         'alphabet': set(),
         'states': {'root'},
         'initial_state': 'root',
         'accepting_states': set(),
         'transitions': {}
     }
     self.assertDictEqual(
         AFW.nfa_to_afw_conversion(self.nfa_nfa_to_afw_test_empty),
         expected_solution)
Exemplo n.º 3
0
    def test_nfa_to_afw_conversion(self):
        """ Tests a correct nfa to afw conversion """
        afw_01 = AFW.nfa_to_afw_conversion(self.nfa_nfa_to_afw_test_01)
        self.assertSetEqual(afw_01['alphabet'],
                            self.afw_nfa_to_afw_test_01['alphabet'])
        self.assertSetEqual(afw_01['states'],
                            self.afw_nfa_to_afw_test_01['states'])
        self.assertEqual(afw_01['initial_state'],
                         self.afw_nfa_to_afw_test_01['initial_state'])
        self.assertSetEqual(afw_01['accepting_states'],
                            self.afw_nfa_to_afw_test_01['accepting_states'])

        self.assertEqual(len(afw_01['alphabet']),
                         len(self.afw_nfa_to_afw_test_01['alphabet']))
Exemplo n.º 4
0
 def test_nfa_to_afw_conversion_empty_transition(self):
     """ Tests converting an nfa without transition """
     expected_solution = {
         'alphabet': self.nfa_nfa_to_afw_test_01['alphabet'],
         'states': self.nfa_nfa_to_afw_test_01['states'].union({'root'}),
         'initial_state': 'root',
         'accepting_states': self.nfa_nfa_to_afw_test_01[
             'accepting_states'],
         'transitions': {}
     }
     self.nfa_nfa_to_afw_test_01['transitions'] = {}
     self.assertDictEqual(
         AFW.nfa_to_afw_conversion(self.nfa_nfa_to_afw_test_01),
         expected_solution)
Exemplo n.º 5
0
 def test_nfa_to_afw_conversion_side_effects(self):
     """ Tests the function doesn't make any side effect on the input """
     before = copy.deepcopy(self.nfa_nfa_to_afw_test_01)
     AFW.nfa_to_afw_conversion(self.nfa_nfa_to_afw_test_01)
     self.assertDictEqual(before, self.nfa_nfa_to_afw_test_01)
Exemplo n.º 6
0
 def test_nfa_to_afw_conversion_wrong_dict(self):
     """ Tests the function using an input different from a well 
     formatted dict representing a afw. [EXPECTED FAILURE] """
     AFW.nfa_to_afw_conversion({'goofy': 'donald'})
Exemplo n.º 7
0
 def test_nfa_to_afw_conversion_wrong_input(self):
     """ Tests the function using an input different from a dict object. 
     [EXPECTED FAILURE] """
     AFW.nfa_to_afw_conversion(0)