def test_creation(self): # S -> a S b | a b enfa = Regex("a S b | a b").to_epsilon_nfa() dfa = enfa.minimize() box = Box(dfa, Symbol("S")) rsa_1 = RecursiveAutomaton({Symbol("S")}, Symbol("S"), {box}) self.assertEqual(rsa_1.get_number_of_boxes(), 1) self.assertEqual(box, rsa_1.get_box(Symbol("S"))) self.assertEqual(rsa_1.labels, {Symbol("S")}) self.assertEqual(rsa_1.initial_label, Symbol("S")) rsa_2 = RecursiveAutomaton() rsa_2.add_box(box) rsa_2.change_initial_label(Symbol("S")) self.assertEqual(rsa_2, rsa_1) # Checking to add a start label rsa_3 = RecursiveAutomaton(set(), Symbol("S"), {box}) self.assertEqual(rsa_3.labels, {Symbol("S")}) try: rsa_4 = RecursiveAutomaton({Symbol("S"), Symbol("v")}, Symbol("S"), {box}) except ValueError: self.assertEqual(True, True)
def test_from_regex(self): # S -> a* rsa_2 = RecursiveAutomaton.from_regex(Regex("a*"), Symbol("S")) enfa = Regex("a*").to_epsilon_nfa() dfa = enfa.minimize() box = Box(dfa, Symbol("S")) rsa_1 = RecursiveAutomaton({Symbol("S")}, Symbol("S"), {box}) self.assertEqual(rsa_2, rsa_1)