Beispiel #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
Beispiel #2
0
 def test_afw_to_nfa_conversion_empty_transitions(self):
     """ Tests a AFW to NFA conversion with a AFW without transitions """
     self.afw_afw_to_nfa_test_01['transitions'] = {}
     nfa_01 = AFW.afw_to_nfa_conversion(self.afw_afw_to_nfa_test_01)
     result = {
         'initial_states': {('s',)},
         'accepting_states': {('s',)},
         'transitions': {},
         'states': {('s',)},
         'alphabet': {'b', 'a'}
     }
     self.assertSetEqual(nfa_01['initial_states'], result['initial_states'])
     self.assertDictEqual(nfa_01['transitions'], result['transitions'])
     self.assertSetEqual(nfa_01['alphabet'], result['alphabet'])
     self.assertEqual(len(nfa_01['accepting_states']),
                      len(result['accepting_states']))
     self.assertEqual(len(nfa_01['states']), len(result['states']))
Beispiel #3
0
 def test_afw_to_nfa_conversion_language_bis_bis(self):
     """ Test a correct afw conversion to nfa comparing the language read 
     by the two automaton """
     nfa_01 = AFW.afw_to_nfa_conversion(self.afw_nonemptiness_check_test_2)
     # automata_IO.nfa_to_dot(nfa_01, 'afw_to_nfa_strange')
     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)
             afw_acceptance = AFW.afw_word_acceptance(
                 self.afw_nonemptiness_check_test_2, word)
             nfa_acceptance = NFA.nfa_word_acceptance(nfa_01, word)
             self.assertEqual(afw_acceptance, nfa_acceptance)
         i += 1
Beispiel #4
0
 def test_afw_to_nfa_conversion_side_effects(self):
     """ Tests the function doesn't make any side effect on the input """
     before = copy.deepcopy(self.afw_afw_to_nfa_test_01)
     AFW.afw_to_nfa_conversion(self.afw_afw_to_nfa_test_01)
     self.assertDictEqual(before, self.afw_afw_to_nfa_test_01)
Beispiel #5
0
 def test_afw_to_nfa_conversion_wrong_dict(self):
     """ Tests the function using an input different from a well 
     formatted dict representing a afw. [EXPECTED FAILURE] """
     AFW.afw_to_nfa_conversion({'goofy': 'donald'})
Beispiel #6
0
 def test_afw_to_nfa_conversion_wrong_input(self):
     """ Tests the function using an input different from a dict object. 
     [EXPECTED FAILURE] """
     AFW.afw_to_nfa_conversion(0)
Beispiel #7
0
 def test_afw_to_nfa_conversion_empty_states(self):
     """ Tests a AFW to NFA conversion with an empty AFW """
     nfa_01 = AFW.afw_to_nfa_conversion(self.afw_afw_to_nfa_test_empty)
     self.nfa_empty['initial_states'] = {(None,)}
     self.nfa_empty['states'] = self.nfa_empty['initial_states']
     self.assertDictEqual(nfa_01, self.nfa_empty)