MRPT  1.9.9
CMatrixFixed_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-2020, 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>
11 #include <mrpt/math/CMatrixFixed.h>
12 #include <Eigen/Dense>
13 
14 TEST(CMatrixFixed, CtorUninit)
15 {
17  // do nothing, just test that the ctor above compiles
18  (void)M(0, 0);
19 }
20 
21 TEST(CMatrixFixed, CtorAllZeros)
22 {
24  for (int i = 0; i < 2; i++)
25  for (int j = 0; j < 2; j++) EXPECT_EQ(M(i, j), .0);
26 }
27 
28 TEST(CMatrixFixed, Identity)
29 {
31  M.setIdentity();
32  for (int i = 0; i < 3; i++)
33  {
34  EXPECT_EQ(M(i, i), 1.0);
35  // Also test access via data():
36  EXPECT_EQ(M(i, i), M.data()[i + i * 3]);
37  }
38 
39  // Check that access via data() is what we expect:
40  for (int r = 0; r < 3; r++)
41  for (int c = 0; c < 3; c++) EXPECT_EQ(&M(r, c), &M.data()[c + r * 3]);
42 }
43 
44 TEST(CMatrixFixed, asString)
45 {
47  M.setIdentity();
48  EXPECT_EQ(std::string("1 0\n0 1"), M.asString());
49 }
50 
51 TEST(CMatrixFixed, GetSetEigen)
52 {
53  {
55  auto em = M.asEigen();
56  em.setIdentity();
57  for (int i = 0; i < 3; i++) EXPECT_EQ(M(i, i), 1.0);
58  }
59  {
61  auto em = M.asEigen();
62  for (int i = 0; i < 3; i++)
63  for (int j = 0; j < 3; j++)
64  {
65  const auto n = ((i + 1) * 3) + (j * 1001);
66  em(i, j) = n;
67  EXPECT_NEAR(M(i, j), em(i, j), 1e-9)
68  << "(i,j)=(" << i << "," << j << ")\n";
69  }
70  }
71 }
A compile-time fixed-size numeric matrix container.
Definition: CMatrixFixed.h:33
std::string asString() const
Returns a string representation of the vector/matrix, using Eigen&#39;s default settings.
const T * data() const
Return raw pointer to row-major data buffer.
Definition: CMatrixFixed.h:278
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
EIGEN_MAP asEigen()
Get as an Eigen-compatible Eigen::Map object.
Definition: CMatrixFixed.h:251
EXPECT_NEAR(out.cam_params.rightCameraPose.x, 0.1194, 0.005)
TEST(CMatrixFixed, CtorUninit)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020