iDynTree/TestUtils.h file

Namespaces

namespace iDynTree

Classes

struct iDynTree::TestMatrixMismatch

Functions

void assertStringAreEqual(const std::string& val1, const std::string& val2, double tol = DEFAULT_TOL, std::string file = "", int line = -1)
void assertDoubleAreEqual(const double& val1, const double& val2, double tol = DEFAULT_TOL, std::string file = "", int line = -1)
void assertTransformsAreEqual(const Transform& trans1, const Transform& trans2, double tol = DEFAULT_TOL, std::string file = "", int line = -1)
Assert that two transforms are equal, and exit with EXIT_FAILURE if they are not.
void assertSpatialMotionAreEqual(const SpatialMotionVector& t1, const SpatialMotionVector& t2, double tol = DEFAULT_TOL, std::string file = "", int line = -1)
Assert that two spatial motion vectors are equal, and exit with EXIT_FAILURE if they are not.
void assertSpatialForceAreEqual(const SpatialForceVector& f1, const SpatialForceVector& f2, double tol = DEFAULT_TOL, std::string file = "", int line = -1)
Assert that two spatial force vectors are equal, and exit with EXIT_FAILURE if they are not.
void assertTrue(bool prop, std::string file = "", int line = -1)
auto getRandomBool() -> bool
Get random bool.
auto getRandomDouble(double min = 0.0, double max = 1.0) -> double
Get a random double between min and max .
auto getRandomInteger(int min, int max) -> int
Get a random integer between min and max (included).
template<typename VectorType>
void getRandomVector(VectorType& vec, double min = 0.0, double max = 1.0)
Fill a vector with random double.
template<typename MatrixType>
void getRandomMatrix(MatrixType& mat)
Fill a matrix of random doubles.
auto getRandomPosition() -> Position
Get a random position.
auto getRandomRotation() -> Rotation
Get a random rotation.
auto getRandomTransform() -> Transform
Get a random transform.
auto getRandomAxis() -> Axis
Get a random axis.
auto getRandomInertia() -> SpatialInertia
Get a random (but physically consistent) inertia.
auto getRandomTwist() -> SpatialMotionVector
Get a random twist-like 6D vector.
auto getRandomWrench() -> SpatialForceVector
Get a random wrench-like 6D object.
template<typename VectorType>
void printVector(std::string, const VectorType& vec)
Helper for printing vectors.
template<typename VectorType1, typename VectorType2>
void printVectorDifference(std::string name, const VectorType1& vec1, const VectorType2& vec2)
Helper for printing difference of two vectors.
void printVectorWrongElements(std::string name, std::vector<bool>& correctElems)
Helper for printing the patter of wrong elements in between two vectors.
void printMatrixWrongElements(std::string name, std::vector<std::vector<TestMatrixMismatch>>& correctElems)
Helper for printing the patter of wrong elements in between two matrix.
template<typename MatrixType1, typename MatrixType2>
void printMatrixPercentageError(const MatrixType1& mat1, const MatrixType2& mat2)
Helper for printing the patter of wrong elements in between two matrix.
template<typename VectorType1, typename VectorType2>
void assertVectorAreEqual(const VectorType1& vec1, const VectorType2& vec2, double tol, std::string file, int line)
Assert that two vectors are equal, and exit with EXIT_FAILURE if they are not.
template<typename VectorType1, typename VectorType2>
void assertVectorAreEqualWithRelativeTol(const VectorType1& vec1, const VectorType2& vec2, double relativeTol, double minAbsoluteTol, std::string file, int line)
Assert that two vectors are equal, and exit with EXIT_FAILURE if they are not.
template<typename MatrixType1, typename MatrixType2>
void assertMatrixAreEqual(const MatrixType1& mat1, const MatrixType2& mat2, double tol, std::string file, int line)
Assert that two matrices are equal, and exit with EXIT_FAILURE if they are not.

Defines

#define ASSERT_IS_TRUE(prop)
#define ASSERT_IS_FALSE(prop)
#define ASSERT_EQUAL_STRING(val1, val2)
#define ASSERT_EQUAL_DOUBLE(val1, val2)
#define ASSERT_EQUAL_DOUBLE_TOL(val1, val2, tol)
#define ASSERT_EQUAL_VECTOR(val1, val2)
#define ASSERT_EQUAL_VECTOR_TOL(val1, val2, tol)
#define ASSERT_EQUAL_VECTOR_REL_TOL(val1, val2, relTol, minAbsTol)
#define ASSERT_EQUAL_SPATIAL_MOTION(val1, val2)
#define ASSERT_EQUAL_SPATIAL_FORCE(val1, val2)
#define ASSERT_EQUAL_SPATIAL_FORCE_TOL(val1, val2, tol)
#define ASSERT_EQUAL_MATRIX(val1, val2)
#define ASSERT_EQUAL_MATRIX_TOL(val1, val2, tol)
#define ASSERT_EQUAL_TRANSFORM(val1, val2)
#define ASSERT_EQUAL_TRANSFORM_TOL(val1, val2, tol)
#define IDYNTREE_MATCH_CHARACTER

Function documentation

int getRandomInteger(int min, int max)

Get a random integer between min and max (included).

For example a dice could be simulated with getRandomInteger(1,6);

template<typename VectorType1, typename VectorType2>
void assertVectorAreEqualWithRelativeTol(const VectorType1& vec1, const VectorType2& vec2, double relativeTol, double minAbsoluteTol, std::string file, int line)

Assert that two vectors are equal, and exit with EXIT_FAILURE if they are not.

The tolerance passed in this function is a relative tolerance on the max element of the comparison, i.e. absoluteTol = max(relativeTol*max(val1,val2), minAbsoluteTol)