コード例 #1
0
def test_pop_double():
    d = Derivation()
    d.add("bbs", -1)
    d.add("bSa", 2)
    assert ("bSa", 2) == d.pop()
    assert ("bbs", -1) == d.pop()
    assert d.isEmpty()
コード例 #2
0
def test_all_derivations_two():
    cfg = ({"E"}, {"a", "b"}, {"E": ["E+E", "E*E", "(E)", "a", "b"]}, "E")
    string = "a+b+a"

    firstDerivation = Derivation(entries=[("E", 0), ("E+E", 0), ("E+E+E", 0), ("a+E+E", 2), ("a+b+E", 4), ("a+b+a", -1)])
    secondDerivation = Derivation(entries=[("E", 0), ("E+E", 0), ("E+E+E", 0), ("a+E+E", 4), ("a+E+a", 2), ("a+b+a", -1)])

    derivations = d.getAllDerivations(cfg, string, MAX_SUBSTITUTIONS=5, MAX_DERIVATIONS=36)
    # for de in derivations: print str(de)
    assert firstDerivation in derivations
    assert secondDerivation in derivations
コード例 #3
0
def test_simple_derivations():
    cfg = (["S", "A"], ["a", "b"], {"S": ["aA"], "A": ["a", "b"]}, "S")
    string = "aa"
    firstDerivation = Derivation(entries=[("S", 0), ("aA", 1), ("aa", -1)])
    derivations = d.getAllDerivations(cfg, string, MAX_SUBSTITUTIONS=5, MAX_DERIVATIONS=2)
    for de in derivations: print str(de)
    assert firstDerivation in derivations
コード例 #4
0
def test_get_left_derivations():
    cfg = ({"S", "A"}, {"a", "b"}, {"S": ["aAS", "a"], "A": ["SbA", "SS", "ba"]}, "S")
    string = "aabbaa"
    expected = Derivation(entries=[("S", 0), ("aAS", 1), ("aSbAS", 1), ("aabAS", 3), ("aabbaS", 5), ("aabbaa", -1)])
    actual = d.getLeftDerivation(cfg, string)
    print actual
    print expected
    assert expected == actual
コード例 #5
0
def test_add():
    d = Derivation()
    d.add("AAs", 1)
コード例 #6
0
def test_clear():
    d = Derivation()
    d.add("bbs", -1)
    d.add("bSa", 2)
    d.clear()
    assert d.isEmpty()
コード例 #7
0
def test_empty():
    d = Derivation()
    assert d.isEmpty()
コード例 #8
0
def test_pop_simple():
    d = Derivation()
    d.add("bBs", 2)
    d.pop()
    assert d.isEmpty()
コード例 #9
0
def test_add_no_variable():
    d = Derivation()
    d.add("aas", -1)