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>
13 #include <Eigen/Dense>
14 
15 TEST(CMatrixDynamic, GetSetEigen)
16 {
17  {
19  auto em = M.asEigen();
20  em.setIdentity();
21  for (int i = 0; i < 3; i++) EXPECT_EQ(M(i, i), 1.0);
22  }
23  {
25  auto em = M.asEigen();
26  for (int i = 0; i < 3; i++)
27  for (int j = 0; j < 3; j++)
28  {
29  const auto n = ((i + 1) * 3) + (j * 1001);
30  em(i, j) = n;
31  EXPECT_NEAR(M(i, j), em(i, j), 1e-9)
32  << "(i,j)=(" << i << "," << j << ")\n";
33  }
34  }
35 }
36 TEST(CMatrixDynamic, asString)
37 {
39  M.setIdentity();
40  EXPECT_EQ(std::string("1 0\n0 1"), M.asString());
41 }
42 
43 TEST(CMatrixDynamic, CtorFromArray)
44 {
45  const double dat_R[] = {1., 2., 3., 4., 5., 6., 7., 8., 9.};
46  mrpt::math::CMatrixDouble R(3, 3, dat_R);
47  for (int r = 0; r < 3; r++)
48  {
49  for (int c = 0; c < 3; c++)
50  {
51  EXPECT_EQ(dat_R[c + r * 3], R(r, c))
52  << "(r,c)=(" << r << "," << c << ")\n";
53  }
54  }
55 }
56 
57 // Added to run with valgrind to error checking.
58 TEST(CMatrixDynamic, Resizes)
59 {
61  {
62  CMatrixDouble M(0, 0);
63  M.resize(0, 0);
64  M.resize(1, 1);
65  M.resize(10, 10);
66  M.resize(15, 10);
67  M.resize(15, 12);
68  M.resize(5, 12);
69  M.resize(3, 2);
70  }
71  {
72  CMatrixDouble M(40, 50);
73  M.resize(3, 3);
74  }
75 }
76 
77 TEST(CVectorDynamic, segment)
78 {
81  v.resize(10);
82  for (int i = 0; i < v.size(); i++) v[i] = i;
83 
84  for (int start = 0; start < 8; start++)
85  for (int len = 1; len < v.size() - start; len++)
86  {
87  const auto s = v.segmentCopy(start, len);
88  for (int i = 0; i < s.size(); i++) EXPECT_EQ(v[i + start], s[i]);
89  }
90 }
static CMatrixDynamic< T > Identity()
Definition: MatrixBase.h:64
GLenum GLsizei n
Definition: glext.h:5136
GLdouble s
Definition: glext.h:3682
GLenum GLsizei len
Definition: glext.h:4756
CVectorDynamic< double > CVectorDouble
const GLubyte * c
Definition: glext.h:6406
GLsizei const GLchar ** string
Definition: glext.h:4116
const GLdouble * v
Definition: glext.h:3684
GLdouble GLdouble GLdouble r
Definition: glext.h:3711
const float R
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
EXPECT_NEAR(out.cam_params.rightCameraPose.x, 0.1194, 0.005)
GLuint start
Definition: glext.h:3532
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: 479715d5b Tue Nov 12 07:26:21 2019 +0100 at mar nov 12 07:30:12 CET 2019