1 #ifndef SOPUHS_TESTS_MACROS_HPP 2 #define SOPUHS_TESTS_MACROS_HPP 9 template <
class Scalar>
15 template <
class Scalar,
int M,
int N>
28 template <
class... Args>
29 void testFailed(
bool& passed,
char const* func,
char const* file,
int line,
30 std::string
const& msg) {
31 std::cerr <<
FormatString(
"Test failed in function %, file %, line %\n", func,
33 std::cerr << msg <<
"\n\n";
40 std::cerr <<
"failed!" << std::endl << std::endl;
43 std::cerr <<
"passed." << std::endl << std::endl;
47 #define SOPHUS_STRINGIFY(x) #x 51 #define SOPHUS_TEST(passed, condition, ...) \ 54 std::string msg = Sophus::details::FormatString( \ 55 "condition ``%`` is false\n", SOPHUS_STRINGIFY(condition)); \ 56 msg += Sophus::details::FormatString(__VA_ARGS__); \ 57 Sophus::details::testFailed(passed, SOPHUS_FUNCTION, __FILE__, __LINE__, \ 64 #define SOPHUS_TEST_EQUAL(passed, left, right, ...) \ 66 if (left != right) { \ 67 std::string msg = Sophus::details::FormatString( \ 68 "% (=%) is not equal to % (=%)\n", SOPHUS_STRINGIFY(left), \ 69 Sophus::details::pretty(left), SOPHUS_STRINGIFY(right), \ 70 Sophus::details::pretty(right)); \ 71 msg += Sophus::details::FormatString(__VA_ARGS__); \ 72 Sophus::details::testFailed(passed, SOPHUS_FUNCTION, __FILE__, __LINE__, \ 79 #define SOPHUS_TEST_NEQ(passed, left, right, ...) \ 81 if (left == right) { \ 82 std::string msg = Sophus::details::FormatString( \ 83 "% (=%) shoudl not be equal to % (=%)\n", SOPHUS_STRINGIFY(left), \ 84 Sophus::details::pretty(left), SOPHUS_STRINGIFY(right), \ 85 Sophus::details::pretty(right)); \ 86 msg += Sophus::details::FormatString(__VA_ARGS__); \ 87 Sophus::details::testFailed(passed, SOPHUS_FUNCTION, __FILE__, __LINE__, \ 94 #define SOPHUS_TEST_APPROX(passed, left, right, thr, ...) \ 96 auto nrm = Sophus::metric((left), (right)); \ 97 if (!(nrm < (thr))) { \ 98 std::string msg = Sophus::details::FormatString( \ 99 "% (=%) is not approx % (=%); % is % \n", SOPHUS_STRINGIFY(left), \ 100 Sophus::details::pretty(left), SOPHUS_STRINGIFY(right), \ 101 Sophus::details::pretty(right), SOPHUS_STRINGIFY(thr), \ 102 Sophus::details::pretty(thr)); \ 103 msg += Sophus::details::FormatString(__VA_ARGS__); \ 104 Sophus::details::testFailed(passed, SOPHUS_FUNCTION, __FILE__, __LINE__, \ 109 #endif // SOPUHS_TESTS_MACROS_HPP void testFailed(bool &passed, char const *func, char const *file, int line, std::string const &msg)
std::string FormatString(char const *text, Args &&... args)
std::string pretty(T const &v)
Eigen::Matrix< Scalar, M, N > Matrix
static std::string impl(Scalar s)
void processTestResult(bool passed)
static std::string impl(Matrix< Scalar, M, N > const &v)