Beispiel #1
0
 def test_afw_completion_empty_transitions(self):
     """ Tests a completion of a afw without transitions"""
     self.afw_completion_test_01['transitions'] = {}
     result = copy.deepcopy(self.afw_completion_test_01)
     for state in result['states']:
         for action in result['alphabet']:
             result['transitions'][state, action] = 'False'
     AFW.afw_completion(self.afw_completion_test_01)
     self.assertDictEqual(self.afw_completion_test_01, result)
Beispiel #2
0
 def test_afw_completion_empty_states(self):
     """ Tests a completion of a afw without states"""
     AFW.afw_completion(self.afw_completion_test_empty)
     result = {
         'alphabet': set(),
         'states': set(),
         'initial_state': None,
         'accepting_states': set(),
         'transitions': {}
     }
     self.assertDictEqual(self.afw_completion_test_empty, result)
Beispiel #3
0
    def test_afw_completion(self):
        """ Tests a correct afw completion comparing the language read, 
        that must be the same"""
        original = copy.deepcopy(self.afw_completion_test_01)
        AFW.afw_completion(self.afw_completion_test_01)

        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)
                original_acceptance = AFW.afw_word_acceptance(original, word)
                completed_acceptance = AFW.afw_word_acceptance(
                    self.afw_completion_test_01, word)
                self.assertEqual(original_acceptance, completed_acceptance)
            i += 1
Beispiel #4
0
 def test_afw_completion_side_effects(self):
     """ Tests the function makes side effect on the input """
     before = copy.deepcopy(self.afw_completion_test_01)
     AFW.afw_completion(self.afw_completion_test_01)
     self.assertNotEqual(before, self.afw_completion_test_01)
Beispiel #5
0
 def test_afw_completion_wrong_dict(self):
     """ Tests a dict() in input different from a well formatted dict() 
     representing a AFW. [EXPECTED FAILURE]"""
     AFW.afw_completion({'goofy': 'donald'})
Beispiel #6
0
 def test_afw_completion_wrong_input(self):
     """ Tests an input different from a dict() object. [EXPECTED 
     FAILURE]"""
     AFW.afw_completion(0)