本文整理汇总了C++中TPt::IsOk方法的典型用法代码示例。如果您正苦于以下问题:C++ TPt::IsOk方法的具体用法?C++ TPt::IsOk怎么用?C++ TPt::IsOk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TPt
的用法示例。
在下文中一共展示了TPt::IsOk方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
// Test update node data
TEST(TNodeEdgeNet, UpdateNodeData) {
int NNodes = 10000;
int NEdges = 100000;
TPt <TNodeEdgeNet<TInt, TInt> > Net;
TPt <TNodeEdgeNet<TInt, TInt> > Net1;
TPt <TNodeEdgeNet<TInt, TInt> > Net2;
int i;
int n;
int NCount;
int x,y;
Net = TNodeEdgeNet<TInt, TInt>::New();
EXPECT_EQ(1,Net->Empty());
// create the nodes
for (i = 0; i < NNodes; i++) {
Net->AddNode(i,i+5);
}
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(NNodes,Net->GetNodes());
// create random edges
NCount = NEdges;
while (NCount > 0) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
n = Net->AddEdge(x, y);
NCount--;
}
EXPECT_EQ(NEdges,Net->GetEdges());
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(1,Net->IsOk());
for (i = 0; i < NNodes; i++) {
EXPECT_EQ(1,Net->IsNode(i));
}
EXPECT_EQ(0,Net->IsNode(NNodes));
EXPECT_EQ(0,Net->IsNode(NNodes+1));
EXPECT_EQ(0,Net->IsNode(2*NNodes));
// test node data
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
EXPECT_EQ(NI.GetId()+5, Net->GetNDat(NI.GetId()));
}
// update node data, node ID + 10
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
Net->SetNDat(NI.GetId(), NI.GetId()+10);
}
// test node data
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
EXPECT_EQ(NI.GetId()+10, Net->GetNDat(NI.GetId()));
}
}
示例2:
// Test the default constructor
TEST(TNodeEdgeNet, DefaultConstructor) {
TPt <TNodeEdgeNet<TInt, TInt> > Net;
Net = TNodeEdgeNet<TInt, TInt>::New();
EXPECT_EQ(0,Net->GetNodes());
EXPECT_EQ(0,Net->GetEdges());
EXPECT_EQ(1,Net->IsOk());
EXPECT_EQ(1,Net->Empty());
EXPECT_EQ(1,Net->HasFlag(gfDirected));
EXPECT_EQ(1,Net->HasFlag(gfNodeDat));
}
示例3: FOut
// Test node, edge creation
TEST(TNodeEdgeNet, ManipulateNodesEdges) {
int NNodes = 10000;
int NEdges = 100000;
const char *FName = "test.net";
TPt <TNodeEdgeNet<TInt, TInt> > Net;
TPt <TNodeEdgeNet<TInt, TInt> > Net1;
TPt <TNodeEdgeNet<TInt, TInt> > Net2;
int i;
int n;
int NCount;
int x,y;
int Deg, InDeg, OutDeg;
Net = TNodeEdgeNet<TInt, TInt>::New();
EXPECT_EQ(1,Net->Empty());
// create the nodes
for (i = 0; i < NNodes; i++) {
Net->AddNode(i);
}
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(NNodes,Net->GetNodes());
// create random edges
NCount = NEdges;
while (NCount > 0) {
x = (long) (drand48() * NNodes);
y = (long) (drand48() * NNodes);
n = Net->AddEdge(x, y);
NCount--;
}
EXPECT_EQ(NEdges,Net->GetEdges());
EXPECT_EQ(0,Net->Empty());
EXPECT_EQ(1,Net->IsOk());
for (i = 0; i < NNodes; i++) {
EXPECT_EQ(1,Net->IsNode(i));
}
EXPECT_EQ(0,Net->IsNode(NNodes));
EXPECT_EQ(0,Net->IsNode(NNodes+1));
EXPECT_EQ(0,Net->IsNode(2*NNodes));
// nodes iterator
NCount = 0;
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
NCount++;
}
EXPECT_EQ(NNodes,NCount);
// edges per node iterator
NCount = 0;
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
for (int e = 0; e < NI.GetOutDeg(); e++) {
NCount++;
}
}
EXPECT_EQ(NEdges,NCount);
// edges iterator
NCount = 0;
for (TNodeEdgeNet<TInt, TInt>::TEdgeI EI = Net->BegEI(); EI < Net->EndEI(); EI++) {
NCount++;
}
EXPECT_EQ(NEdges,NCount);
// node degree
for (TNodeEdgeNet<TInt, TInt>::TNodeI NI = Net->BegNI(); NI < Net->EndNI(); NI++) {
Deg = NI.GetDeg();
InDeg = NI.GetInDeg();
OutDeg = NI.GetOutDeg();
EXPECT_EQ(Deg,InDeg+OutDeg);
}
// assignment
Net1 = TNodeEdgeNet<TInt, TInt>::New();
*Net1 = *Net;
EXPECT_EQ(NNodes,Net1->GetNodes());
EXPECT_EQ(NEdges,Net1->GetEdges());
EXPECT_EQ(0,Net1->Empty());
EXPECT_EQ(1,Net1->IsOk());
// saving and loading
{
TFOut FOut(FName);
Net->Save(FOut);
FOut.Flush();
}
{
TFIn FIn(FName);
Net2 = TNodeEdgeNet<TInt, TInt>::Load(FIn);
}
//.........这里部分代码省略.........