Esempio n. 1
0
def test_mix():
    try:
        with open('./tests/_examples/good_files/mix.txt') as f:
            content = f.readlines()
    except:
        print('Error opening file for reading')
        raise

    parser = ESParser(content)
    tree = NPITree(parser.structured_rules, parser.facts, parser.queries)
    assert tree.resolve_query("G") is True
    assert tree.resolve_query("T") is False
    assert tree.resolve_query("X") is False
Esempio n. 2
0
def test_test_and2():
    try:
        with open('./tests/_correction/test_and2') as f:
            content = f.readlines()
    except:
        print('Error opening file for reading')
        raise

    parser = ESParser(content)
    tree = NPITree(parser.structured_rules, parser.facts, parser.queries)
    assert tree.resolve_query("A") is True
    assert tree.resolve_query("G") is True
    assert tree.resolve_query("K") is False
    assert tree.resolve_query("P") is True
Esempio n. 3
0
def test_and_in_conclusions():
    try:
        with open('./tests/_examples/good_files/and_in_conclusions.txt') as f:
            content = f.readlines()
    except:
        print('Error opening file for reading')
        raise

    parser = ESParser(content)
    tree = NPITree(parser.structured_rules, parser.facts, parser.queries)
    assert tree.resolve_query("F") is True
    assert tree.resolve_query("C") is True
    assert tree.resolve_query("D") is True
    assert tree.resolve_query("U") is True
Esempio n. 4
0
def test_good_files(input, expected):
    with open("./tests/_examples/good_files/" + input) as f:
        file_lines = f.readlines(1000)

    parser = ESParser(file_lines)
    tree = NPITree(parser.structured_rules, parser.facts, parser.queries)

    i = 0
    for query in parser.queries:
        if expected[i] == "ERROR":
            try:
                tree.resolve_query(query)
            except:
                pass
                continue
            assert False
        else:
            assert tree.resolve_query(query) == expected[i]
        i += 1
Esempio n. 5
0
def test_multiple_no_initial_facts2():
    try:
        with open('./tests/_examples/good_files/no_initial_facts2.txt') as f:
            content = f.readlines()
    except:
        print('Error opening file for reading')
        raise

    parser = ESParser(content)
    tree = NPITree(parser.structured_rules, parser.facts, parser.queries)
    assert tree.resolve_query("C") is False