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();
104 int main(int argc, char* argv[])
106 bool __exit_on_fail = false;
110 if (1 < argc) __exit_on_fail = true;
112 std::ifstream __in("testcases.txt");
115 $RETURNTYPE$ __expected;
116 $METHODPARAMDECLARES$
117 __in >> __expected >> $METHODPARAMSTREAMIN$;
118 if (!__in.good()) break;
120 std::cout << "----------------------------------------" << std::endl
121 << "Test " << (__pass + __fail) << ": ";
127 $RETURNTYPE$ __actual = object.$METHODNAME$($METHODPARAMNAMES$);
129 double __t = __timer_stop();
131 if (__actual == __expected)
133 std::cout << "[PASS] in " << __t << " seconds." << std::endl;
138 std::cout << "[FAIL] in " << __t << " seconds." << std::endl
139 << "-> Input: " << $METHODPARAMSTREAMOUT$ << std::endl
140 << " Actual: " << __actual << std::endl
141 << " Expected: " << __expected << std::endl;
143 if (__exit_on_fail) exit(1);
147 std::cout << "========================================" << std::endl
148 << " Total Pass: " << __pass << std::endl
149 << " Total Fail: " << __fail << std::endl;
153 std::cout << std::endl << "Nice! "
154 << "Don't forget to compile remotely before submitting."