TEST(TNEANet, DelSAttrDatN) { PNEANet Graph; Graph = TNEANet::New(); Graph->AddNode(0); TStr IntAttr("TestInt"); TInt IntId; Graph->AddSAttrN(IntAttr, atInt, IntId); TStr FltAttr("TestFlt"); TInt FltId; Graph->AddSAttrN(FltAttr, atFlt, FltId); TStr StrAttr("TestStr"); TInt StrId; Graph->AddSAttrN(StrAttr, atStr, StrId); TInt Id(0); int status = Graph->DelSAttrDatN(Id, IntAttr); EXPECT_EQ(-1, status); status = Graph->DelSAttrDatN(Id, IntId); EXPECT_EQ(-1, status); TInt IntVal(5); Graph->AddSAttrDatN(Id, IntId, IntVal); status = Graph->DelSAttrDatN(Id, IntAttr); EXPECT_EQ(0, status); Graph->AddSAttrDatN(Id, IntId, IntVal); status = Graph->DelSAttrDatN(Id, IntId); EXPECT_EQ(0, status); status = Graph->DelSAttrDatN(Id, IntId); EXPECT_EQ(-1, status); TInt ErrorId(1); status = Graph->DelSAttrDatN(ErrorId, IntId); EXPECT_EQ(-1, status); TFlt FltVal(5.0); Graph->AddSAttrDatN(Id, FltId, FltVal); status = Graph->DelSAttrDatN(Id, FltAttr); EXPECT_EQ(0, status); Graph->AddSAttrDatN(Id, FltId, FltVal); status = Graph->DelSAttrDatN(Id, FltId); EXPECT_EQ(0, status); status = Graph->DelSAttrDatN(Id, FltId); EXPECT_EQ(-1, status); status = Graph->DelSAttrDatN(ErrorId, FltId); EXPECT_EQ(-1, status); TStr StrVal("5"); Graph->AddSAttrDatN(Id, StrId, StrVal); status = Graph->DelSAttrDatN(Id, StrAttr); EXPECT_EQ(0, status); Graph->AddSAttrDatN(Id, StrId, StrVal); status = Graph->DelSAttrDatN(Id, StrId); EXPECT_EQ(0, status); status = Graph->DelSAttrDatN(Id, StrId); EXPECT_EQ(-1, status); status = Graph->DelSAttrDatN(ErrorId, StrId); EXPECT_EQ(-1, status); }
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()); }
void CfgNextTok (void) /* Read the next token from the input stream */ { Again: /* Skip whitespace */ while (isspace (C)) { NextChar (); } /* Remember the current position */ CfgErrorPos = InputPos; /* Identifier? */ if (C == '_' || IsAlpha (C)) { /* Read the identifier */ SB_Clear (&CfgSVal); while (C == '_' || IsAlNum (C)) { SB_AppendChar (&CfgSVal, C); NextChar (); } SB_Terminate (&CfgSVal); CfgTok = CFGTOK_IDENT; return; } /* Hex number? */ if (C == '$') { NextChar (); if (!isxdigit (C)) { CfgError (&CfgErrorPos, "Hex digit expected"); } CfgIVal = 0; while (isxdigit (C)) { CfgIVal = CfgIVal * 16 + DigitVal (C); NextChar (); } CfgTok = CFGTOK_INTCON; return; } /* Decimal number? */ if (isdigit (C)) { CfgIVal = 0; while (isdigit (C)) { CfgIVal = CfgIVal * 10 + DigitVal (C); NextChar (); } CfgTok = CFGTOK_INTCON; return; } /* Other characters */ switch (C) { case '-': NextChar (); CfgTok = CFGTOK_MINUS; break; case '+': NextChar (); CfgTok = CFGTOK_PLUS; break; case '*': NextChar (); CfgTok = CFGTOK_MUL; break; case '/': NextChar (); CfgTok = CFGTOK_DIV; break; case '(': NextChar (); CfgTok = CFGTOK_LPAR; break; case ')': NextChar (); CfgTok = CFGTOK_RPAR; break; case '{': NextChar (); CfgTok = CFGTOK_LCURLY; break; case '}': NextChar (); CfgTok = CFGTOK_RCURLY; break; case ';': NextChar (); CfgTok = CFGTOK_SEMI; break; case '.': NextChar (); CfgTok = CFGTOK_DOT; break; case ',': NextChar (); CfgTok = CFGTOK_COMMA; break; case '=': NextChar (); CfgTok = CFGTOK_EQ; break; case ':': NextChar (); CfgTok = CFGTOK_COLON; break; case '\"': StrVal (); break; case '#': /* Comment */ while (C != '\n' && C != EOF) { NextChar (); } if (C != EOF) { goto Again; } CfgTok = CFGTOK_EOF; break; case '%': NextChar (); switch (C) { case 'O': NextChar (); if (OutputName) { SB_CopyStr (&CfgSVal, OutputName); } else { SB_Clear (&CfgSVal); } SB_Terminate (&CfgSVal); OutputNameUsed = 1; CfgTok = CFGTOK_STRCON; break; case 'S': NextChar (); CfgIVal = StartAddr; CfgTok = CFGTOK_INTCON; break; default: CfgError (&CfgErrorPos, "Invalid format specification"); } break; case EOF: CfgTok = CFGTOK_EOF; break; default: CfgError (&CfgErrorPos, "Invalid character `%c'", C); } }