Exemplo n.º 1
0
TEST(TNEANet, AddNodeAttributeError) {
  PNEANet Graph;
  Graph = TNEANet::New();

  TStr StrAttr("name");
  TStr FltAttr("weight");
  TStr IntAttr("test");

  Graph->AddStrAttrN(StrAttr);
  Graph->AddFltAttrN(FltAttr);
  Graph->AddIntAttrN(IntAttr);
  int NumNodes = 5;
  for (int i = 0; i < NumNodes; i++) {
    Graph->AddNode(i);
    Graph->AddIntAttrDatN(i, TInt(i), IntAttr);
    Graph->AddFltAttrDatN(i, TFlt(i), FltAttr);
    TInt Val(i);
    Graph->AddStrAttrDatN(i, Val.GetStr(), StrAttr);
  }
  Graph->DelNode(0);
  for (int j = 1; j < NumNodes; j++) {
    ASSERT_EQ(Graph->GetIntAttrDatN(j, IntAttr), j);
    ASSERT_EQ(Graph->GetFltAttrDatN(j, FltAttr), TFlt(j));
    TInt Val(j);
    ASSERT_EQ(Graph->GetStrAttrDatN(j, StrAttr), Val.GetStr());
  }
}
Exemplo n.º 2
0
// Test node, edge attribute functionality
TEST(TNEANet, AddEdgeNodeAfterAttrAdded) {
  PNEANet Graph;
  Graph = TNEANet::New();

  TStr StrAttr("name");
  TStr EIntAttr("weight");
  TStr NIntAttr("test");

  Graph->AddStrAttrN(StrAttr);
  Graph->AddIntAttrN(NIntAttr);
  Graph->AddIntAttrE(EIntAttr);

  Graph->AddNode(0);
  Graph->AddNode(1);
  Graph->AddNode(2);

  Graph->AddStrAttrDatN(0, "zero", StrAttr);
  Graph->AddStrAttrDatN(1, "one", StrAttr);
  Graph->AddStrAttrDatN(2, "two", StrAttr);

  Graph->AddEdge(0, 1);
  Graph->AddEdge(1, 2);
  Graph->AddEdge(2, 0);

  for (TNEANet::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
    Graph->AddIntAttrDatE(EI.GetId(), EI.GetId()*3+1, EIntAttr);
  }

  for (TNEANet::TEdgeI EI = Graph->BegEI(); EI < Graph->EndEI(); EI++) {
    TInt AttrVal = Graph->GetIntAttrDatE(EI.GetId(), EIntAttr);
    ASSERT_EQ(EI.GetId()*3+1, AttrVal);
  }
}