예제 #1
0
def test_parse_grammar():
    c = CFG()
    s = {'c', 'X', 'Z', 'S', 'b', 'a', 'Y'}
    c.parse_grammar(lines)
    assert (set(c.symb.keys()) == s)
    assert (len(c.nonterms) == 4)
    assert (len(c.terms) == 3)
    assert (len(c.rules) == 8)
예제 #2
0
def test_output():
    c = CFG()
    testdir = tempfile.gettempdir()
    c.parse_grammar(lines)
    c.print_cnf(path.join(testdir, 'output.txt'))

    with open(path.join(testdir, 'output.txt')) as f:
        lines1 = map(lambda x: re.sub("\n", "", x), f.readlines())

    assert (set(lines1) == set(cnf_lines))