예제 #1
0
// Test GetNodeClustCf (Vector)
TEST(triad, TestGetNodeClustCfVector) {
  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  TIntFltH NIdCCfH;

  TSnap::GetNodeClustCf(GraphTUN, NIdCCfH);
  for (int i = 0; i < GraphTUN->GetNodes(); i++) {
    double ClustCf = NIdCCfH.GetDat(i);
    VerifyNodeClustCf(i, ClustCf);
  }

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph GraphTN = TriadGetTestTNGraph();
  NIdCCfH.Clr();

  TSnap::GetNodeClustCf(GraphTN, NIdCCfH);
  for (int i = 0; i < GraphTN->GetNodes(); i++) {
    double ClustCf = NIdCCfH.GetDat(i);
    VerifyNodeClustCf(i, ClustCf);
  }

  // TNEGraph should be treated as TUNGraph for calculations
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  NIdCCfH.Clr();

  TSnap::GetNodeClustCf(GraphTNE, NIdCCfH);
  for (int i = 0; i < GraphTNE->GetNodes(); i++) {
    double ClustCf = NIdCCfH.GetDat(i);
    VerifyNodeClustCf(i, ClustCf);
  }
}
예제 #2
0
파일: test-triad.cpp 프로젝트: Accio/snap
// Test GetTriads for Whole Graph (Open and Closed)
TEST(triad, TestGetTriadsOpenClosed) {
  const int expected_closed = 3;  // Expected closed triads
  const int expected_open = 9;    // Expected open triads

  // Test TUNGraph
  PUNGraph Graph_TUNGraph = TriadGetTestTUNGraph();
  int64 closed = 0, open = 0;

  TSnap::GetTriads(Graph_TUNGraph, closed, open);
  EXPECT_EQ(expected_closed, closed);
  EXPECT_EQ(expected_open, open);

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph Graph_TNGraph = TriadGetTestTNGraph();
  closed = 0, open = 0;

  TSnap::GetTriads(Graph_TNGraph, closed, open);
  EXPECT_EQ(expected_closed, closed);
  EXPECT_EQ(expected_open, open);

  // TNEGraph should be treated as TUNGraph for calculations
  PNEGraph Graph_TNEGraph = TriadGetTestTNEGraph();
  closed = 0, open = 0;

  TSnap::GetTriads(Graph_TNEGraph, closed, open);
  EXPECT_EQ(expected_closed, closed);
  EXPECT_EQ(expected_open, open);
}
예제 #3
0
// Test GetCmnNbrs: the number of neighbors in common
TEST(triad, TestGetCmnNbrs) {
  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  for (int i = 0; i < GraphTUN->GetNodes(); i++) {
    for (int j = i + 1; j < GraphTUN->GetNodes(); j++) {
      VerifyCmnNbrs(i, j, TSnap::GetCmnNbrs(GraphTUN, i, j));
    }
  }
  
  // Test TNGraph which is same as undirected.
  PNGraph GraphTN = TriadGetTestTNGraph();
  for (int i = 0; i < GraphTN->GetNodes(); i++) {
    for (int j = i + 1; j < GraphTN->GetNodes(); j++) {
      VerifyCmnNbrs(i, j, TSnap::GetCmnNbrs(GraphTN, i, j));
    }
  }
  
  // Test TNEGraph which is same as undirected.
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  for (int i = 0; i < GraphTNE->GetNodes(); i++) {
    for (int j = i + 1; j < GraphTNE->GetNodes(); j++) {
      VerifyCmnNbrs(i, j, TSnap::GetCmnNbrs(GraphTNE, i, j));
    }
  }
}
예제 #4
0
// Test GetNodeClustCf (Specific Node)
TEST(triad, TestGetNodeClustCfSpecific) {
  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();

  for (int i = 0; i < GraphTUN->GetNodes(); i++) {
    double ClustCf = TSnap::GetNodeClustCf(GraphTUN, i);
    VerifyNodeClustCf(i, ClustCf);
  }

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph GraphTN = TriadGetTestTNGraph();

  for (int i = 0; i < GraphTN->GetNodes(); i++) {
    double ClustCf = TSnap::GetNodeClustCf(GraphTN, i);
    VerifyNodeClustCf(i, ClustCf);
  }

  // TNEGraph should be treated as TUNGraph for calculations
  PNEGraph GraphTNE = TriadGetTestTNEGraph();

  for (int i = 0; i < GraphTNE->GetNodes(); i++) {
    double ClustCf = TSnap::GetNodeClustCf(GraphTNE, i);
    VerifyNodeClustCf(i, ClustCf);
  }
}
예제 #5
0
// Test GetLen2Paths: Number of path lengths 2 between pair of nodes
TEST(triad, TestGetLen2Paths) {
  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  for (int i = 0; i < GraphTUN->GetNodes(); i++) {
    for (int j = i + 1; j < GraphTUN->GetNodes(); j++) {
      VerifyLen2Paths(i, j, TSnap::GetLen2Paths(GraphTUN, i, j), 0);
    }
  }
  
  // Test TNGraph which is different from undirected due to out neighbors.
  PNGraph GraphTN = TriadGetTestTNGraph();
  for (int i = 0; i < GraphTN->GetNodes(); i++) {
    for (int j = i + 1; j < GraphTN->GetNodes(); j++) {
      VerifyLen2Paths(i, j, TSnap::GetLen2Paths(GraphTN, i, j), 1);
    }
  }

  // Test TNEGraph which is different from undirected due to out neighbors.
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  for (int i = 0; i < GraphTNE->GetNodes(); i++) {
    for (int j = i + 1; j < GraphTNE->GetNodes(); j++) {
      VerifyLen2Paths(i, j, TSnap::GetLen2Paths(GraphTNE, i, j), 2);
    }
  }
}
예제 #6
0
// Test GetTriads for Whole Graph (Open and Closed)
TEST(triad, TestGetTriadsOpenClosed) {
  const int ExpClosedTr = 3;  // Expected closed triads
  const int ExpOpenTr = 9;    // Expected open triads

  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  int64 ClosedTr = 0;
  int64 OpenTr = 0;

  TSnap::GetTriads(GraphTUN, ClosedTr, OpenTr);
  EXPECT_EQ(ExpClosedTr, ClosedTr);
  EXPECT_EQ(ExpOpenTr, OpenTr);

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph GraphTN = TriadGetTestTNGraph();
  ClosedTr = 0;
  OpenTr = 0;

  TSnap::GetTriads(GraphTN, ClosedTr, OpenTr);
  EXPECT_EQ(ExpClosedTr, ClosedTr);
  EXPECT_EQ(ExpOpenTr, OpenTr);

  // TNEGraph should be treated as TUNGraph for calculations
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  ClosedTr = 0;
  OpenTr = 0;

  TSnap::GetTriads(GraphTNE, ClosedTr, OpenTr);
  EXPECT_EQ(ExpClosedTr, ClosedTr);
  EXPECT_EQ(ExpOpenTr, OpenTr);
}
예제 #7
0
// Test GetNodeTriads (Open and Closed)
TEST(triad, TestGetNodeCOTriads) {
  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  for (int i = 0; i < GraphTUN->GetNodes(); i++) {
    int ClosedTr = -1, OpenTr = -1;
    TSnap::GetNodeTriads(GraphTUN, i, ClosedTr, OpenTr);
    VerifyClosedTriads(i, ClosedTr);
    VerifyOpenTriads(i, OpenTr);
  }
  
  // Test TNGraph which is treated same as undirected.
  PNGraph GraphTN = TriadGetTestTNGraph();
  for (int i = 0; i < GraphTN->GetNodes(); i++) {
    int ClosedTr = -1, OpenTr = -1;
    TSnap::GetNodeTriads(GraphTN, i, ClosedTr, OpenTr);
    VerifyClosedTriads(i, ClosedTr);
    VerifyOpenTriads(i, OpenTr);
  }

  // Test TNEGraph which is treated same as undirected.
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  for (int i = 0; i < GraphTNE->GetNodes(); i++) {
    int ClosedTr = -1, OpenTr = -1;
    TSnap::GetNodeTriads(GraphTNE, i, ClosedTr, OpenTr);
    VerifyClosedTriads(i, ClosedTr);
    VerifyOpenTriads(i, OpenTr);
  }
}
예제 #8
0
// Test GetClustCf (Distribution and Closed and Open)
TEST(triad, TestGetClustCfDistCO) {
  const int ExpClosedTr = 3;  // Expected closed triads
  const int ExpOpenTr = 9;    // Expected open triads

  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  TFltPrV DegToCCfV;
  int64 ClosedTr = 0;
  int64 OpenTr = 0;

  TSnap::GetClustCf(GraphTUN, DegToCCfV, ClosedTr, OpenTr);
  TestDegToCCfVector(DegToCCfV);
  EXPECT_EQ(ExpClosedTr, ClosedTr);
  EXPECT_EQ(ExpOpenTr, OpenTr);

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph GraphTN = TriadGetTestTNGraph();
  DegToCCfV.Clr();
  ClosedTr = 0;
  OpenTr = 0;

  TSnap::GetClustCf(GraphTN, DegToCCfV, ClosedTr, OpenTr);
  TestDegToCCfVector(DegToCCfV);
  EXPECT_EQ(ExpClosedTr, ClosedTr);
  EXPECT_EQ(ExpOpenTr, OpenTr);

  // TNEGraph is not treated the same! Be careful with multigraphs
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  DegToCCfV.Clr();
  ClosedTr = 0;
  OpenTr = 0;

  TSnap::GetClustCf(GraphTNE, DegToCCfV, ClosedTr, OpenTr);
  for (TFltPr *Pair = DegToCCfV.BegI(); Pair < DegToCCfV.EndI(); Pair++) {
    double Diff = Pair->Val2 - 5.0/9.0;   // Used for case 4
    Diff = (Diff < 0) ? -1.0*Diff : Diff; // Used for case 4
    switch ((int) Pair->Val1) {
      case 2:
        EXPECT_EQ(1.0, Pair->Val2);
        break;
      case 4:
        EXPECT_GT(0.00001, Diff); // Due to floats being imprecise
        break;
      case 7:
        EXPECT_EQ(2.0/3.0, Pair->Val2);
        break;
      case 15:
        EXPECT_EQ(0.3, Pair->Val2);
        break;
      default:
        ASSERT_FALSE(true); // Shouldn't have degrees other than listed
        break;
    }
  }
  EXPECT_EQ(ExpClosedTr, ClosedTr);
  EXPECT_EQ(ExpOpenTr, OpenTr);
}
예제 #9
0
파일: test-triad.cpp 프로젝트: Accio/snap
// Test GetClustCf (Distribution and Closed and Open)
TEST(triad, TestGetClustCfDistCO) {
  const int expected_closed = 3;  // Expected closed triads
  const int expected_open = 9;    // Expected open triads

  // Test TUNGraph
  PUNGraph Graph_TUNGraph = TriadGetTestTUNGraph();
  TFltPrV DegToCCfV;
  int64 closed = 0, open = 0;

  TSnap::GetClustCf(Graph_TUNGraph, DegToCCfV, closed, open);
  TestDegToCCfVector(DegToCCfV);
  EXPECT_EQ(expected_closed, closed);
  EXPECT_EQ(expected_open, open);

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph Graph_TNGraph = TriadGetTestTNGraph();
  DegToCCfV.Clr();
  closed = 0, open = 0;

  TSnap::GetClustCf(Graph_TNGraph, DegToCCfV, closed, open);
  TestDegToCCfVector(DegToCCfV);
  EXPECT_EQ(expected_closed, closed);
  EXPECT_EQ(expected_open, open);

  // TNEGraph is not treated the same! Be careful with multigraphs
  PNEGraph Graph_TNEGraph = TriadGetTestTNEGraph();
  DegToCCfV.Clr();
  closed = 0, open = 0;

  TSnap::GetClustCf(Graph_TNEGraph, DegToCCfV, closed, open);
  for (TFltPr *pair = DegToCCfV.BegI(); pair < DegToCCfV.EndI(); pair++) {
    double diff = pair->Val2 - 5.0/9.0;   // Used for case 4
    diff = (diff < 0) ? -1.0*diff : diff; // Used for case 4
    switch ((int) pair->Val1) {
      case 2:
        EXPECT_EQ(1.0, pair->Val2);
        break;
      case 4:
        EXPECT_GT(0.00001, diff); // Due to floats being imprecise
        break;
      case 7:
        EXPECT_EQ(2.0/3.0, pair->Val2);
        break;
      case 15:
        EXPECT_EQ(0.3, pair->Val2);
        break;
      default:
        ASSERT_FALSE(true); // Shouldn't have degrees other than listed
        break;
    }
  }
  EXPECT_EQ(expected_closed, closed);
  EXPECT_EQ(expected_open, open);
}
예제 #10
0
// Test GetTriadEdges
TEST(triad, TestGetTriadEdges) {
  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  EXPECT_EQ(7, TSnap::GetTriadEdges(GraphTUN));

  // TNGraph is not treated the same! Each directed will be counted
  PNGraph GraphTN = TriadGetTestTNGraph();
  EXPECT_EQ(7, TSnap::GetTriadEdges(GraphTN));

  // TNEGraph is not treated the same! Be careful with multigraphs
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  EXPECT_EQ(14, TSnap::GetTriadEdges(GraphTNE));
}
예제 #11
0
// Test GetTriadParticip
// Number of nodes with x number of triangles it participates in
TEST(triad, TestGetTriadParticip) {
  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  TIntPrV TriadCntV;
  TSnap::GetTriadParticip(GraphTUN, TriadCntV);
  VerifyGetTriadParticip(TriadCntV);

  // Test TNGraph which is same as undirected.
  PNGraph GraphTN = TriadGetTestTNGraph();
  TriadCntV.Clr();
  TSnap::GetTriadParticip(GraphTN, TriadCntV);
  VerifyGetTriadParticip(TriadCntV);
  
  // Test TNEGraph which is same as undirected.
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  TriadCntV.Clr();
  TSnap::GetTriadParticip(GraphTN, TriadCntV);
  VerifyGetTriadParticip(TriadCntV);
}
예제 #12
0
// Test GetNodeTriads
TEST(triad, TestGetNodeTriads) {
  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  for (int i = 0; i < GraphTUN->GetNodes(); i++) {
    VerifyClosedTriads(i, TSnap::GetNodeTriads(GraphTUN, i));
  }
  
  // TNGraph is not treated the same! Each directed will be counted
  PNGraph GraphTN = TriadGetTestTNGraph();
  for (int i = 0; i < GraphTN->GetNodes(); i++) {
    VerifyClosedTriads(i, TSnap::GetNodeTriads(GraphTN, i));
  }

  // TNEGraph is not treated the same! Be careful with multigraphs
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  for (int i = 0; i < GraphTNE->GetNodes(); i++) {
    VerifyClosedTriads(i, TSnap::GetNodeTriads(GraphTNE, i));
  }
}
예제 #13
0
// Test GetNodeTriads (GroupSet, InGroupEdges, InOutGroupEdges, OutGroupEdges)
TEST(triad, TestGetNodeTriadsGroupSetAndOut) {
  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  for (int i = 0; i < GraphTUN->GetNodes(); i++) {
    TIntSet GroupSet;
    GetGroupSet(i, GroupSet);
    int InGroupEdges = -1, InOutGroupEdges = -1, OutGroupEdges = -1;
    TSnap::GetNodeTriads(GraphTUN, i, GroupSet, 
                         InGroupEdges, InOutGroupEdges, OutGroupEdges);
    VerifyInGroupEdges(i, InGroupEdges);
    VerifyInOutGroupEdges(i, InOutGroupEdges);
    VerifyOutGroupEdges(i, OutGroupEdges);
  }
  
  // Test TNGraph which is same as undirected.
  PNGraph GraphTN = TriadGetTestTNGraph();
  for (int i = 0; i < GraphTN->GetNodes(); i++) {
    TIntSet GroupSet;
    GetGroupSet(i, GroupSet);
    int InGroupEdges = -1, InOutGroupEdges = -1, OutGroupEdges = -1;
    TSnap::GetNodeTriads(GraphTN, i, GroupSet, 
                         InGroupEdges, InOutGroupEdges, OutGroupEdges);
    VerifyInGroupEdges(i, InGroupEdges);
    VerifyInOutGroupEdges(i, InOutGroupEdges);
    VerifyOutGroupEdges(i, OutGroupEdges);
  }
  
  // Test TNEGraph which is same as undirected.
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  for (int i = 0; i < GraphTNE->GetNodes(); i++) {
    TIntSet GroupSet;
    GetGroupSet(i, GroupSet);
    int InGroupEdges = -1, InOutGroupEdges = -1, OutGroupEdges = -1;
    TSnap::GetNodeTriads(GraphTNE, i, GroupSet, 
                         InGroupEdges, InOutGroupEdges, OutGroupEdges);
    VerifyInGroupEdges(i, InGroupEdges);
    VerifyInOutGroupEdges(i, InOutGroupEdges);
    VerifyOutGroupEdges(i, OutGroupEdges);
  }
}
예제 #14
0
// Test GetTriads for Whole Graph (Only Closed)
TEST(triad, TestGetTriadsClosed) {
  const int ExpClosedTr = 3; // Expected closed triads
  int64 ClosedTr = 0;

  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();

  ClosedTr = TSnap::GetTriads(GraphTUN);
  EXPECT_EQ(ExpClosedTr, ClosedTr);

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph GraphTN = TriadGetTestTNGraph();

  ClosedTr = TSnap::GetTriads(GraphTN);
  EXPECT_EQ(ExpClosedTr, ClosedTr);

  // TNEGraph should be treated as TUNGraph for calculations
  PNEGraph GraphTNE = TriadGetTestTNEGraph();

  ClosedTr = TSnap::GetTriads(GraphTNE);
  EXPECT_EQ(ExpClosedTr, ClosedTr);
}
예제 #15
0
// Test GetClustCf (Average Clustering Coefficient)
TEST(triad, TestGetClustCf) {
  const double ExpClustCf = 109.0/180.0;  // Expected ClustCf (0.60555..)

  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  double ClustCf = 0.0;

  ClustCf = TSnap::GetClustCf(GraphTUN);
  EXPECT_EQ(ExpClustCf, ClustCf);

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph GraphTN = TriadGetTestTNGraph();

  ClustCf = TSnap::GetClustCf(GraphTN);
  EXPECT_EQ(ExpClustCf, ClustCf);

  // TNEGraph should be treated as TUNGraph for calculations
  PNEGraph GraphTNE = TriadGetTestTNEGraph();

  ClustCf = TSnap::GetClustCf(GraphTNE);
  EXPECT_EQ(ExpClustCf, ClustCf);
}
예제 #16
0
// Test GetTriads Close/Open Triad Vector for each NId
TEST(triad, TestGetTriadsVector) {
  // Test TUNGraph
  PUNGraph GraphTUN = TriadGetTestTUNGraph();
  TIntTrV NIdCOTriadV;
  
  TSnap::GetTriads(GraphTUN, NIdCOTriadV);
  TestOpenCloseVector(NIdCOTriadV);

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph GraphTN = TriadGetTestTNGraph();
  NIdCOTriadV.Clr();
  ASSERT_TRUE(NIdCOTriadV.Empty());

  TSnap::GetTriads(GraphTN, NIdCOTriadV);
  TestOpenCloseVector(NIdCOTriadV);

  // TNEGraph should be treated as TUNGraph for calculations
  PNEGraph GraphTNE = TriadGetTestTNEGraph();
  NIdCOTriadV.Clr();
  ASSERT_TRUE(NIdCOTriadV.Empty());
  TestOpenCloseVector(NIdCOTriadV);

}
예제 #17
0
파일: test-triad.cpp 프로젝트: Accio/snap
// Test GetTriads for Whole Graph (Only Closed)
TEST(triad, TestGetTriadsClosed) {
  const int expected_closed = 3; // Expected closed triads

  // Test TUNGraph
  PUNGraph Graph_TUNGraph = TriadGetTestTUNGraph();
  int closed = 0;

  closed = TSnap::GetTriads(Graph_TUNGraph);
  EXPECT_EQ(expected_closed, closed);

  // TNGraph should be treated as TUNGraph for calculations
  PNGraph Graph_TNGraph = TriadGetTestTNGraph();
  closed = 0;

  closed = TSnap::GetTriads(Graph_TNGraph);
  EXPECT_EQ(expected_closed, closed);

  // TNEGraph should be treated as TUNGraph for calculations
  PNEGraph Graph_TNEGraph = TriadGetTestTNEGraph();
  closed = 0;

  closed = TSnap::GetTriads(Graph_TNEGraph);
  EXPECT_EQ(expected_closed, closed);
}