Skip to content

Commit

Permalink
- added the test of GetEgonet()
Browse files Browse the repository at this point in the history
- fixed parameter naming in GetEgonet()
  • Loading branch information
roks committed Sep 24, 2020
1 parent 584a072 commit 8ed38c9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions snap-core/subgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ PNGraph GetSubGraph(const PNGraph& Graph, const TIntV& NIdV, const bool& Renumbe
return NewGraphPt;
}

PUNGraph GetEgonet(const PUNGraph& Graph, const int CtrNId, int& ArndEdgesX) {
PUNGraph GetEgonet(const PUNGraph& Graph, const int CtrNId, int& ArndEdges) {
PUNGraph NewGraphPt = TUNGraph::New();
TUNGraph& NewGraph = *NewGraphPt;
NewGraph.AddNode(CtrNId);
Expand All @@ -105,7 +105,7 @@ PUNGraph GetEgonet(const PUNGraph& Graph, const int CtrNId, int& ArndEdgesX) {
return NewGraphPt;
}

PNGraph GetEgonet(const PNGraph& Graph, const int CtrNId, int& InEgoEdgesX, int& OutEgoEdgesX) {
PNGraph GetEgonet(const PNGraph& Graph, const int CtrNId, int& InEdges, int& OutEdges) {
PNGraph NewGraphPt = TNGraph::New();
TNGraph& NewGraph = *NewGraphPt;
NewGraph.AddNode(CtrNId);
Expand Down
70 changes: 70 additions & 0 deletions test/test-subgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PUNGraph GetTestTUNGraph();
PNGraph GetTestTNGraph();
PNEGraph GetTestTNEGraph();
PNEANet GetTestTNEANet();
PUNGraph GetUPetersen();
PNGraph GetDPetersen();
TPt <TNodeEDatNet<TInt, TInt> > GetTestTNodeEDatNet();
TPt <TNodeEdgeNet<TInt, TInt> > GetTestTNodeEdgeNet();

Expand Down Expand Up @@ -316,6 +318,34 @@ TEST(subgraph, TestGetRndGraphs) {
EXPECT_EQ(10,NGraph3->GetEdges());
}

// Test GetEgonet
TEST(subgraph, TestGetEgonet) {

PUNGraph UGraph = GetUPetersen();
for (int i = 0; i < 10; i++) {
int Edges;
PUNGraph Ego = TSnap::GetEgonet(UGraph, i, Edges);
EXPECT_EQ(4, Ego->GetNodes());
EXPECT_EQ(3, Ego->GetEdges());
EXPECT_EQ(6, Edges);
}

PNGraph Graph = GetDPetersen();
for (int i = 0; i < 10; i++) {
int EdgesIn, EdgesOut;
PNGraph Ego = TSnap::GetEgonet(Graph, i, EdgesIn, EdgesOut);
EXPECT_EQ(4, Ego->GetNodes());
EXPECT_EQ(3, Ego->GetEdges());
if (i < 5) {
EXPECT_EQ(2, EdgesIn);
EXPECT_EQ(4, EdgesOut);
} else {
EXPECT_EQ(4, EdgesIn);
EXPECT_EQ(2, EdgesOut);
}
}
}

// Test TNGraph GetEgoNetHop
TEST(subgraph, TestGetInEgonetHopTNGraph) {
// Test on TNSmall Graph
Expand Down Expand Up @@ -708,6 +738,46 @@ PNEGraph GetTestTNEGraph() {
return Graph;
}

// Generate TUNGraph Petersen graph
PUNGraph GetUPetersen() {
PUNGraph Graph = TUNGraph::New();

for (int i = 0; i < 10; i++) {
Graph->AddNode(i);
}
for (int i = 0; i < 5; i++) {
Graph->AddEdge(i,(i+1) % 5);
}
for (int i = 0; i < 5; i++) {
Graph->AddEdge(i + 5,(i+2) % 5 + 5);
}
for (int i = 0; i < 5; i++) {
Graph->AddEdge(i,i + 5);
}

return Graph;
}

// Generate TNGraph Petersen graph
PNGraph GetDPetersen() {
PNGraph Graph = TNGraph::New();

for (int i = 0; i < 10; i++) {
Graph->AddNode(i);
}
for (int i = 0; i < 5; i++) {
Graph->AddEdge(i,(i+1) % 5);
}
for (int i = 0; i < 5; i++) {
Graph->AddEdge(i + 5,(i+2) % 5 + 5);
}
for (int i = 0; i < 5; i++) {
Graph->AddEdge(i,i + 5);
}

return Graph;
}

// Generate TNodeEDatNet
TPt <TNodeEDatNet<TInt, TInt> > GetTestTNodeEDatNet() {
TPt <TNodeEDatNet<TInt, TInt> > Net;
Expand Down

0 comments on commit 8ed38c9

Please sign in to comment.