Question: I have this code that i have been working on, the assert cases should all go through but some of them fail due to some
I have this code that i have been working on, the assert cases should all go through but some of them fail due to some error in my code but i cant seem to find it and fix it
def check_acceptance(dfa, string): state = dfa['start'] print("Start state: ", state) for char in string: state = dfa['transition'][state].get(char) print("Current state: ", state) if state is None: return False return state in dfa['accept'] def fa1(string): """ A first DFA that accepts strings containing an odd number of 0s. """ dfa = { 'start': 'A', 'accept': {'A'}, 'transition': { 'A': {'0': 'B', '1': 'A'}, 'B': {'0': 'A', '1': 'B'}, } } return check_acceptance(dfa, string) def fa2(string): """ A second DFA that accepts strings containing a substring "111". """ dfa = { 'start': 'A', 'accept': {'C'}, 'transition': { 'A': {'0': 'A', '1': 'B'}, 'B': {'0': 'A', '1': 'C'}, 'C': {'0': 'A', '1': 'A'} } } return check_acceptance(dfa, string) def fa3(string): """ 3) A third DFA that accepts strings that a) have at least two 0's, and b) at least one 1, and c) end with 0. """ dfa = { 'start': 'A', 'accept': {'C'}, 'transition': { 'A': {'0': 'B', '1': 'D'}, 'B': {'0': 'C', '1': 'D'}, 'C': {'0': 'D', '1': 'D'}, 'D': {'0': 'D', '1': 'D'} } } return check_acceptance(dfa, string) #Test cases for fa1 #1.1 assert fa1(" ") == False #1.2 assert fa1('0') == True #1.3 assert fa1('00') == False #1.4 assert fa1('000') == False #1.5 assert fa1('1') == False #1.6 assert fa1("10") == True #1.7 assert fa1("11") == False #1.8 assert fa1("010") == False #1.9 assert fa1("101010") == True #1.10 assert fa1("0111000") == False #Test cases for fa2 #2.1 assert fa2(" ") == False #2.2 assert fa2('0') == False #2.3 assert fa2('11011') == False #2.4 assert fa2('111') == True #2.5 assert fa2('1') == False #2.6 assert fa2("1011111") == True #2.7 assert fa2("11") == False #2.8 assert fa2("01011101011110") == True #2.9 assert fa2("101010") == False #2.10 assert fa2("0111000") == True #Test cases for fa3 #3.1 assert fa3(" ") == False #3.2 assert fa3('00') == True #3.3 assert fa3('100') == True #3.4 assert fa3('00010') == True #3.5 assert fa3('0100101') == False #3.6 assert fa3("1110") == False #3.7 assert fa3("110") == False #3.8 assert fa3("010") == True #3.9 assert fa3("101010") == True #3.10 assert fa3("0111000") == True #TODO: Fix the following test cases for fa3 so that they pass the assertions below #Cases that fail in fa3: 3.5, 3.6, 3.7, 3.8, 3.9, 3.10 #Cases that fail in fa2: 2.3, 2.4, 2.6, 2.8, 2.9, 2.10 #Cases that fail in fa1: 1.3, 1.4, 1.6, 1.8, 1.9, 1.10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
