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
6
#include <
yarp/robottestingframework/TestAsserter.h
>
7
#include <
yarp/sig/Vector.h
>
8
#include <robottestingframework/TestAssert.h>
9
#include <cmath>
10
11
12
class
yarp::robottestingframework::TestAsserter::Private
13
{
14
};
15
16
yarp::robottestingframework::TestAsserter::TestAsserter
() :
17
mPriv(new
Private
)
18
{
19
}
20
21
yarp::robottestingframework::TestAsserter::~TestAsserter
()
22
{
23
delete
mPriv;
24
}
25
26
bool
yarp::robottestingframework::TestAsserter::isApproxEqual
(
const
double
*left,
27
const
double
*right,
28
const
double
*thresholds,
29
int
length)
30
{
31
return
isApproxEqual(left, right, thresholds, thresholds, length);
32
}
33
34
bool
yarp::robottestingframework::TestAsserter::isApproxEqual
(
const
double
*left,
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
51
bool
yarp::robottestingframework::TestAsserter::isApproxEqual
(
const
yarp::sig::Vector
&left,
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
62
bool
yarp::robottestingframework::TestAsserter::isApproxEqual
(
double
left,
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
}
TestAsserter.h
Vector.h
contains the definition of a Vector type
yarp::robottestingframework::TestAsserter::Private
Definition
TestAsserter.cpp:13
yarp::robottestingframework::TestAsserter::~TestAsserter
virtual ~TestAsserter()
Definition
TestAsserter.cpp:21
yarp::robottestingframework::TestAsserter::isApproxEqual
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...
Definition
TestAsserter.cpp:34
yarp::robottestingframework::TestAsserter::TestAsserter
TestAsserter()
Definition
TestAsserter.cpp:16
yarp::sig::VectorOf< double >
yarp::sig::VectorOf::size
size_t size() const
Definition
Vector.h:341
yarp::sig::VectorOf::data
T * data()
Return a pointer to the first element of the vector.
Definition
Vector.h:206
YARP
3.11.100+20250603.4+gitaa77f8b5c
src
libYARP_robottestingframework
src
yarp
robottestingframework
TestAsserter.cpp
Generated on Wed Jun 4 2025 02:40:12 for YARP by
1.9.8