2 #include "$CLASSNAME$.cc"
17 const static double __EPSILON = 1e-9;
18 static double __time = 0.0;
20 static void __timer_start()
23 if (gettimeofday(&tv, NULL) == 0)
25 __time = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
29 static double __timer_stop()
31 double start = __time;
33 return __time - start;
37 std::ostream& operator << (std::ostream& out, const std::string& str)
39 out << '"' << str.c_str() << '"';
44 std::ostream& operator << (std::ostream& out, const std::vector<T>& vec)
50 for (size_t i = 1; i < vec.size(); ++i) out << ", " << vec[i];
56 std::istream& operator >> (std::istream& in, std::string& str)
58 while (in.good() && std::isspace(in.peek())) in.get();
61 if (in.good() && (c = in.get()) == '"')
64 while (in.good() && (c = in.get()) != '"')
79 std::istream& operator >> (std::istream& in, std::vector<T>& vec)
81 while (in.good() && std::isspace(in.peek())) in.get();
84 if (in.good() && (c = in.get()) == '{')
86 while (in.good() && std::isspace(in.peek())) in.get();
89 while (in.good() && (c = in.get()) != '}')
91 if (c != ',') in.putback(c);
94 while (in.good() && std::isspace(in.peek())) in.get();
106 bool __equals(const T& actual, const T& expected)
108 return actual == expected;
111 bool __equals(double actual, double expected)
113 if (std::abs(actual - expected) < __EPSILON)
119 double minimum = std::min(expected * (1.0 - __EPSILON), expected * (1.0 + __EPSILON));
120 double maximum = std::max(expected * (1.0 - __EPSILON), expected * (1.0 + __EPSILON));
121 return actual > minimum && actual < maximum;
125 bool __equals(const std::vector<double>& actual, const std::vector<double>& expected)
127 if (actual.size() != expected.size())
130 for (size_t i = 0; i < actual.size(); ++i)
131 if (!__equals(actual[i], expected[i]))
138 int main(int argc, char* argv[])
140 bool __exit_on_fail = false;
144 if (1 < argc) __exit_on_fail = true;
146 std::ifstream __in("testcases.txt");
149 $RETURNTYPE$ __expected;
150 $METHODPARAMDECLARES$
151 __in >> __expected >> $METHODPARAMSTREAMIN$;
152 if (!__in.good()) break;
154 std::cout << "----------------------------------------" << std::endl
155 << "Test " << (__pass + __fail) << ": ";
161 $RETURNTYPE$ __actual = object.$METHODNAME$($METHODPARAMNAMES$);
163 double __t = __timer_stop();
165 if (__equals(__actual, __expected))
167 std::cout << "[PASS] in " << __t << " seconds." << std::endl;
172 std::cout << "[FAIL] in " << __t << " seconds." << std::endl
173 << "-> Input: " << $METHODPARAMSTREAMOUT$ << std::endl
174 << " Actual: " << __actual << std::endl
175 << " Expected: " << __expected << std::endl;
177 if (__exit_on_fail) exit(1);
181 std::cout << "========================================" << std::endl
182 << " Total Pass: " << __pass << std::endl
183 << " Total Fail: " << __fail << std::endl;
187 std::cout << std::endl << "Nice! "
188 << "Don't forget to compile remotely before submitting."