YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
TestAsserter.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include <yarp/sig/Vector.h>
8#include <robottestingframework/TestAssert.h>
9#include <cmath>
10
11
15
20
25
27 const double *right,
28 const double *thresholds,
29 int length)
30{
31 return isApproxEqual(left, right, thresholds, thresholds, length);
32}
33
35 const double *right,
36 const double *l_thresholds,
37 const double *h_thresholds,
38 int length)
39{
40 bool reached = true;
41 for(int j = 0; j < length; j++)
42 {
43 if (left[j]<(right[j]-fabs(l_thresholds[j])) || left[j]>(right[j]+fabs(h_thresholds[j]))) {
44 reached=false;
45 }
46 }
47 return reached;
48}
49
50
52 const yarp::sig::Vector &right,
53 const yarp::sig::Vector &thresholds)
54{
55 if (left.size() != right.size() && right.size() != thresholds.size()) {
56 ROBOTTESTINGFRAMEWORK_ASSERT_ERROR("yarp::robottestingframework::TestAsserter::isApproxEqual : vectors must have same size!");
57 return false;
58 }
59 return isApproxEqual(left.data(), right.data(), thresholds.data(), left.size());
60}
61
63 double right,
64 double l_th,
65 double h_th)
66{
67
68 if (left >= right - fabs(l_th) && left <= right + fabs(h_th)) {
69 return true;
70 } else {
71 return false;
72 }
73}
contains the definition of a Vector type
static bool isApproxEqual(const double *left, const double *right, const double *l_thresholds, const double *h_thresholds, int length)
Element-wise compare two vectors to determine if they are approximately equal, according to asymmetri...
size_t size() const
Definition Vector.h:341
T * data()
Return a pointer to the first element of the vector.
Definition Vector.h:206