def test_graph_branching():
    g = nx.DiGraph()
    add_nodes(g, ['a', 'b', 'a', 'c'])
    g.add_edges_from([(1, 2), (1, 3), (2, 4), (3, 4)])

    ex = N('a') + N('b')

    matches = search_all(ex, g)
    assert matches == [[1, 2]]
def test_two_matched():
    g = nx.DiGraph()
    add_nodes(g, ['a', 'b', 'c', 'a', 'b', 'c'])
    g.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)])

    ex = N('b') + N('c')

    matches = search_all(ex, g)
    assert matches == [[2, 3], [5, 6]]
def test_simple():
    g = nx.DiGraph()
    add_nodes(g, ['a', 'b', 'c', 'a'])
    g.add_edges_from([(1, 2), (2, 3), (3, 4)])

    ex = N('b') + N('c')

    matches = search_all(ex, g)
    assert matches == [[2, 3]]
def test_alternating():
    g = nx.DiGraph()
    add_nodes(g, ['a', 'b'])

    g.add_edges_from([(1, 2)])

    ex = N('a') + (N('a') | N('b'))

    matches = search_all(ex, g)
    assert matches == [[1, 2]]
def test_branching_expression2():
    g = nx.DiGraph()
    #   b
    # a e  d
    #   c
    add_nodes(g, ['a', 'b', 'c', 'd', 'e'])
    g.add_edges_from([(1, 2), (1, 3), (2, 4), (3, 4), (1, 5), (5, 4)])
    c_ = (N('b') & N('c') & N('e'))
    n = N('a')
    node_expression = N('d')
    ex = n + c_ + node_expression

    matches = search_all(ex, g)
    assert matches == [[1, 2, 3, 5, 4]]
Example #6
0
def test_branching_expression3():
    g = nx.DiGraph()
    #   b
    # a   d
    #   c
    add_nodes(g, ['a', 'b', 'c', 'd'])
    g.add_edges_from([(1, 2), (1, 3), (2, 4), (3, 4)])
    c_ = N('b') & (N('e') | N('c'))
    n = N('a')
    node_expression = N('d')
    ex = n + c_ + node_expression

    ex = N('a') + (N('b') & N('c')) + N('d')

    matches = search_all(g, ex)
    assert matches == [[1, 2, 3, 4]]
def test_alternating_longest():
    g = nx.DiGraph()
    #   b c
    # a     d
    #    b
    add_nodes(g, ['a', 'b', 'c', 'b', 'd'])
    g.add_edges_from([(1, 2), (2, 3), (3, 5), (1, 4), (4, 5)])

    ex = N('a') + (N('b') | N('b') + N('c'))
    ex2 = N('a') + (N('b') + N('c') | N('b'))

    matches = search_all(ex, g)
    matches2 = search_all(ex2, g)

    assert matches2 == matches == [[1, 2, 3]]