def test_word_acceptance_check_side_effects(self): """ Tests that the function doesn't make any side effect on the input""" before = copy.deepcopy(self.afw_word_acceptance_test_01) AFW.afw_word_acceptance(self.afw_word_acceptance_test_01, ['a', 'b', 'b', 'a', 'a', 'b', 'a', 'a']) self.assertDictEqual(before, self.afw_word_acceptance_test_01)
def test_afw_intersection_equals(self): """ Tests a correct afw intersection with the same afw """ AFW.rename_afw_states(self.afw_intersection_1_test_01, 'a_') intersection = AFW.afw_intersection(self.afw_intersection_1_test_01, self.afw_intersection_1_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_1 = AFW.afw_word_acceptance( self.afw_intersection_1_test_01, word) original_acceptance_2 = AFW.afw_word_acceptance( self.afw_intersection_1_test_01, word) intersection_acceptance = AFW.afw_word_acceptance(intersection, word) self.assertEqual( original_acceptance_1 and original_acceptance_2, intersection_acceptance) i += 1
def test_afw_union_intersecting(self): """ Tests a correct afw union where the afws have some state in common """ AFW.rename_afw_states(self.afw_union_3_test_01, 'a_') union = AFW.afw_union(self.afw_union_1_test_01, self.afw_union_3_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) # print(word) original_acceptance_1 = AFW.afw_word_acceptance( self.afw_union_1_test_01, word) original_acceptance_2 = AFW.afw_word_acceptance( self.afw_union_3_test_01, word) union_acceptance = AFW.afw_word_acceptance(union, word) self.assertEqual( original_acceptance_1 or original_acceptance_2, union_acceptance) i += 1
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
def test_afw_complementation(self): """ Test a correct afw complementation comparing the language read, that must be discording""" afw_complemented = AFW.afw_complementation( self.afw_complementation_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) afw_acceptance = AFW.afw_word_acceptance( self.afw_complementation_test_01, word) complement_acceptance = AFW.afw_word_acceptance( afw_complemented, word) self.assertNotEqual(afw_acceptance, complement_acceptance) i += 1
def test_afw_union_empty_states_2(self): """ Tests a afw union where the second afw is empty """ union = AFW.afw_union(self.afw_union_1_test_01, self.afw_union_test_empty) 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_1 = AFW.afw_word_acceptance( self.afw_union_1_test_01, word) original_acceptance_2 = AFW.afw_word_acceptance( self.afw_union_test_empty, word) union_acceptance = AFW.afw_word_acceptance(union, word) self.assertEqual( original_acceptance_1 or original_acceptance_2, union_acceptance) i += 1
def test_afw_union_disjoint(self): """ Tests a correct afw union with completely disjoint afws """ AFW.rename_afw_states(self.afw_union_2_test_01, 'a_') union = AFW.afw_union(self.afw_union_1_test_01, self.afw_union_2_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_1 = AFW.afw_word_acceptance( self.afw_union_1_test_01, word) original_acceptance_2 = AFW.afw_word_acceptance( self.afw_union_2_test_01, word) union_acceptance = AFW.afw_word_acceptance(union, word) self.assertEqual( original_acceptance_1 or original_acceptance_2, union_acceptance) i += 1
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
def test_word_acceptance_wrong_dict(self): """ Tests a dict() in input different from a well formatted dict() representing a AFW. [EXPECTED FAILURE]""" AFW.afw_word_acceptance({'goofy': 'donald'}, ['a', 'b', 'b', 'a', 'b'])
def test_word_acceptance_wrong_input_2(self): """ Tests an input different from a list() object. [EXPECTED FAILURE]""" AFW.afw_word_acceptance(self.afw_word_acceptance_test_01, 1)
def test_word_acceptance_wrong_input_1(self): """ Tests an input different from a dict() object. [EXPECTED FAILURE]""" AFW.afw_word_acceptance(1, ['a', 'b', 'b', 'a', 'b'])
def test_word_acceptance_empty_word(self): """ Tests an empty word""" self.afw_word_acceptance_test_01['initial_state'] = 'q1' self.assertFalse( AFW.afw_word_acceptance(self.afw_word_acceptance_test_01, []))
def test_word_acceptance_wrong_alphabet(self): """ Tests a non correct word, with letters not form the afw alphabet """ self.assertFalse( AFW.afw_word_acceptance(self.afw_word_acceptance_test_01, ['a', 'b', 'wrong']))
def test_word_acceptance_false(self): """ Tests a non correct word to be refused, with good alphabet """ self.assertFalse( AFW.afw_word_acceptance(self.afw_word_acceptance_test_01, ['a', 'b', 'a']))
def test_word_acceptance(self): """ Tests a correct word acceptance """ self.assertTrue( AFW.afw_word_acceptance(self.afw_word_acceptance_test_01, ['a', 'b', 'b', 'a', 'a', 'b', 'a', 'a']))