checks.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Pilz GmbH & Co. KG
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CHECKS_H
18 #define CHECKS_H
19 
20 #include <gtest/gtest.h>
22 
24 {
25 ::testing::AssertionResult isAtExpectedPosition(const robot_state::RobotState& expected,
26  const robot_state::RobotState& actual,
27  const double epsilon)
28 {
29  if (expected.getVariableCount() != actual.getVariableCount())
30  {
31  return ::testing::AssertionFailure() << "Both states have different number of Variables";
32  }
33 
34  for (size_t i = 0; i < actual.getVariableCount(); ++i)
35  {
36  // PLEASE NOTE: This comparision only works for reasonably
37  // values. That means: Values are not to large, values are
38  // reasonably close by each other.
39  if (std::fabs(expected.getVariablePosition(i) - actual.getVariablePosition(i)) > epsilon)
40  {
41  std::stringstream msg;
42  msg << expected.getVariableNames().at(i) << " position - expected: " << expected.getVariablePosition(i)
43  << " actual: " << actual.getVariablePosition(i);
44 
45  return ::testing::AssertionFailure() << msg.str();
46  }
47  }
48 
49  return ::testing::AssertionSuccess();
50 }
51 
52 } // namespace pilz_industrial_motion_testutils
53 
54 #endif // CENTERAUXILIARY_H
::testing::AssertionResult isAtExpectedPosition(const robot_state::RobotState &expected, const robot_state::RobotState &actual, const double epsilon)
Definition: checks.h:25


pilz_industrial_motion_testutils
Author(s):
autogenerated on Mon Feb 28 2022 23:13:36