TEST(TestJSONDecoder, Float) { // broken value ASSERT_NO_THROW(qi::decodeJSON("42.43")); ASSERT_NO_THROW(qi::decodeJSON("-42.43")); ASSERT_NO_THROW(qi::decodeJSON("0.42")); ASSERT_NO_THROW(qi::decodeJSON("42.0")); ASSERT_NO_THROW(qi::decodeJSON("0.0000042")); ASSERT_NO_THROW(qi::decodeJSON("0.42").asDouble()); ASSERT_NO_THROW(qi::decodeJSON("40.40e+10")); ASSERT_NO_THROW(qi::decodeJSON("42e+10")); ASSERT_NO_THROW(qi::decodeJSON("42e-10")); ASSERT_NO_THROW(qi::decodeJSON("42e10")); EXPECT_DOUBLE_EQ(0.42, qi::decodeJSON("0.42").asDouble()); EXPECT_DOUBLE_EQ(42.0, qi::decodeJSON("42.0").asDouble()); EXPECT_DOUBLE_EQ(0.0000042, qi::decodeJSON("0.0000042").asDouble()); // positive value EXPECT_DOUBLE_EQ(42.43, qi::decodeJSON("42.43").asDouble()); // negative value EXPECT_DOUBLE_EQ(-42.43, qi::decodeJSON("-42.43").asDouble()); // with E EXPECT_DOUBLE_EQ(42e+10, qi::decodeJSON("42e+10").asDouble()); EXPECT_DOUBLE_EQ(42e-10, qi::decodeJSON("42e-10").asDouble()); EXPECT_DOUBLE_EQ(42e10, qi::decodeJSON("42e10").asDouble()); // max/min vals EXPECT_DOUBLE_EQ(DBL_MAX, qi::decodeJSON(cleanStr(STR(DBL_MAX))).asDouble()); EXPECT_DOUBLE_EQ(DBL_MIN, qi::decodeJSON(cleanStr(STR(DBL_MIN))).asDouble()); }
int isInFile(char *targ, char *filename){ FILE *fp; //fprintf(stderr,"Checking file '%s' for string '%s...\n",filename,targ); fp = fopen(filename,"r"); if(fp == NULL){ //fprintf(stderr,"Creating new file '%s'...\n",filename); fp = fopen(filename,"w"); fclose(fp); fp = fopen(filename,"r"); } char *inputLine = malloc(sizeof(char)*256); while(fgets(inputLine,512,fp) != NULL){ //fprintf(stderr,"Comparing target '%s' to file entry '%s'...\n",targ,inputLine); if(strcmp(cleanStr(inputLine),targ) == 0){ //fprintf(stderr,"Match!\n"); return 1; } } fclose(fp); //fprintf(stderr,"No match found.\n"); return 0; }
int TableManagement::writeToDisk(){ string path = string(".\\Table\\") + cleanStr("TableInfo"); ofstream fout(path.c_str()); if (!fout){ fout.close(); throw "No TableInfo Files Found!\n"; return false; } else { for (size_t i = 0; i < TableInfomation.size(); i++){ fout << TableInfomation.at(i).Tablename<<endl; for (size_t j = 0; j < TableInfomation.at(i).Columns.size() - 1; j++){ fout << TableInfomation.at(i).Columns.at(j).column_name <<","; } if (TableInfomation.at(i).Columns.size() >= 1) { fout << TableInfomation.at(i).Columns.at(TableInfomation.at(i).Columns.size()-1).column_name << endl; } for (size_t j = 0; j < TableInfomation.at(i).Columns.size() - 1; j++){ fout << TableInfomation.at(i).Columns.at(j).datatype << ","; } if (TableInfomation.at(i).Columns.size() >= 1) { fout << TableInfomation.at(i).Columns.at(TableInfomation.at(i).Columns.size()-1).datatype << endl; } fout << TableInfomation.at(i).primaryKey.column_name << endl; fout << TableInfomation.at(i).primaryKey.datatype << endl; } fout.close(); return true; } }
int isPalindrome(char *str) { char temp[MAX_SIZE]; cleanStr(str); copyStr(str, temp); reverseStr(temp); if(isEqual(str, temp)){ return 1; } return 0; }
int TableManagement::initialFromDisk(){ string path = string(".\\Table\\") + cleanStr("TableInfo"); ifstream fin(path.c_str()); if (!fin){ string info = "No TableInfo Files Found!\n"; fin.close(); throw info; return false; } else{ int count = 0; this->TableInfomation.clear(); char s[1000]; while (fin.getline(s, 1000), !fin.eof()){ TableInfo info; // Name info.Tablename = Text2Inner(&s[0]); fin.getline(s, 1000); //Attributes for (size_t i = 0, len = 0;strlen(s) && i <= strlen(s); i++){ if (s[i] == ',' || s[i] == '\n' || s[i] == '\0') info.Columns.push_back(ColumnTitle(Text2Inner(&s[i - len], len))), len = 0; else len++; } vector<DataType> types; int tmp; types.clear(); fin.getline(s, 1000); //DataType for (size_t i = 0, j = 0, len = 0; i < info.Columns.size(); i++, j += 2){ tmp = s[j] - '0'; types.push_back((DataType)tmp); info.Columns.at(i).datatype = types[i]; } fin.getline(s, 1000); //Parimary Key info.primaryKey.column_name = Text2Inner(&s[0]); fin.getline(s, 1000); //Parimary Key DataType tmp = s[0] - '0'; info.primaryKey.datatype = (DataType)tmp; TableInfomation.push_back(info); count++; } this->TableNum = count; fin.close(); return true; } }
int main(void){ HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); static char string[1000] = ""; char cmd[1000] = ""; int exitCheck = 0; changeSize(); printIntro(string); SetConsoleTextAttribute(hConsole, 0); system("cls"); printMainString(string, 1); printInputField(string); while (!exitCheck){ SetConsoleTextAttribute(hConsole, 14); fgets(cmd, 999, stdin); if ((strcmp(cmd, "") != 0)) exitCheck = executeCmd(cmd, string, 7 + strlen(string) / 74); cleanStr(cmd); } return 0; }