test_common.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <iostream>
  2. #include <sophus/test_macros.hpp>
  3. #include <sophus/formatstring.hpp>
  4. namespace Sophus {
  5. namespace {
  6. bool testFormatString() {
  7. bool passed = true;
  8. SOPHUS_TEST_EQUAL(passed, details::FormatString(), std::string());
  9. std::string test_str = "Hello World!";
  10. SOPHUS_TEST_EQUAL(passed, details::FormatString(test_str.c_str()), test_str);
  11. SOPHUS_TEST_EQUAL(passed, details::FormatString("Number: %", 5),
  12. std::string("Number: 5"));
  13. SOPHUS_TEST_EQUAL(passed,
  14. details::FormatString("Real: % msg %", 1.5, test_str),
  15. std::string("Real: 1.5 msg Hello World!"));
  16. SOPHUS_TEST_EQUAL(passed,
  17. details::FormatString(
  18. "vec: %", Eigen::Vector3f(0.f, 1.f, 1.5f).transpose()),
  19. std::string("vec: 0 1 1.5"));
  20. SOPHUS_TEST_EQUAL(
  21. passed, details::FormatString("Number: %", 1, 2),
  22. std::string("Number: 1\nFormat-Warning: There are 1 args unused."));
  23. return passed;
  24. }
  25. bool testSmokeDetails() {
  26. bool passed = true;
  27. std::cout << details::pretty(4.2) << std::endl;
  28. std::cout << details::pretty(Vector2f(1, 2)) << std::endl;
  29. bool dummy = true;
  30. details::testFailed(dummy, "dummyFunc", "dummyFile", 99,
  31. "This is just a pratice alarm!");
  32. SOPHUS_TEST_EQUAL(passed, dummy, false);
  33. double val = transpose(42.0);
  34. SOPHUS_TEST_EQUAL(passed, val, 42.0);
  35. Matrix<float, 1, 2> row = transpose(Vector2f(1, 7));
  36. Matrix<float, 1, 2> expected_row(1, 7);
  37. SOPHUS_TEST_EQUAL(passed, row, expected_row);
  38. optional<int> opt(nullopt);
  39. SOPHUS_TEST(passed, !opt);
  40. return passed;
  41. }
  42. void runAll() {
  43. std::cerr << "Common tests:" << std::endl;
  44. bool passed = testFormatString();
  45. passed &= testSmokeDetails();
  46. processTestResult(passed);
  47. }
  48. } // namespace
  49. } // namespace Sophus
  50. int main() { Sophus::runAll(); }