Esempio n. 1
0
 def test_nfa_complementation_empty_transitions(self):
     """ Tests a NFA complementation with a NFA without
     transitions """
     self.nfa_complementation_test_01['transitions'] = {}
     dfa_complemented = NFA.nfa_complementation(
         self.nfa_complementation_test_01)
     # automata_IO.dfa_to_dot(dfa_complemented,
     # 'nfa_complemented_empty_transition')
     self.assertDictEqual(
         dfa_complemented, {
             'alphabet':
             self.nfa_complementation_test_01['alphabet'],
             'states': {
                 str(self.nfa_complementation_test_01['initial_states']),
                 "sink"
             },
             'initial_state':
             str(self.nfa_complementation_test_01['initial_states']),
             'accepting_states': {
                 str(self.nfa_complementation_test_01['initial_states']),
                 "sink"
             },
             'transitions': {
                 ('sink', 'a'):
                 'sink',
                 ('sink', 'b'):
                 'sink',
                 (str(self.nfa_complementation_test_01['initial_states']), 'b'):
                 'sink',
                 (str(self.nfa_complementation_test_01['initial_states']), 'a'):
                 'sink'
             }
         })
Esempio n. 2
0
 def test_nfa_complementation(self):
     """ Tests a correct nfa complementation """
     dfa_complemented = NFA.nfa_complementation(
         self.nfa_complementation_test_01)
     self.assertEqual(len(dfa_complemented['alphabet']), 2)
     self.assertEqual(len(dfa_complemented['states']), 10 + 1)
     self.assertEqual(len(dfa_complemented['accepting_states']), 4 + 1)
     self.assertEqual(len(dfa_complemented['transitions']), 22)
Esempio n. 3
0
 def test_nfa_complementation_empty_states(self):
     """ Tests a NFA complementation with an empty NFA """
     dfa_complemented = NFA.nfa_complementation(
         self.nfa_complementation_test_empty)
     # automata_IO.dfa_to_dot(dfa_complemented,
     # 'nfa_complemented_empty_States')
     self.assertDictEqual(
         dfa_complemented, {
             'alphabet': set(),
             'states': {'sink'},
             'initial_state': None,
             'accepting_states': {'sink'},
             'transitions': {}
         })
Esempio n. 4
0
    def complement(self):
        if self.special_attr == 'true':
            return FiniteAutomaton.false_aut()
        elif self.special_attr == 'false':
            return FiniteAutomaton.true_aut()
        else:
            # print('PERFORMING COMPLEMENT')
            # print(self.relabel_states().to_str())
            new_aut = NFA.nfa_complementation(self.aut)

            # Convert to an NFA
            new_aut['initial_states'] = {new_aut.pop('initial_state')}
            new_aut['transitions'] = {
                k: [v]
                for k, v in new_aut.pop('transitions').items()
            }

            res = FiniteAutomaton(new_aut, self.var_map)
            # print(res.relabel_states().to_str())
            return res
Esempio n. 5
0
 def test_nfa_complementation_side_effects(self):
     """ Tests the function doesn't make any side effect on
     the input """
     before = copy.deepcopy(self.nfa_complementation_test_01)
     NFA.nfa_complementation(self.nfa_complementation_test_01)
     self.assertDictEqual(before, self.nfa_complementation_test_01)
Esempio n. 6
0
 def test_nfa_complementation_wrong_dict(self):
     """ Tests the function using an input different from a
     well formatted dict representing a nfa. [EXPECTED
     FAILURE] """
     NFA.nfa_complementation({'goofy': 'donald'})
Esempio n. 7
0
 def test_nfa_complementation_wrong_input(self):
     """ Tests the function using an input different from a
     dict object. [EXPECTED FAILURE] """
     NFA.nfa_complementation(0)