Go to the documentation of this file.    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";
 
   41     std::cerr << 
"failed!" << std::endl << std::endl;
 
   45   std::cerr << 
"passed." << std::endl << std::endl;
 
   49 #define SOPHUS_STRINGIFY(x) #x 
   53 #define SOPHUS_TEST(passed, condition, ...)                                    \ 
   56       std::string msg = Sophus::details::FormatString(                         \ 
   57           "condition ``%`` is false\n", SOPHUS_STRINGIFY(condition));          \ 
   58       msg += Sophus::details::FormatString(__VA_ARGS__);                       \ 
   59       Sophus::details::testFailed(passed, SOPHUS_FUNCTION, __FILE__, __LINE__, \ 
   66 #define SOPHUS_TEST_EQUAL(passed, left, right, ...)                            \ 
   68     if (left != right) {                                                       \ 
   69       std::string msg = Sophus::details::FormatString(                         \ 
   70           "% (=%) is not equal to % (=%)\n", SOPHUS_STRINGIFY(left),           \ 
   71           Sophus::details::pretty(left), SOPHUS_STRINGIFY(right),              \ 
   72           Sophus::details::pretty(right));                                     \ 
   73       msg += Sophus::details::FormatString(__VA_ARGS__);                       \ 
   74       Sophus::details::testFailed(passed, SOPHUS_FUNCTION, __FILE__, __LINE__, \ 
   81 #define SOPHUS_TEST_NEQ(passed, left, right, ...)                              \ 
   83     if (left == right) {                                                       \ 
   84       std::string msg = Sophus::details::FormatString(                         \ 
   85           "% (=%) shoudl not be equal to % (=%)\n", SOPHUS_STRINGIFY(left),    \ 
   86           Sophus::details::pretty(left), SOPHUS_STRINGIFY(right),              \ 
   87           Sophus::details::pretty(right));                                     \ 
   88       msg += Sophus::details::FormatString(__VA_ARGS__);                       \ 
   89       Sophus::details::testFailed(passed, SOPHUS_FUNCTION, __FILE__, __LINE__, \ 
   96 #define SOPHUS_TEST_APPROX(passed, left, right, thr, ...)                      \ 
   98     auto nrm = Sophus::maxMetric((left), (right));                             \ 
   99     if (!(nrm < (thr))) {                                                      \ 
  100       std::string msg = Sophus::details::FormatString(                         \ 
  101           "% (=%) is not approx % (=%); % is %; nrm is %\n",                   \ 
  102           SOPHUS_STRINGIFY(left), Sophus::details::pretty(left),               \ 
  103           SOPHUS_STRINGIFY(right), Sophus::details::pretty(right),             \ 
  104           SOPHUS_STRINGIFY(thr), Sophus::details::pretty(thr), nrm);           \ 
  105       msg += Sophus::details::FormatString(__VA_ARGS__);                       \ 
  106       Sophus::details::testFailed(passed, SOPHUS_FUNCTION, __FILE__, __LINE__, \ 
  113 #define SOPHUS_TEST_NOT_APPROX(passed, left, right, thr, ...)                  \ 
  115     auto nrm = Sophus::maxMetric((left), (right));                             \ 
  117       std::string msg = Sophus::details::FormatString(                         \ 
  118           "% (=%) is approx % (=%), but it should not!\n % is %; nrm is %\n",  \ 
  119           SOPHUS_STRINGIFY(left), Sophus::details::pretty(left),               \ 
  120           SOPHUS_STRINGIFY(right), Sophus::details::pretty(right),             \ 
  121           SOPHUS_STRINGIFY(thr), Sophus::details::pretty(thr), nrm);           \ 
  122       msg += Sophus::details::FormatString(__VA_ARGS__);                       \ 
  123       Sophus::details::testFailed(passed, SOPHUS_FUNCTION, __FILE__, __LINE__, \ 
  128 #endif  // SOPUHS_TESTS_MACROS_HPP 
 
void testFailed(bool &passed, char const *func, char const *file, int line, std::string const &msg)
Eigen::Matrix< Scalar, M, N > Matrix
void processTestResult(bool passed)
static std::string impl(Matrix< Scalar, M, N > const &v)
static std::string impl(Scalar s)
std::string pretty(T const &v)
std::string FormatString(char const *text, Args &&... args)
sophus
Author(s): Hauke Strasdat
autogenerated on Wed Mar 2 2022 01:01:48