X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fcom%2Fdogcows%2Fresources%2FC%2B%2BDriver;h=24ab333609ffa5ed8a51c9c80f0b32943fe2fb19;hb=5e3d72f23da7634e1b87d005333eb7708ea78e4d;hp=60ef873967713dd8bd18ec8331aa3f24df74c6cc;hpb=6787bf85ff50a6c7832bb122068118f041c8335f;p=chaz%2Fvimcoder diff --git a/src/com/dogcows/resources/C++Driver b/src/com/dogcows/resources/C++Driver index 60ef873..24ab333 100644 --- a/src/com/dogcows/resources/C++Driver +++ b/src/com/dogcows/resources/C++Driver @@ -22,7 +22,7 @@ static void __timer_start() struct timeval tv; if (gettimeofday(&tv, NULL) == 0) { - __time = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001; + __time = double(tv.tv_sec) + double(tv.tv_usec) * 0.000001; } } @@ -34,6 +34,12 @@ static double __timer_stop() } +static void __eat_whitespace(std::istream& in) +{ + while (in.good() && std::isspace(in.peek())) in.get(); +} + + std::ostream& operator << (std::ostream& out, const std::string& str) { out << '"' << str.c_str() << '"'; @@ -55,7 +61,7 @@ std::ostream& operator << (std::ostream& out, const std::vector& vec) std::istream& operator >> (std::istream& in, std::string& str) { - while (in.good() && std::isspace(in.peek())) in.get(); + __eat_whitespace(in); int c; if (in.good() && (c = in.get()) == '"') @@ -74,26 +80,29 @@ std::istream& operator >> (std::istream& in, std::string& str) template std::istream& operator >> (std::istream& in, std::vector& vec) { - while (in.good() && std::isspace(in.peek())) in.get(); + __eat_whitespace(in); int c; if (in.good() && (c = in.get()) == '{') { - while (in.good() && std::isspace(in.peek())) in.get(); - T t; + __eat_whitespace(in); vec.clear(); while (in.good() && (c = in.get()) != '}') { if (c != ',') in.putback(c); + + T t; in >> t; + __eat_whitespace(in); + vec.push_back(t); - while (in.good() && std::isspace(in.peek())) in.get(); } } return in; } + template bool __equals(const T& actual, const T& expected) { @@ -132,9 +141,9 @@ int main(int argc, char* argv[]) bool __exit_on_fail = false; int __pass = 0; int __fail = 0; - + if (1 < argc) __exit_on_fail = true; - + std::ifstream __in("testcases.txt"); for(;;) { @@ -142,18 +151,18 @@ int main(int argc, char* argv[]) $METHODPARAMDECLARES$ __in >> __expected >> $METHODPARAMSTREAMIN$; if (!__in.good()) break; - + std::cout << "----------------------------------------" << std::endl << "Test " << (__pass + __fail) << ": "; std::cout.flush(); - + __timer_start(); - + $CLASSNAME$ object; $RETURNTYPE$ __actual = object.$METHODNAME$($METHODPARAMNAMES$); - + double __t = __timer_stop(); - + if (__equals(__actual, __expected)) { std::cout << "[PASS] in " << __t << " seconds." << std::endl;