Ejemplo n.º 1
0
def test_two_nonterm(algo):
    test_data_path = LOCAL_CFPQ_DATA.joinpath('two_nonterm')
    singlepath_algo: SinglePathProblem = algo()
    graph = Graph.from_txt(test_data_path.joinpath('Graphs/graph_1.txt'))
    grammar = cfg_from_txt(test_data_path.joinpath('Grammars/g.cfg'))
    singlepath_algo.prepare(graph, grammar)

    result: ResultAlgo = singlepath_algo.solve()
    assert result.matrix_S.nvals == 156

    paths = singlepath_algo.getPath(1, 1, "S")
    assert paths == 2
Ejemplo n.º 2
0
def test_two_nonterm(algo):
    test_data_path = LOCAL_CFPQ_DATA.joinpath('two_nonterm')
    allpath_algo: AllPathsProblem = algo()
    graph = Graph.from_txt(test_data_path.joinpath('Graphs/graph_1.txt'))
    grammar = cfg_from_txt(test_data_path.joinpath('Grammars/g.cfg'))
    allpath_algo.prepare(graph, grammar)

    result: ResultAlgo = allpath_algo.solve()
    assert result.matrix_S.nvals == 156

    allpath_algo.prepare_for_exctract_paths()
    paths = allpath_algo.getPaths(1, 1, "S", 3)
    assert len(paths) == 1
Ejemplo n.º 3
0
def test_case_1_graph_1(algo):
    # (0)-[a]->(1)-[a]->(2)-[b]->(3)-[b]->(4)
    # S -> a S b | a b

    test_case_1_path = LOCAL_CFPQ_DATA.joinpath('test_case_1')

    graph = LabelGraph.from_txt(
        test_case_1_path.joinpath('Matrices/graph_1.txt'))
    grammar = CnfGrammar.from_cnf(
        test_case_1_path.joinpath('Grammars/grammar.cnf'))
    single_source: SingleSourceSolver = algo(graph, grammar)

    m, _ = single_source.solve([1])
    assert vecbool_to_list(m[1]) == [3]

    m, _ = single_source.solve([0])
    assert vecbool_to_list(m[0]) == [4]
Ejemplo n.º 4
0
def test_case_1_graph_2(algo):
    #       (6)
    #      /   \
    #    (2)   (5)
    #   /  \   /  \
    # (0) (1) (3) (4)
    # Upstream edges labeled by "a", downstream by "b"
    # S -> a S b | a b

    test_case_1_path = LOCAL_CFPQ_DATA.joinpath('test_case_1')

    graph = LabelGraph.from_txt(
        test_case_1_path.joinpath('Matrices/graph_2.txt'))
    grammar = CnfGrammar.from_cnf(
        test_case_1_path.joinpath('Grammars/grammar.cnf'))
    single_source: SingleSourceSolver = algo(graph, grammar)

    m, _ = single_source.solve([0])
    assert vecbool_to_list(m[0]) == [0, 1, 3, 4]

    m, _ = single_source.solve([2])
    assert vecbool_to_list(m[2]) == [2, 5]