test_matrix_parser.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <ros/ros.h>
4 
5 void assertMatrixEqual(const Eigen::MatrixXd &m1, const Eigen::MatrixXd &m2)
6 {
7  ASSERT_EQ(m1.cols(), m2.cols());
8  ASSERT_EQ(m1.rows(), m2.rows());
9 
10  for (unsigned int i = 0; i < m1.rows(); i++)
11  {
12  for (unsigned int j = 0; j < m1.cols(); j++)
13  {
14  ASSERT_NEAR(m1(i, j), m2(i, j), DBL_EPSILON);
15  }
16  }
17 }
18 
19 TEST(TestMatrixParser, TestParseSquareMatrix)
20 {
21  ros::NodeHandle nh("~");
22  Eigen::MatrixXd square_m;
23  Eigen::Matrix3d expected_m;
24 
25  expected_m << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0;
26 
28  square_m, "square_matrix", nh));
29 
30  ASSERT_EQ(square_m.cols(), square_m.rows());
31  ASSERT_EQ(square_m.rows(), 3);
32  assertMatrixEqual(square_m, expected_m);
33 }
34 
35 TEST(TestMatrixParser, TestParseRectangularMatrix)
36 {
37  ros::NodeHandle nh("~");
38  Eigen::MatrixXd rectangular_m;
39  Eigen::Matrix<double, 3, 2> expected_m;
40 
41  expected_m << 1, 2, 3, 4, 5, 6;
42 
44  rectangular_m, "rectangular_matrix", nh));
45 
46  ASSERT_EQ(rectangular_m.rows(), 3);
47  ASSERT_EQ(rectangular_m.cols(), 2);
48  assertMatrixEqual(rectangular_m, expected_m);
49 }
50 
51 TEST(TestMatrixParser, TestVectorParse)
52 {
53  ros::NodeHandle nh("~");
54  Eigen::MatrixXd vector_m;
55  Eigen::Vector3d expected_m;
56 
57  expected_m << 1, 2, 3;
58 
60  vector_m, "vector", nh));
61 
62  ASSERT_EQ(vector_m.rows(), 3);
63  ASSERT_EQ(vector_m.cols(), 1);
64  assertMatrixEqual(vector_m, expected_m);
65 }
66 
67 TEST(TestMatrixParser, TestFailParse)
68 {
69  ros::NodeHandle nh("~");
70  Eigen::MatrixXd fail_m;
71 
73  fail_m, "non_existant_ns", nh));
74 }
75 
76 TEST(TestMatrixParser, TestComputeSkew) { ros::NodeHandle nh("~"); }
77 
78 int main(int argc, char **argv)
79 {
80  ros::init(argc, argv, "my_test_node");
81  ros::start();
82  ::testing::InitGoogleTest(&argc, argv);
83  return RUN_ALL_TESTS();
84 }
ROSCPP_DECL void start()
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
void assertMatrixEqual(const Eigen::MatrixXd &m1, const Eigen::MatrixXd &m2)
static bool parseMatrixData(Eigen::MatrixXd &M, const std::string param_name, const ros::NodeHandle &n)
TEST(TestMatrixParser, TestParseSquareMatrix)


generic_control_toolbox
Author(s): diogo
autogenerated on Wed Apr 28 2021 03:01:15