test_common.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <sophus/test_macros.hpp>
4 
5 namespace Sophus {
6 
7 namespace {
8 
9 bool testFormatString() {
10  bool passed = true;
11  SOPHUS_TEST_EQUAL(passed, details::FormatString(), std::string());
12  std::string test_str = "Hello World!";
13  SOPHUS_TEST_EQUAL(passed, details::FormatString(test_str.c_str()), test_str);
14  SOPHUS_TEST_EQUAL(passed, details::FormatString("Number: %", 5),
15  std::string("Number: 5"));
16  SOPHUS_TEST_EQUAL(passed,
17  details::FormatString("Real: % msg %", 1.5, test_str),
18  std::string("Real: 1.5 msg Hello World!"));
19  SOPHUS_TEST_EQUAL(passed,
21  "vec: %", Eigen::Vector3f(0.f, 1.f, 1.5f).transpose()),
22  std::string("vec: 0 1 1.5"));
24  passed, details::FormatString("Number: %", 1, 2),
25  std::string("Number: 1\nFormat-Warning: There are 1 args unused."));
26  return passed;
27 }
28 
29 bool testSmokeDetails() {
30  bool passed = true;
31  std::cout << details::pretty(4.2) << std::endl;
32  std::cout << details::pretty(Vector2f(1, 2)) << std::endl;
33  bool dummy = true;
34  details::testFailed(dummy, "dummyFunc", "dummyFile", 99,
35  "This is just a pratice alarm!");
36  SOPHUS_TEST_EQUAL(passed, dummy, false);
37 
38  double val = transpose(42.0);
39  SOPHUS_TEST_EQUAL(passed, val, 42.0);
40  Matrix<float, 1, 2> row = transpose(Vector2f(1, 7));
41  Matrix<float, 1, 2> expected_row(1, 7);
42  SOPHUS_TEST_EQUAL(passed, row, expected_row);
43 
44  optional<int> opt(nullopt);
45  SOPHUS_TEST(passed, !opt);
46 
47  return passed;
48 }
49 
50 void runAll() {
51  std::cerr << "Common tests:" << std::endl;
52  bool passed = testFormatString();
53  passed &= testSmokeDetails();
54  processTestResult(passed);
55 }
56 
57 } // namespace
58 } // namespace Sophus
59 
60 int main() { Sophus::runAll(); }
test_macros.hpp
main
int main()
Definition: test_common.cpp:60
Sophus::details::testFailed
void testFailed(bool &passed, char const *func, char const *file, int line, std::string const &msg)
Definition: test_macros.hpp:29
Sophus::Vector2f
Vector2< float > Vector2f
Definition: types.hpp:17
SOPHUS_TEST
#define SOPHUS_TEST(passed, condition,...)
Definition: test_macros.hpp:53
Sophus
Definition: average.hpp:17
Sophus::processTestResult
void processTestResult(bool passed)
Definition: test_macros.hpp:38
Sophus::transpose
auto transpose(T const &p) -> decltype(details::Transpose< T >::impl(T()))
Definition: types.hpp:195
Sophus::nullopt
constexpr nullopt_t nullopt
Definition: common.hpp:177
Sophus::Vector3f
Vector3< float > Vector3f
Definition: types.hpp:22
SOPHUS_TEST_EQUAL
#define SOPHUS_TEST_EQUAL(passed, left, right,...)
Definition: test_macros.hpp:66
Sophus::details::pretty
std::string pretty(T const &v)
Definition: test_macros.hpp:24
Sophus::details::FormatString
std::string FormatString(char const *text, Args &&... args)
Definition: common.hpp:91


sophus
Author(s): Hauke Strasdat
autogenerated on Wed Mar 2 2022 01:01:48