def test_cyk_2(): c = CFG() c.read_from_file(path.dirname(__file__) + "/res/gram2.txt") assert (c.cyk("a b".split())) assert (not c.cyk("a b c".split())) assert (c.cyk("a a a b a b a".split())) assert (c.cyk("".split()))
def test_input(): c = CFG() testdir = tempfile.gettempdir() test_keys = {'b', 'X', 'Z', 'c', 'Y', 'T0', 'a', 'S'} with open(path.join(testdir, 'input.txt'), 'w') as f: for i in cnf_lines: f.write(i + '\n') c.read_from_file(path.join(testdir, 'input.txt')) assert (len(c.grammar.rules) == 11) assert (c.symb.keys() == test_keys) assert (len(c.rules) == 12) assert (len(c.terms) == 3) assert (len(c.nonterms) == 5)