MRPT  1.9.9
CMatrixDynamic_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
12 #include <Eigen/Dense>
13 
14 TEST(CMatrixDynamic, GetSetEigen)
15 {
16  {
18  auto em = M.asEigen();
19  em.setIdentity();
20  for (int i = 0; i < 3; i++) EXPECT_EQ(M(i, i), 1.0);
21  }
22  {
24  auto em = M.asEigen();
25  for (int i = 0; i < 3; i++)
26  for (int j = 0; j < 3; j++)
27  {
28  const auto n = ((i + 1) * 3) + (j * 1001);
29  em(i, j) = n;
30  EXPECT_NEAR(M(i, j), em(i, j), 1e-9)
31  << "(i,j)=(" << i << "," << j << ")\n";
32  }
33  }
34 }
35 TEST(CMatrixDynamic, asString)
36 {
38  M.setIdentity();
39  EXPECT_EQ(std::string("1 0\n0 1"), M.asString());
40 }
41 
42 TEST(CMatrixDynamic, CtorFromArray)
43 {
44  const double dat_R[] = {1., 2., 3., 4., 5., 6., 7., 8., 9.};
45  mrpt::math::CMatrixDouble R(3, 3, dat_R);
46  for (int r = 0; r < 3; r++)
47  {
48  for (int c = 0; c < 3; c++)
49  {
50  EXPECT_EQ(dat_R[c + r * 3], R(r, c))
51  << "(r,c)=(" << r << "," << c << ")\n";
52  }
53  }
54 }
55 
56 // Added to run with valgrind to error checking.
57 TEST(CMatrixDynamic, Resizes)
58 {
60  {
61  CMatrixDouble M(0, 0);
62  M.resize(0, 0);
63  M.resize(1, 1);
64  M.resize(10, 10);
65  M.resize(15, 10);
66  M.resize(15, 12);
67  M.resize(5, 12);
68  M.resize(3, 2);
69  }
70  {
71  CMatrixDouble M(40, 50);
72  M.resize(3, 3);
73  }
74 }
static CMatrixDynamic< T > Identity()
Definition: MatrixBase.h:64
GLenum GLsizei n
Definition: glext.h:5136
const GLubyte * c
Definition: glext.h:6406
GLsizei const GLchar ** string
Definition: glext.h:4116
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
const float R
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
TEST(CMatrixDynamic, GetSetEigen)
CMatrixDynamic< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019