Skip to content
Snippets Groups Projects
Commit c137c311 authored by Joan Vallvé Navarro's avatar Joan Vallvé Navarro
Browse files

gtest_yaml_conversions

parent d9d59b5a
No related branches found
No related tags found
1 merge request!278Resolve "Revisit demos (formerly called examples) and update them"
......@@ -190,6 +190,10 @@ target_link_libraries(gtest_odom_2D ${PROJECT_NAME})
wolf_add_gtest(gtest_processor_odom_3D gtest_processor_odom_3D.cpp)
target_link_libraries(gtest_processor_odom_3D ${PROJECT_NAME})
# yaml conversions
wolf_add_gtest(gtest_yaml_conversions gtest_yaml_conversions.cpp)
target_link_libraries(gtest_yaml_conversions ${PROJECT_NAME})
# ------- Now Core classes Serialization ----------
add_subdirectory(serialization)
......
......@@ -5,19 +5,23 @@
* \author: jsola
*/
#include "core/common/wolf.h"
#include "core/utils/utils_gtest.h"
#include "core/yaml/yaml_conversion.h"
#include <yaml-cpp/yaml.h>
#include <eigen3/Eigen/Dense>
#include <iostream>
//#include <fstream>
int main()
{
using namespace Eigen;
using namespace wolf;
using namespace Eigen;
TEST(MapYaml, save_2D)
{
MatrixXs M23(2,3);
MatrixXs M33(3,3);
M23 << 1, 2, 3, 4, 5, 6;
M33 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
std::cout << "\nTrying different yaml specs for matrix..." << std::endl;
......@@ -29,26 +33,37 @@ int main()
mat_23 = YAML::Load("[1, 2, 3, 4, 5, 6]"); // insensitive to spacing
mat_33 = YAML::Load("[1, 2, 3, 4, 5, 6, 7, 8, 9]"); // insensitive to spacing
MatrixXd Mx = mat_sized_23.as<MatrixXd>();
MatrixXs Mx = mat_sized_23.as<MatrixXs>();
std::cout << "Dyn-Dyn [[2,3] ,[1, 2, 3, 4, 5, 6] ] = \n" << Mx << std::endl;
ASSERT_MATRIX_APPROX(Mx, M23, 1e-12);
Matrix<double, 2, Dynamic> M2D = mat_sized_23.as<Matrix<double, 2, Dynamic>>();
Matrix<Scalar, 2, Dynamic> M2D = mat_sized_23.as<Matrix<Scalar, 2, Dynamic>>();
std::cout << "2-Dyn [[2,3] ,[1, 2, 3, 4, 5, 6] ] = \n" << M2D << std::endl;
ASSERT_MATRIX_APPROX(M2D, M23, 1e-12);
Matrix<double, Dynamic, 3> MD3 = mat_sized_23.as<Matrix<double, Dynamic, 3>>();
Matrix<Scalar, Dynamic, 3> MD3 = mat_sized_23.as<Matrix<Scalar, Dynamic, 3>>();
std::cout << "Dyn-3 [[2,3] ,[1, 2, 3, 4, 5, 6] ] = \n" << MD3 << std::endl;
ASSERT_MATRIX_APPROX(MD3, M23, 1e-12);
Matrix3d M3 = mat_sized_33.as<Matrix3d>();
Matrix3s M3 = mat_sized_33.as<Matrix3s>();
std::cout << "3-3 [[3,3] ,[1, 2, 3, 4, 5, 6, 7, 8, 9] ] = \n" << M3 << std::endl;
ASSERT_MATRIX_APPROX(M3, M33, 1e-12);
M2D = mat_23.as<Matrix<double, 2, Dynamic>>();
M2D = mat_23.as<Matrix<Scalar, 2, Dynamic>>();
std::cout << "2-Dyn [1, 2, 3, 4, 5, 6] = \n" << M2D << std::endl;
ASSERT_MATRIX_APPROX(M2D, M23, 1e-12);
MD3 = mat_23.as<Matrix<double, Dynamic, 3>>();
MD3 = mat_23.as<Matrix<Scalar, Dynamic, 3>>();
std::cout << "Dyn-3 [1, 2, 3, 4, 5, 6] = \n" << MD3 << std::endl;
ASSERT_MATRIX_APPROX(MD3, M23, 1e-12);
M3 = mat_33.as<Matrix3d>();
M3 = mat_33.as<Matrix3s>();
std::cout << "3-3 [1, 2, 3, 4, 5, 6, 7, 8, 9] = \n" << M3 << std::endl;
ASSERT_MATRIX_APPROX(M3, M33, 1e-12);
}
return 0;
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment