2 #include "$CLASSNAME$.cc"
8 static bool __exit_on_fail = false;
10 static int __fail = 0;
11 static double __time = 0.0;
13 static void __timer_start()
16 if (gettimeofday(&tv, NULL) == 0)
18 __time = (double)tv.tv_sec + (double)tv.tv_usec * 0.000001;
22 static double __timer_stop()
24 double start = __time;
26 return __time - start;
30 std::string __encode(const T& in)
37 std::string __encode(const std::string& in)
40 s << '"' << in << '"';
45 std::string __join(const std::vector<T>& in, const std::string& glue)
47 if (in.size() == 0) return "";
50 for (size_t i = 1; i < in.size(); ++i) s << glue << __encode(in[i]);
55 std::string __encode(const std::vector<T>& in)
58 s << "{ " << __join(in, ", ") << " }";
62 void __do_test(const std::string& expected, $METHODPARAMS$)
64 static int testNum = 0;
65 std::cout << "----------------------------------------" << std::endl
66 << "Test " << testNum++ << ": ";
71 $RETURNTYPE$ ret = object.$METHODNAME$($METHODPARAMNAMES$);
73 double t = __timer_stop();
75 std::string actual = __encode(ret);
76 if (actual == expected)
78 std::cout << "[PASS] in " << t << " seconds." << std::endl;
83 std::cout << "[FAIL] in " << t << " seconds." << std::endl
84 << " Actual: " << actual << std::endl
85 << " Expected: " << expected << std::endl;
87 if (__exit_on_fail) exit(1);
91 int main(int argc, char* argv[])
93 if (1 < argc) __exit_on_fail = true;
96 std::cout << "========================================" << std::endl
97 << " Total Pass: " << __pass << std::endl
98 << " Total Fail: " << __fail << std::endl;