2 #include "$CLASSNAME$.cc"
15 static double __time = 0.0;
17 static void __timer_start()
20 if (gettimeofday(&tv, NULL) == 0)
22 __time = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
26 static double __timer_stop()
28 double start = __time;
30 return __time - start;
34 std::ostream& operator << (std::ostream& out, const std::string& str)
36 out << '"' << str.c_str() << '"';
41 std::ostream& operator << (std::ostream& out, const std::vector<T>& vec)
47 for (size_t i = 1; i < vec.size(); ++i) out << ", " << vec[i];
53 std::istream& operator >> (std::istream& in, std::string& str)
55 while (in.good() && std::isspace(in.peek())) in.get();
58 if (in.good() && (c = in.get()) == '"')
61 while (in.good() && (c = in.get()) != '"')
76 std::istream& operator >> (std::istream& in, std::vector<T>& vec)
78 while (in.good() && std::isspace(in.peek())) in.get();
81 if (in.good() && (c = in.get()) == '{')
83 while (in.good() && std::isspace(in.peek())) in.get();
86 while (in.good() && (c = in.get()) != '}')
88 if (c != ',') in.putback(c);
91 while (in.good() && std::isspace(in.peek())) in.get();
103 int main(int argc, char* argv[])
105 bool __exit_on_fail = false;
109 if (1 < argc) __exit_on_fail = true;
111 std::ifstream __in("testcases.txt");
114 $RETURNTYPE$ __expected;
115 $METHODPARAMDECLARES$
116 __in >> __expected >> $METHODPARAMSTREAMIN$;
117 if (!__in.good()) break;
119 std::cout << "----------------------------------------" << std::endl
120 << "Test " << (__pass + __fail) << ": ";
126 $RETURNTYPE$ __actual = object.$METHODNAME$($METHODPARAMNAMES$);
128 double __t = __timer_stop();
130 if (__actual == __expected)
132 std::cout << "[PASS] in " << __t << " seconds." << std::endl;
137 std::cout << "[FAIL] in " << __t << " seconds." << std::endl
138 << "-> Input: " << $METHODPARAMSTREAMOUT$ << std::endl
139 << " Actual: " << __actual << std::endl
140 << " Expected: " << __expected << std::endl;
142 if (__exit_on_fail) exit(1);
146 std::cout << "========================================" << std::endl
147 << " Total Pass: " << __pass << std::endl
148 << " Total Fail: " << __fail << std::endl;
152 std::cout << std::endl << "Nice! "
153 << "Don't forget to compile remotely before submitting."