2 #include "$CLASSNAME$.cc"
15 const static double __EPSILON = 1e-9;
16 static double __time = 0.0;
18 static void __timer_start()
21 if (gettimeofday(&tv, NULL) == 0)
23 __time = double(tv.tv_sec) * 1000.0 + double(tv.tv_usec) * 0.001;
27 static double __timer_stop()
29 double start = __time;
31 return __time - start;
35 static void __eat_whitespace(std::istream& in)
37 while (in.good() && std::isspace(in.peek())) in.get();
41 std::ostream& operator << (std::ostream& out, const std::string& str)
43 out << '"' << str.c_str() << '"';
48 std::ostream& operator << (std::ostream& out, const std::vector<T>& vec)
54 for (size_t i = 1; i < vec.size(); ++i) out << ", " << vec[i];
60 std::istream& operator >> (std::istream& in, std::string& str)
65 if (in.good() && (c = in.get()) == '"')
68 while (in.good() && (c = in.get()) != '"')
79 std::istream& operator >> (std::istream& in, std::vector<T>& vec)
84 if (in.good() && (c = in.get()) == '{')
88 while (in.good() && (c = in.get()) != '}')
90 if (c != ',') in.putback(c);
105 bool __equals(const T& actual, const T& expected)
107 return actual == expected;
110 bool __equals(double actual, double expected)
112 if (std::abs(actual - expected) < __EPSILON)
118 double minimum = std::min(expected * (1.0 - __EPSILON), expected * (1.0 + __EPSILON));
119 double maximum = std::max(expected * (1.0 - __EPSILON), expected * (1.0 + __EPSILON));
120 return actual > minimum && actual < maximum;
124 bool __equals(const std::vector<double>& actual, const std::vector<double>& expected)
126 if (actual.size() != expected.size())
131 for (size_t i = 0; i < actual.size(); ++i)
133 if (!__equals(actual[i], expected[i]))
143 int main(int argc, char* argv[])
145 bool __abort_on_fail = false;
149 if (1 < argc) __abort_on_fail = true;
151 std::cout << "TAP version 13" << std::endl;
154 std::ifstream __in("testcases.txt");
157 int __testnum = __pass + __fail + 1;
159 $RETURNTYPE$ __expected;
160 $METHODPARAMDECLARES$
161 __in >> __expected >> $METHODPARAMSTREAMIN$;
162 if (!__in.good()) break;
164 std::cout << "# input for test " << __testnum << ": " << $METHODPARAMSTREAMOUT$ << std::endl;
169 $CLASSNAME$ __object;
170 $RETURNTYPE$ __actual = __object.$METHODNAME$($METHODPARAMNAMES$);
172 double __t = __timer_stop();
174 std::cout << "# test completed in " << __t << "ms" << std::endl;
177 if (__equals(__actual, __expected))
184 std::cout << "not ok";
188 std::cout << " " << __testnum << " - " << __actual << " must equal " << __expected << std::endl;
191 if (__abort_on_fail && 0 < __fail) std::abort();
194 std::cout << "1.." << (__pass + __fail) << std::endl
195 << "# passed: " << __pass << std::endl
196 << "# failed: " << __fail << std::endl;
200 std::cout << std::endl
201 << "# Nice! Don't forget to compile remotely before submitting." << std::endl;
207 // vim:ft=cpp:noet:ts=8