Skip to content

Commit

Permalink
Merge pull request #988 from fabratu/20220902_fix_graph_constructor_i…
Browse files Browse the repository at this point in the history
…ndex

Initialize edgeID datastructure when constr. graph with indexed edges.
  • Loading branch information
angriman committed Sep 26, 2022
2 parents 0aeb0da + c71b968 commit 285df66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion networkit/cpp/graph/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Graph::Graph(count n, bool weighted, bool directed, bool edgesIndexed)
outgoing edges, for undirected graphs outEdges stores the adjacency list of
undirected edges*/
outEdges(n), inEdgeWeights(weighted && directed ? n : 0), outEdgeWeights(weighted ? n : 0),
inEdgeIds(), outEdgeIds(), nodeAttributeMap(this) {}
inEdgeIds(edgesIndexed && directed ? n : 0), outEdgeIds(edgesIndexed ? n : 0),
nodeAttributeMap(this) {}

Graph::Graph(std::initializer_list<WeightedEdge> edges) : Graph(0, true) {
using namespace std;
Expand Down
15 changes: 15 additions & 0 deletions networkit/cpp/graph/test/GraphGTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ void GraphGTest::SetUp() {

/** CONSTRUCTORS **/

TEST(GraphGTest, testDefConstructorWithUndirIndex) {
// Test indexed + undirected graph
Graph GUndir(3, false, false, true);
GUndir.addEdge(0, 1);
EXPECT_EQ(GUndir.edgeId(0, 1), 0);
EXPECT_EQ(GUndir.edgeId(1, 0), 0);
}

TEST(GraphGTest, testDefConstructorWithDirIndex) {
// Test indexed + directed graph
Graph GDir(3, false, true, true);
GDir.addEdge(0, 1);
EXPECT_EQ(GDir.edgeId(0, 1), 0);
}

TEST_P(GraphGTest, testCopyConstructor) {
Graph G = Graph(this->Ghouse, false, false);
Graph GW = Graph(this->Ghouse, true, false);
Expand Down

0 comments on commit 285df66

Please sign in to comment.