def test_match_and_remove(): G = Graph() G.add_node(Node("test0")) G.add_node(Node("test1")) G.add_node(Node('test2')) G.add_edge(Edge('test0', 'test1')) G.add_edge(Edge('test1', 'test2')) G.add_edge(Edge('test1', Node('test3'))) G.add_node(Node('test4')) G.add_edge(Edge('test2', 'test4')) G.add_edge(Edge('test3', 'test4')) G.add_edge(Edge('test4', Node('test5'))) fragment = Graph() fragment.add_node(MatchNameNode("test1")) fragment.add_node(MatchNameNode('test2')) fragment.add_edge(Edge('test1', 'test2')) fragment.add_edge(Edge('test1', MatchNameNode('test3'))) res = G.match_fragment(fragment) assert len(res) == 1 assert res[0].num_nodes() == 3 assert res[0].num_edges() == 2 G.remove_fragment(res[0]) assert [node.name for node in G.dfs()] == ['test0', 'test4', 'test5'] assert not G.verify_edges()
def test_match1(): G = Graph() G.add_node(Node("test1")) G.add_node(Node('test2')) G.add_edge(Edge('test1', 'test2')) G.add_edge(Edge('test2', Node('test3'))) G.add_node(Node('test4')) G.add_edge(Edge('test3', 'test4')) assert not G.verify_edges() fragment = Graph() fragment.add_node(MatchNameNode("test1")) fragment.add_node(MatchNameNode('test2')) fragment.add_edge(Edge('test1', 'test2')) assert not fragment.verify_edges() res = G.match_fragment(fragment) assert len(res) == 1 assert len(res[0]) == 2 assert res[0].num_edges() == 1
def test_match3(): G = Graph() G.add_node(Node("test1")) G.add_node(Node('test2')) G.add_edge(Edge('test1', 'test2')) G.add_edge(Edge('test1', Node('test3'))) G.add_node(Node('test4')) G.add_edge(Edge('test2', 'test4')) # not the same - look here fragment = Graph() fragment.add_node(MatchNameNode("test1")) fragment.add_node(MatchNameNode('test2')) fragment.add_edge(Edge('test1', 'test2')) fragment.add_edge(Edge('test1', MatchNameNode('test3'))) res = G.match_fragment(fragment) assert len(res) == 1 assert res[0].num_nodes() == 3 assert res[0].num_edges() == 2
def test_match4(): G = Graph() G.add_node(Node("test1")) G.add_node(Node('test2')) G.add_node(Node('test3')) G.add_node(Node('test4')) G.add_node(Node('test5')) G.add_edge(Edge('test1', 'test2')) G.add_edge(Edge('test2', 'test4')) G.add_edge(Edge('test3', 'test4', to_idx=1)) G.add_edge(Edge('test4', 'test5')) fragment = Graph() fragment.add_node(MatchNameNode("test2")) fragment.add_node(MatchNameNode('test3')) fragment.add_node(MatchNameNode('test4')) fragment.add_edge(Edge('test2', 'test4')) fragment.add_edge(Edge('test3', 'test4', to_idx=1)) res = G.match_fragment(fragment) assert len(res) == 1 assert res[0].num_nodes() == 3 assert res[0].num_edges() == 2