eigen_test_utils.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2022, Bielefeld University
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Bielefeld University nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Robert Haschke */
36 
37 #include <gtest/gtest.h>
38 #include <sstream>
39 #include <Eigen/Geometry>
40 
42 template <typename _Scalar, int _Dim, int _Mode, int _Options>
43 std::ostream& operator<<(std::ostream& s, const Eigen::Transform<_Scalar, _Dim, _Mode, _Options>& t)
44 {
45  return s << "p=[" << t.translation().transpose() << "] q=[" << Eigen::Quaterniond(t.linear()).coeffs().transpose()
46  << "]";
47 }
48 
50 template <typename T1, typename T2>
51 struct IsApprox
52 {
53  double prec_;
55  {
56  }
57 
58  ::testing::AssertionResult operator()(const char* expr1, const char* expr2, T1 val1, T2 val2)
59  {
60  if (val1.isApprox(val2, prec_))
61  return ::testing::AssertionSuccess();
62 
63  std::stringstream msg;
64  msg << "Expected equality of these values (up to precision " << prec_ << "):" << std::fixed
65  << std::setprecision(1 - std::log10(prec_)) // limit to precision
66  << "\n " << expr1 << "\n Which is: " << val1 // first
67  << "\n " << expr2 << "\n Which is: " << val2; // second
68  return ::testing::AssertionFailure() << msg.str();
69  }
70 };
71 
72 #define EXPECT_EIGEN_EQ(val1, val2) \
73  EXPECT_PRED_FORMAT2((IsApprox<decltype(val1), decltype(val2)>( \
74  Eigen::NumTraits<typename std::decay<decltype(val1)>::type::Scalar>::dummy_precision())), \
75  val1, val2)
76 #define EXPECT_EIGEN_NEAR(val1, val2, prec_) \
77  EXPECT_PRED_FORMAT2((IsApprox<decltype(val1), decltype(val2)>(prec_)), val1, val2)
IsApprox::prec_
double prec_
Definition: eigen_test_utils.h:53
s
XmlRpcServer s
operator<<
std::ostream & operator<<(std::ostream &s, const Eigen::Transform< _Scalar, _Dim, _Mode, _Options > &t)
Definition: eigen_test_utils.h:43
IsApprox
Definition: eigen_test_utils.h:51
IsApprox::IsApprox
IsApprox(double prec_)
Definition: eigen_test_utils.h:54
IsApprox::operator()
::testing::AssertionResult operator()(const char *expr1, const char *expr2, T1 val1, T2 val2)
Definition: eigen_test_utils.h:58
t
geometry_msgs::TransformStamped t


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Tue Dec 24 2024 03:27:14