testing.hpp
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include <gtest/gtest.h>
8 #include <Eigen/Core>
9 
10 #define ASSERT_MATRICES_EQ_WITH_NAN(first, second) assertMatrixesEqualWithNan((first), #first, (second), #second, __LINE__)
11 static void assertMatrixesEqualWithNan(Eigen::Ref<const Eigen::MatrixXf> first, std::string firstName,
12  Eigen::Ref<const Eigen::MatrixXf> second, std::string secondName, int line) {
13  ASSERT_EQ(first.rows(), second.rows());
14  ASSERT_EQ(first.cols(), second.cols());
15 
16  bool matricesAreEqual = true;
17  for (Eigen::Index row = 0; row < first.rows() && matricesAreEqual; ++row) {
18  for (Eigen::Index col = 0; col < first.cols() && matricesAreEqual; ++col) {
19  bool ifRealThenValid = first.block<1, 1>(row, col).isApprox(second.block<1, 1>(row, col));
20  bool bothNaN = std::isnan(first(row, col)) && std::isnan(second(row, col));
21  if (ifRealThenValid || bothNaN) {
22  continue;
23  } else {
24  matricesAreEqual = false;
25  }
26  }
27  }
28 
29  Eigen::IOFormat compactFormat(2, 0, ",", "\n", "[", "]");
30  ASSERT_TRUE(matricesAreEqual) // NO LINT
31  << "L. " << std::to_string(line) << ": Matrices are not equal" // NO LINT
32  << "\n" // NO LINT
33  << firstName << "\n" // NO LINT
34  << first.format(compactFormat) << "\n" // NO LINT
35  << secondName << "\n" // NO LINT
36  << second.format(compactFormat) << "\n"; // NO LINT
37 }
Eigen::Array2i Index
Definition: TypeDefs.hpp:22
static void assertMatrixesEqualWithNan(Eigen::Ref< const Eigen::MatrixXf > first, std::string firstName, Eigen::Ref< const Eigen::MatrixXf > second, std::string secondName, int line)
Definition: testing.hpp:11


grid_map_core
Author(s): Péter Fankhauser
autogenerated on Wed Jul 5 2023 02:23:35