diff --git a/pgraph/pgraph.go b/pgraph/pgraph.go index a22d24f0..3c56040c 100644 --- a/pgraph/pgraph.go +++ b/pgraph/pgraph.go @@ -500,10 +500,10 @@ func (g *Graph) DFS(start Vertex) []Vertex { } // FilterGraph builds a new graph containing only vertices from the list. -func (g *Graph) FilterGraph(name string, vertices []Vertex) (*Graph, error) { - newGraph := &Graph{Name: name} - if err := newGraph.Init(); err != nil { - return nil, errwrap.Wrapf(err, "could not run FilterGraph() properly") +func (g *Graph) FilterGraph(vertices []Vertex) (*Graph, error) { + newGraph, err := NewGraph(g.Name) + if err != nil { + return nil, err } for k1, x := range g.adjacency { contains := VertexContains(k1, vertices) @@ -539,7 +539,7 @@ func (g *Graph) DisconnectedGraphs() ([]*Graph, error) { dfs := g.DFS(start) // filter all the collected elements into a new graph // TODO: is this method of filtering correct here? && or || ? - newGraph, err := g.FilterGraph(g.Name, dfs) + newGraph, err := g.FilterGraph(dfs) if err != nil { return nil, errwrap.Wrapf(err, "could not run DisconnectedGraphs() properly") } diff --git a/pgraph/pgraph_test.go b/pgraph/pgraph_test.go index e669458d..b5bdcdf0 100644 --- a/pgraph/pgraph_test.go +++ b/pgraph/pgraph_test.go @@ -181,7 +181,7 @@ func TestFilterGraph1(t *testing.T) { //G.AddEdge(v6, v4, e6) save := []Vertex{v1, v2, v3} - out, err := G.FilterGraph("new g5", save) + out, err := G.FilterGraph(save) if err != nil { t.Errorf("failed with: %v", err) } @@ -203,7 +203,7 @@ func TestFilterGraph2(t *testing.T) { G.AddVertex(v4) save := []Vertex{v1, v2, v3} - out, err := G.FilterGraph("new g5", save) + out, err := G.FilterGraph(save) if err != nil { t.Errorf("failed with: %v", err) } @@ -227,7 +227,7 @@ func TestFilterGraph3(t *testing.T) { G.AddVertex(v5) save := []Vertex{v1, v2, v3} - out, err := G.FilterGraph("new g5", save) + out, err := G.FilterGraph(save) if err != nil { t.Errorf("failed with: %v", err) }