Example #1
0
 def test_invalid_tokenizer_unfinished_last_rule(self, invalid_end,
                                                       monkeypatch):
     def mock_tokenizer(data):
         for el in ["q1", "0", "->", "R", "q2", "\n"] + invalid_end:
             yield el
     monkeypatch.setattr(pyturing, "tokenizer", mock_tokenizer)
     rgen = raw_rule_generator("")
     assert next(rgen) == (["q1", "0"], ["R", "q2"])
     with raises(TMSyntaxError):
         next(rgen)
Example #2
0
    def test_invalid_tokenizer_unfinished_last_rule(self, invalid_end,
                                                    monkeypatch):
        def mock_tokenizer(data):
            for el in ["q1", "0", "->", "R", "q2", "\n"] + invalid_end:
                yield el

        monkeypatch.setattr(pyturing, "tokenizer", mock_tokenizer)
        rgen = raw_rule_generator("")
        assert next(rgen) == (["q1", "0"], ["R", "q2"])
        with raises(TMSyntaxError):
            next(rgen)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 def test_group_rules(self):
     rgen = raw_rule_generator("\n".join([
         "A",
         "  0 -> P1 R",
         "       P1 R B",
         "B",
         "  0 -> P0 R C",
         "  1 -> P0 L A",
         "C",
         "  -> P1 B",
     ]))
     assert next(rgen) == (["A", "0"], ["P1", "R", "P1", "R", "B"])
     assert next(rgen) == (["B", "0"], ["P0", "R", "C"])
     assert next(rgen) == ([" ", "1"], ["P0", "L", "A"])
     assert next(rgen) == (["C"], ["P1", "B"])
     with raises(StopIteration):
         next(rgen)
Example #6
0
 def test_group_rules(self):
     rgen = raw_rule_generator("\n".join([
         "A",
         "  0 -> P1 R",
         "       P1 R B",
         "B",
         "  0 -> P0 R C",
         "  1 -> P0 L A",
         "C",
         "  -> P1 B",
     ]))
     assert next(rgen) == (["A", "0"], ["P1", "R", "P1", "R", "B"])
     assert next(rgen) == (["B", "0"], ["P0", "R", "C"])
     assert next(rgen) == ([" ", "1"], ["P0", "L", "A"])
     assert next(rgen) == (["C"], ["P1", "B"])
     with raises(StopIteration):
         next(rgen)
Example #7
0
 def test_missing_first_m_configuration(self):
     rgen = raw_rule_generator(" -> N q1\n\n")
     assert next(rgen) == ([" "], ["N", "q1"])
     with raises(StopIteration):
         next(rgen)
Example #8
0
 def test_one_and_an_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)
Example #9
0
 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)
Example #10
0
 def test_half_rule(self, rule):
     rgen = raw_rule_generator(rule)
     with raises(TMSyntaxError):
         next(rgen)
Example #11
0
 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)
Example #12
0
 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)
Example #13
0
 def test_missing_first_m_configuration(self):
     rgen = raw_rule_generator(" -> N q1\n\n")
     assert next(rgen) == ([" "], ["N", "q1"])
     with raises(StopIteration):
         next(rgen)
Example #14
0
 def test_one_and_an_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)
Example #15
0
 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)
Example #16
0
 def test_half_rule(self, rule):
     rgen = raw_rule_generator(rule)
     with raises(TMSyntaxError):
         next(rgen)
Example #17
0
 def test_no_rules(self):
     assert list(raw_rule_generator("\n \n\n")) == [] == \
            list(raw_rule_generator(""))
Example #18
0
 def test_no_rules(self):
     assert list(raw_rule_generator("\n \n\n")) == [] == \
            list(raw_rule_generator(""))