Ejemplo n.º 1
0
 def test12(self):
     stdin7 = NFAStdin("nfa7.txt")
     machine7 = NFA(stdin7.states, stdin7.transitions,
                    stdin7.transition_function, stdin7.start_state,
                    stdin7.accept_states)
     assert (NFAProblem("000000000000000", machine7).is_string_in_language(
         NFAProblem("000000000000000", machine7).to_check,
         NFAProblem("000000000000000",
                    machine7).machine.start_state) == False)
     assert (NFAProblem("", machine7).is_string_in_language(
         NFAProblem("", machine7).to_check,
         NFAProblem("", machine7).machine.start_state))
Ejemplo n.º 2
0
 def test9(self):
     stdin4 = NFAStdin("nfa4.txt")
     machine4 = NFA(stdin4.states, stdin4.transitions,
                    stdin4.transition_function, stdin4.start_state,
                    stdin4.accept_states)
     assert (NFAProblem("", machine4).is_string_in_language(
         NFAProblem("", machine4).to_check,
         NFAProblem("", machine4).machine.start_state))
     assert (NFAProblem("1", machine4).is_string_in_language(
         NFAProblem("1", machine4).to_check,
         NFAProblem("1", machine4).machine.start_state))
     assert (NFAProblem("001", machine4).is_string_in_language(
         NFAProblem("001", machine4).to_check,
         NFAProblem("001", machine4).machine.start_state))
     assert (NFAProblem("00011101", machine4).is_string_in_language(
         NFAProblem("00011101", machine4).to_check,
         NFAProblem("00011101", machine4).machine.start_state))
     assert (NFAProblem("01", machine4).is_string_in_language(
         NFAProblem("01", machine4).to_check,
         NFAProblem("01", machine4).machine.start_state))
     assert (NFAProblem("010", machine4).is_string_in_language(
         NFAProblem("010", machine4).to_check,
         NFAProblem("010", machine4).machine.start_state))
     assert (NFAProblem("0101", machine4).is_string_in_language(
         NFAProblem("0101", machine4).to_check,
         NFAProblem("0101", machine4).machine.start_state))
     assert (NFAProblem("01111101", machine4).is_string_in_language(
         NFAProblem("01111101", machine4).to_check,
         NFAProblem("01111101", machine4).machine.start_state))
     assert (NFAProblem("1011101", machine4).is_string_in_language(
         NFAProblem("1011101", machine4).to_check,
         NFAProblem("1011101", machine4).machine.start_state))
     assert (NFAProblem("0", machine4).is_string_in_language(
         NFAProblem("0", machine4).to_check,
         NFAProblem("0", machine4).machine.start_state) == False)
     assert (NFAProblem("000", machine4).is_string_in_language(
         NFAProblem("000", machine4).to_check,
         NFAProblem("000", machine4).machine.start_state) == False)
     assert (NFAProblem("0001", machine4).is_string_in_language(
         NFAProblem("0001", machine4).to_check,
         NFAProblem("0001", machine4).machine.start_state) == False)
     assert (NFAProblem("000111", machine4).is_string_in_language(
         NFAProblem("000111", machine4).to_check,
         NFAProblem("000111", machine4).machine.start_state) == False)
     assert (NFAProblem("00011101101", machine4).is_string_in_language(
         NFAProblem("00011101101", machine4).to_check,
         NFAProblem("00011101101", machine4).machine.start_state) == False)
     assert (NFAProblem("011111", machine4).is_string_in_language(
         NFAProblem("011111", machine4).to_check,
         NFAProblem("011111", machine4).machine.start_state) == False)
     assert (NFAProblem("00000", machine4).is_string_in_language(
         NFAProblem("00000", machine4).to_check,
         NFAProblem("00000", machine4).machine.start_state) == False)
Ejemplo n.º 3
0
def main():
    try:
        stdin = NFAStdin(sys.argv[1])
        machine = NFA(stdin.states, stdin.transitions,
                      stdin.transition_function, stdin.start_state,
                      stdin.accept_states)
        string = "" if len(sys.argv) < 3 else sys.argv[2]
        problem = NFAProblem(string, machine)
    except Exception:
        print("Bad input")
    print(
        problem.is_string_in_language(problem.to_check,
                                      problem.machine.start_state))
Ejemplo n.º 4
0
 def test11(self):
     stdin6 = NFAStdin("nfa6.in")
     machine6 = NFA(stdin6.states, stdin6.transitions,
                    stdin6.transition_function, stdin6.start_state,
                    stdin6.accept_states)
     assert (NFAProblem("000", machine6).is_string_in_language(
         NFAProblem("000", machine6).to_check,
         NFAProblem("000", machine6).machine.start_state))
     assert (NFAProblem("00", machine6).is_string_in_language(
         NFAProblem("00", machine6).to_check,
         NFAProblem("00", machine6).machine.start_state))
     assert (NFAProblem("1111101", machine6).is_string_in_language(
         NFAProblem("1111101", machine6).to_check,
         NFAProblem("1111101", machine6).machine.start_state))
     assert (NFAProblem("1111100", machine6).is_string_in_language(
         NFAProblem("1111100", machine6).to_check,
         NFAProblem("1111100", machine6).machine.start_state))
     assert (NFAProblem("1010000000", machine6).is_string_in_language(
         NFAProblem("1010000000", machine6).to_check,
         NFAProblem("1010000000", machine6).machine.start_state))
     assert (NFAProblem("00000001", machine6).is_string_in_language(
         NFAProblem("00000001", machine6).to_check,
         NFAProblem("00000001", machine6).machine.start_state))
     assert (NFAProblem("", machine6).is_string_in_language(
         NFAProblem("", machine6).to_check,
         NFAProblem("", machine6).machine.start_state) == False)
     assert (NFAProblem("0", machine6).is_string_in_language(
         NFAProblem("0", machine6).to_check,
         NFAProblem("0", machine6).machine.start_state) == False)
     assert (NFAProblem("010", machine6).is_string_in_language(
         NFAProblem("010", machine6).to_check,
         NFAProblem("010", machine6).machine.start_state) == False)
     assert (NFAProblem("01010", machine6).is_string_in_language(
         NFAProblem("01010", machine6).to_check,
         NFAProblem("01010", machine6).machine.start_state) == False)
     assert (NFAProblem("111110", machine6).is_string_in_language(
         NFAProblem("111110", machine6).to_check,
         NFAProblem("111110", machine6).machine.start_state) == False)
     assert (NFAProblem(
         "00000000000001111110", machine6).is_string_in_language(
             NFAProblem("00000000000001111110", machine6).to_check,
             NFAProblem("00000000000001111110",
                        machine6).machine.start_state) == False)
     assert (NFAProblem("1110", machine6).is_string_in_language(
         NFAProblem("1110", machine6).to_check,
         NFAProblem("1110", machine6).machine.start_state) == False)
     assert (NFAProblem(
         "sdfghkl;kjhgfdsfghjkl", machine6).is_string_in_language(
             NFAProblem("sdfghkl;kjhgfdsfghjkl", machine6).to_check,
             NFAProblem("sdfghkl;kjhgfdsfghjkl",
                        machine6).machine.start_state) == False)
Ejemplo n.º 5
0
 def test13(self):
     stdin8 = NFAStdin("nfa8.in")
     machine8 = NFA(stdin8.states, stdin8.transitions,
                    stdin8.transition_function, stdin8.start_state,
                    stdin8.accept_states)
     assert (NFAProblem("000000000000000", machine8).is_string_in_language(
         NFAProblem("000000000000000", machine8).to_check,
         NFAProblem("000000000000000",
                    machine8).machine.start_state) == False)
     assert (NFAProblem("", machine8).is_string_in_language(
         NFAProblem("", machine8).to_check,
         NFAProblem("", machine8).machine.start_state) == False)
     assert (NFAProblem("asdfghgfdsa", machine8).is_string_in_language(
         NFAProblem("asdfghgfdsa", machine8).to_check,
         NFAProblem("asdfghgfdsa", machine8).machine.start_state) == False)
Ejemplo n.º 6
0
 def test8(self):
     stdin3 = NFAStdin("nfa3.in")
     machine3 = NFA(stdin3.states, stdin3.transitions,
                    stdin3.transition_function, stdin3.start_state,
                    stdin3.accept_states)
     assert (NFAProblem("", machine3).is_string_in_language(
         NFAProblem("", machine3).to_check,
         NFAProblem("", machine3).machine.start_state))
     assert (NFAProblem("00", machine3).is_string_in_language(
         NFAProblem("00", machine3).to_check,
         NFAProblem("00", machine3).machine.start_state))
     assert (NFAProblem("010", machine3).is_string_in_language(
         NFAProblem("010", machine3).to_check,
         NFAProblem("010", machine3).machine.start_state))
     assert (NFAProblem("0", machine3).is_string_in_language(
         NFAProblem("0", machine3).to_check,
         NFAProblem("0", machine3).machine.start_state))
     assert (NFAProblem("1", machine3).is_string_in_language(
         NFAProblem("1", machine3).to_check,
         NFAProblem("1", machine3).machine.start_state))
Ejemplo n.º 7
0
 def test6(self):
     stdin1 = NFAStdin("nfa1.in")
     machine1 = NFA(stdin1.states, stdin1.transitions,
                    stdin1.transition_function, stdin1.start_state,
                    stdin1.accept_states)
     assert (NFAProblem("a", machine1).is_string_in_language(
         NFAProblem("a", machine1).to_check,
         NFAProblem("a", machine1).machine.start_state))
     assert (NFAProblem("", machine1).is_string_in_language(
         NFAProblem("", machine1).to_check,
         NFAProblem("", machine1).machine.start_state) == False)
     assert (NFAProblem("aa", machine1).is_string_in_language(
         NFAProblem("aa", machine1).to_check,
         NFAProblem("aa", machine1).machine.start_state))
     assert (NFAProblem("aaaaaaaaaaaaaaaaa",
                        machine1).is_string_in_language(
                            NFAProblem("aaaaaaaaaaaaaaaaa",
                                       machine1).to_check,
                            NFAProblem("aaaaaaaaaaaaaaaaa",
                                       machine1).machine.start_state))
Ejemplo n.º 8
0
 def test7(self):
     stdin2 = NFAStdin("nfa2.in")
     machine2 = NFA(stdin2.states, stdin2.transitions,
                    stdin2.transition_function, stdin2.start_state,
                    stdin2.accept_states)
     assert (NFAProblem("011", machine2).is_string_in_language(
         NFAProblem("011", machine2).to_check,
         NFAProblem("011", machine2).machine.start_state))
     assert (NFAProblem("0000000011", machine2).is_string_in_language(
         NFAProblem("0000000011", machine2).to_check,
         NFAProblem("0000000011", machine2).machine.start_state))
     assert (NFAProblem("011101011", machine2).is_string_in_language(
         NFAProblem("011101011", machine2).to_check,
         NFAProblem("011101011", machine2).machine.start_state))
     assert (NFAProblem("11111100001011", machine2).is_string_in_language(
         NFAProblem("11111100001011", machine2).to_check,
         NFAProblem("11111100001011", machine2).machine.start_state))
     assert (NFAProblem("0110", machine2).is_string_in_language(
         NFAProblem("0110", machine2).to_check,
         NFAProblem("0110", machine2).machine.start_state) == False)
     assert (NFAProblem("0111", machine2).is_string_in_language(
         NFAProblem("0111", machine2).to_check,
         NFAProblem("0111", machine2).machine.start_state) == False)
     assert (NFAProblem("01110", machine2).is_string_in_language(
         NFAProblem("01110", machine2).to_check,
         NFAProblem("01110", machine2).machine.start_state) == False)
     assert (NFAProblem("11", machine2).is_string_in_language(
         NFAProblem("11", machine2).to_check,
         NFAProblem("11", machine2).machine.start_state) == False)
     assert (NFAProblem("111111000010110", machine2).is_string_in_language(
         NFAProblem("111111000010110", machine2).to_check,
         NFAProblem("111111000010110",
                    machine2).machine.start_state) == False)
     assert (NFAProblem("", machine2).is_string_in_language(
         NFAProblem("", machine2).to_check,
         NFAProblem("", machine2).machine.start_state) == False)