// 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); } }
TEST(TNEANet, GetSAttrVE) { PNEANet Graph; Graph = TNEANet::New(); Graph->AddNode(0); Graph->AddNode(1); Graph->AddEdge(0, 1, 0); TStr IntAttr("TestInt"); TInt IntId; Graph->AddSAttrE(IntAttr, atInt, IntId); TStr FltAttr("TestFlt"); TInt FltId; Graph->AddSAttrE(FltAttr, atFlt, FltId); TStr StrAttr("TestStr"); TInt StrId; Graph->AddSAttrE(StrAttr, atStr, StrId); TInt Id(0); TInt IntVal(5); Graph->AddSAttrDatE(Id, IntId, IntVal); TFlt FltVal(5.0); Graph->AddSAttrDatE(Id, FltId, FltVal); TStr StrVal("5"); Graph->AddSAttrDatE(Id, StrId, StrVal); TAttrPrV AttrV; int status = Graph->GetSAttrVE(Id, atInt, AttrV); EXPECT_EQ(0, status); EXPECT_EQ(1, AttrV.Len()); status = Graph->GetSAttrVE(Id, atFlt, AttrV); EXPECT_EQ(0, status); EXPECT_EQ(1, AttrV.Len()); status = Graph->GetSAttrVE(Id, atStr, AttrV); EXPECT_EQ(0, status); EXPECT_EQ(1, AttrV.Len()); //status = Graph->GetSAttrVE(Id, atAny, AttrV); //EXPECT_EQ(0, status); //EXPECT_EQ(3, AttrV.Len()); //status = Graph->GetSAttrVE(Id, atUndef, AttrV); //EXPECT_EQ(0, status); //EXPECT_EQ(0, AttrV.Len()); //TInt ErrorId(1); //status = Graph->GetSAttrVE(ErrorId, atUndef, AttrV); //EXPECT_EQ(-1, status); }
TEST(TNEANet, GetIdVSAttrE) { PNEANet Graph; Graph = TNEANet::New(); TStr IntAttr("TestInt"); TInt IntId; Graph->AddSAttrE(IntAttr, atInt, IntId); TStr FltAttr("TestFlt"); TInt FltId; Graph->AddSAttrE(FltAttr, atFlt, FltId); TStr StrAttr("TestStr"); TInt StrId; Graph->AddSAttrE(StrAttr, atStr, StrId); TInt IntVal(0); TFlt FltVal(0); TStr StrVal("test"); Graph->AddNode(0); for (int i = 0; i < 10; i++) { Graph->AddNode(i+1); Graph->AddEdge(i, i+1, i); TInt Id(i); Graph->AddSAttrDatE(Id, IntId, IntVal); if (i%2 == 0) { Graph->AddSAttrDatE(Id, FltId, FltVal); } } Graph->AddSAttrDatE(0, StrId, StrVal); TIntV IdV; Graph->GetIdVSAttrE(IntAttr, IdV); EXPECT_EQ(10, IdV.Len()); Graph->GetIdVSAttrE(IntId, IdV); EXPECT_EQ(10, IdV.Len()); Graph->GetIdVSAttrE(FltAttr, IdV); EXPECT_EQ(5, IdV.Len()); Graph->GetIdVSAttrE(FltId, IdV); EXPECT_EQ(5, IdV.Len()); Graph->GetIdVSAttrE(StrAttr, IdV); EXPECT_EQ(1, IdV.Len()); Graph->GetIdVSAttrE(StrId, IdV); EXPECT_EQ(1, IdV.Len()); }
TEST(TNEANet, DelSAttrDatE) { PNEANet Graph; Graph = TNEANet::New(); Graph->AddNode(0); Graph->AddNode(1); Graph->AddEdge(0, 1, 0); TStr IntAttr("TestInt"); TInt IntId; Graph->AddSAttrE(IntAttr, atInt, IntId); TStr FltAttr("TestFlt"); TInt FltId; Graph->AddSAttrE(FltAttr, atFlt, FltId); TStr StrAttr("TestStr"); TInt StrId; Graph->AddSAttrE(StrAttr, atStr, StrId); TInt Id(0); int status = Graph->DelSAttrDatE(Id, IntAttr); EXPECT_EQ(-1, status); status = Graph->DelSAttrDatE(Id, IntId); EXPECT_EQ(-1, status); TInt IntVal(5); Graph->AddSAttrDatE(Id, IntId, IntVal); status = Graph->DelSAttrDatE(Id, IntAttr); EXPECT_EQ(0, status); Graph->AddSAttrDatE(Id, IntId, IntVal); status = Graph->DelSAttrDatE(Id, IntId); EXPECT_EQ(0, status); status = Graph->DelSAttrDatE(Id, IntId); EXPECT_EQ(-1, status); TInt ErrorId(1); status = Graph->DelSAttrDatE(ErrorId, IntId); EXPECT_EQ(-1, status); TFlt FltVal(5.0); Graph->AddSAttrDatE(Id, FltId, FltVal); status = Graph->DelSAttrDatE(Id, FltAttr); EXPECT_EQ(0, status); Graph->AddSAttrDatE(Id, FltId, FltVal); status = Graph->DelSAttrDatE(Id, FltId); EXPECT_EQ(0, status); status = Graph->DelSAttrDatE(Id, FltId); EXPECT_EQ(-1, status); status = Graph->DelSAttrDatE(ErrorId, FltId); EXPECT_EQ(-1, status); TStr StrVal("5"); Graph->AddSAttrDatE(Id, StrId, StrVal); status = Graph->DelSAttrDatE(Id, StrAttr); EXPECT_EQ(0, status); Graph->AddSAttrDatE(Id, StrId, StrVal); status = Graph->DelSAttrDatE(Id, StrId); EXPECT_EQ(0, status); status = Graph->DelSAttrDatE(Id, StrId); EXPECT_EQ(-1, status); status = Graph->DelSAttrDatE(ErrorId, StrId); EXPECT_EQ(-1, status); }