// XPE.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include #include //#include "tests.cpp" using namespace std; struct Tree_Cell { char name[20]; int value; Tree_Cell* next[50]; int iMax_Cell; }; struct Data_Out { int daykey; string outstr[100]; int strmax; }; /////////////////////////////////////////////////// //////////////////////////////////HESH DATA /////////////////////////////////////////////////// class HeshData { private: int makehash(string name) { int sum; sum=0; for(int i=0; iiHeshMaxSize) {sum = 0;} if (wepassed>iHeshMaxSize-1) {return -1;} } heshnames[sum] = name; sOrgHeshNames[maxOHNames]=name; maxOHNames++; return sum; } int GetHash(string name) { int sum, wepassed; wepassed = 0; sum = makehash(name); while(heshnames[sum]!=name) { if (heshnames[sum]=="*"){return -1;} sum++; wepassed++; if (sum>iHeshMaxSize) {sum = 0;} if (wepassed >iHeshMaxSize-1) {return -1;} } return sum; } string *sOrgHeshNames; int maxOHNames; int iHeshMaxSize; private: string heshnames[100]; }; /////////////////////////////////////////////////// /////////////////////////////////////////////////// /////////////////////////////////////////////////// void MakeData(HeshData *Hesh,Tree_Cell** cNods, char *fname) { /////Читаем строчку char buffer [256]; char name[20],cValue[100]; string sLine; fstream fin; fin.open(fname,ios::in); fin.getline(buffer,256); sLine = buffer; Tree_Cell* Last_Header; Last_Header = new Tree_Cell; Last_Header->iMax_Cell=0; Tree_Cell* Last_Main_Header; Last_Main_Header = new Tree_Cell; Last_Main_Header = Last_Header; while(sLine != "") { int i2=0; for(int i=0; iname,name); i+=1; //read ':' int k=0; while((sLine[i]!=':')&&(sLine[i]!=','))//Читаем значения до двоеточия { cValue[k]=sLine[i]; k++; i++; if (i>sLine.length()) {break;} } cValue[k]='\0'; //Считали значение //MessageBox(hWnd,cValue,"MESSAGE",MB_OK); Last_Header->value = atoi(cValue); //Заполняем ячейку ///////////////////////////////////////////////////// if(Last_Header != Last_Main_Header) //Добавляем ее к отцу { Last_Main_Header->next[Last_Main_Header->iMax_Cell] = new Tree_Cell; Last_Main_Header->next[Last_Main_Header->iMax_Cell] = Last_Header; Last_Main_Header->iMax_Cell++; } Last_Header = new Tree_Cell; //Создаем новый лист для следуещго параметра, если его нет то зря тратим память*/ }//else }//for string sNodName; sNodName = Last_Main_Header->name; cNods[Hesh->SetHash(sNodName)] = Last_Main_Header; //Загоняем в Массив строительных ячеек по имени. Last_Main_Header = new Tree_Cell; //для следующей итерации, создаем новый нод; Last_Main_Header->iMax_Cell = 0; Last_Header = new Tree_Cell; Last_Header = Last_Main_Header; fin.getline(buffer,256); sLine = buffer; //MessageBox(hWnd,sNodName.c_str(),"MESSAGE",MB_OK); //MessageBox(hWnd, buffer,"MESSAGE",MB_OK); } //cout<=Hesh->maxOHNames){return;} iHesh = Hesh->GetHash(Hesh->sOrgHeshNames[i]); //cout<name<name; Data[i].outstr[Data[i].strmax] += " "; Data[i].daykey = cNods[iHesh]->value; //Data[i].outstr[Data[i].strmax] += " дней."; Data[i].strmax +=1; for(int j=0; jiMax_Cell; j++) { int iHesh2; string sName; sName = cNods[iHesh]->next[j]->name; iHesh2 = Hesh->GetHash(sName); //быдлкод if (Data[i].strmax<0){Data[i].strmax = 1;} Data[i].outstr[Data[i].strmax] = sName; char buffer[20]; itoa(cNods[iHesh]->next[j]->value,buffer,10); Data[i].outstr[Data[i].strmax] += " "; Data[i].outstr[Data[i].strmax] += buffer; Data[i].outstr[Data[i].strmax] += " шт. "; //cout<=0; i-=1) //Test hesh names indexes { itoa(i,buff,10); name = "ara"; name +=buff; EXPECT_EQ(inxes[i],Hesh.GetHash(name)); } } TEST(InputTest) { cout<<"running input test"<next[0]->value,4); EXPECT_EQ(cNods[Hesh.GetHash("Кухня")]->next[1]->value,5); EXPECT_EQ(cNods[Hesh.GetHash("Дом")]->next[0]->value,20); EXPECT_EQ(cNods[Hesh.GetHash("Дом")]->next[1]->value,1); EXPECT_STREQ(cNods[Hesh.GetHash("Кухня")]->next[0]->name,"Дерево"); EXPECT_STREQ(cNods[Hesh.GetHash("Кухня")]->next[1]->name,"Деревокав"); EXPECT_STREQ(cNods[Hesh.GetHash("Дом")]->next[0]->name,"Дерево"); EXPECT_STREQ(cNods[Hesh.GetHash("Дом")]->next[1]->name,"Кухня"); EXPECT_STREQ(cNods[Hesh.GetHash("Дом")]->name,"Дом"); EXPECT_STREQ(cNods[Hesh.GetHash("Кухня")]->name,"Кухня"); } TEST(OutputTest) { cout<<"running output test"<next[0]->name<maxval){maxval = Data[i+1].daykey; } tmp = Data[i+1].daykey; Data[i+1].daykey = Data[i].daykey; Data[i].daykey = tmp; tmp = Data[i+1].strmax; for(int k=0; knext[cNods[1]->iMax_Cell]->name; /*string sNodName = "Хрень"; cout<next[1]->name; */ int result=RUN_ALL_TESTS(); getchar(); return 1;//result; }