def test_five_rules(self): rgen = raw_rule_generator("q4 0 -> P1 R q3\n" " 1 -> Px q4\n\n" " x -> P0 L\n\n\n" " P1 q3\n" "q3 0 -> P1 q4\n" " 1 -> P0 L q3") assert next(rgen) == (["q4", "0"], ["P1", "R", "q3"]) assert next(rgen) == ([" ", "1"], ["Px", "q4"]) assert next(rgen) == ([" ", "x"], ["P0", "L", "P1", "q3"]) assert next(rgen) == (["q3", "0"], ["P1", "q4"]) assert next(rgen) == ([" ", "1"], ["P0", "L", "q3"]) with raises(StopIteration): next(rgen)
def test_five_rules(self): rgen = raw_rule_generator( "q4 0 -> P1 R q3\n" " 1 -> Px q4\n\n" " x -> P0 L\n\n\n" " P1 q3\n" "q3 0 -> P1 q4\n" " 1 -> P0 L q3" ) assert next(rgen) == (["q4", "0"], ["P1", "R", "q3"]) assert next(rgen) == ([" ", "1"], ["Px", "q4"]) assert next(rgen) == ([" ", "x"], ["P0", "L", "P1", "q3"]) assert next(rgen) == (["q3", "0"], ["P1", "q4"]) assert next(rgen) == ([" ", "1"], ["P0", "L", "q3"]) with raises(StopIteration): next(rgen)
def test_one_rule(self): rgen = raw_rule_generator("q1 1 -> P0 R q2") assert next(rgen) == (["q1", "1"], ["P0", "R", "q2"]) with raises(StopIteration): next(rgen)
def test_no_rules(self): assert list(raw_rule_generator("\n \n\n")) == [] == \ list(raw_rule_generator(""))
def test_one_and_a_arrow_only_rule(self, rule): rgen = raw_rule_generator("q1 1 -> E q0\n" + rule) assert next(rgen) == (["q1", "1"], ["E", "q0"]) with raises(TMSyntaxError): next(rgen)
def test_one_and_a_half_rule_with_arrow(self, rule): rgen = raw_rule_generator("q0 -> q1\n" + rule) assert next(rgen) == (["q0"], ["q1"]) with raises(TMSyntaxError): next(rgen)
def test_half_rule(self): rgen = raw_rule_generator("q1 1") with raises(TMSyntaxError): next(rgen)