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 static void __eat_whitespace(std::istream& in)
39 while (in.good() && std::isspace(in.peek())) in.get();
43 std::ostream& operator << (std::ostream& out, const std::string& str)
45 out << '"' << str.c_str() << '"';
50 std::ostream& operator << (std::ostream& out, const std::vector<T>& vec)
56 for (size_t i = 1; i < vec.size(); ++i) out << ", " << vec[i];
62 std::istream& operator >> (std::istream& in, std::string& str)
67 if (in.good() && (c = in.get()) == '"')
70 while (in.good() && (c = in.get()) != '"')
81 std::istream& operator >> (std::istream& in, std::vector<T>& vec)
86 if (in.good() && (c = in.get()) == '{')
90 while (in.good() && (c = in.get()) != '}')
92 if (c != ',') in.putback(c);
107 bool __equals(const T& actual, const T& expected)
109 return actual == expected;
112 bool __equals(double actual, double expected)
114 if (std::abs(actual - expected) < __EPSILON)
120 double minimum = std::min(expected * (1.0 - __EPSILON), expected * (1.0 + __EPSILON));
121 double maximum = std::max(expected * (1.0 - __EPSILON), expected * (1.0 + __EPSILON));
122 return actual > minimum && actual < maximum;
126 bool __equals(const std::vector<double>& actual, const std::vector<double>& expected)
128 if (actual.size() != expected.size())
131 for (size_t i = 0; i < actual.size(); ++i)
132 if (!__equals(actual[i], expected[i]))
139 int main(int argc, char* argv[])
141 bool __exit_on_fail = false;
145 if (1 < argc) __exit_on_fail = true;
147 std::ifstream __in("testcases.txt");
150 $RETURNTYPE$ __expected;
151 $METHODPARAMDECLARES$
152 __in >> __expected >> $METHODPARAMSTREAMIN$;
153 if (!__in.good()) break;
155 std::cout << "----------------------------------------" << std::endl
156 << "Test " << (__pass + __fail) << ": ";
162 $RETURNTYPE$ __actual = object.$METHODNAME$($METHODPARAMNAMES$);
164 double __t = __timer_stop();
166 if (__equals(__actual, __expected))
168 std::cout << "[PASS] in " << __t << " seconds." << std::endl;
173 std::cout << "[FAIL] in " << __t << " seconds." << std::endl
174 << "-> Input: " << $METHODPARAMSTREAMOUT$ << std::endl
175 << " Actual: " << __actual << std::endl
176 << " Expected: " << __expected << std::endl;
178 if (__exit_on_fail) exit(1);
182 std::cout << "========================================" << std::endl
183 << " Total Pass: " << __pass << std::endl
184 << " Total Fail: " << __fail << std::endl;
188 std::cout << std::endl << "Nice! "
189 << "Don't forget to compile remotely before submitting."