YARP
Yet Another Robot Platform
TestAsserter.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3
* All rights reserved.
4
*
5
* This software may be modified and distributed under the terms of the
6
* BSD-3-Clause license. See the accompanying LICENSE file for details.
7
*/
8
9
#include <
yarp/robottestingframework/TestAsserter.h
>
10
#include <
yarp/sig/Vector.h
>
11
#include <robottestingframework/TestAssert.h>
12
#include <cmath>
13
14
15
class
yarp::robottestingframework::TestAsserter::Private
16
{
17
};
18
19
yarp::robottestingframework::TestAsserter::TestAsserter
() :
20
mPriv(new
Private
)
21
{
22
}
23
24
yarp::robottestingframework::TestAsserter::~TestAsserter
()
25
{
26
delete
mPriv;
27
}
28
29
bool
yarp::robottestingframework::TestAsserter::isApproxEqual
(
const
double
*left,
30
const
double
*right,
31
const
double
*thresholds,
32
int
length)
33
{
34
return
isApproxEqual(left, right, thresholds, thresholds, length);
35
}
36
37
bool
yarp::robottestingframework::TestAsserter::isApproxEqual
(
const
double
*left,
38
const
double
*right,
39
const
double
*l_thresholds,
40
const
double
*h_thresholds,
41
int
length)
42
{
43
bool
reached =
true
;
44
for
(
int
j = 0; j < length; j++)
45
{
46
if
(left[j]<(right[j]-fabs(l_thresholds[j])) || left[j]>(right[j]+fabs(h_thresholds[j]))) {
47
reached=
false
;
48
}
49
}
50
return
reached;
51
}
52
53
54
bool
yarp::robottestingframework::TestAsserter::isApproxEqual
(
const
yarp::sig::Vector
&left,
55
const
yarp::sig::Vector
&right,
56
const
yarp::sig::Vector
&thresholds)
57
{
58
if
(left.
size
() != right.
size
() && right.
size
() != thresholds.
size
()) {
59
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR(
"yarp::robottestingframework::TestAsserter::isApproxEqual : vectors must have same size!"
);
60
return
false
;
61
}
62
return
isApproxEqual(left.
data
(), right.
data
(), thresholds.
data
(), left.
size
());
63
}
64
65
bool
yarp::robottestingframework::TestAsserter::isApproxEqual
(
double
left,
66
double
right,
67
double
l_th,
68
double
h_th)
69
{
70
71
if
(left >= right - fabs(l_th) && left <= right + fabs(h_th)) {
72
return
true
;
73
}
else
{
74
return
false
;
75
}
76
}
yarp::robottestingframework::TestAsserter::TestAsserter
TestAsserter()
Definition:
TestAsserter.cpp:19
Vector.h
contains the definition of a Vector type
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:37
yarp::sig::VectorOf< double >
yarp::robottestingframework::TestAsserter::Private
Definition:
TestAsserter.cpp:16
yarp::robottestingframework::TestAsserter::~TestAsserter
virtual ~TestAsserter()
Definition:
TestAsserter.cpp:24
yarp::sig::VectorOf::data
T * data()
Return a pointer to the first element of the vector.
Definition:
Vector.h:239
TestAsserter.h
yarp::sig::VectorOf::size
size_t size() const
Definition:
Vector.h:355
YARP
3.4.100+20201223.2+gitb8ea4d712
src
libYARP_robottestingframework
src
yarp
robottestingframework
TestAsserter.cpp
Generated on Sun Jan 3 2021 02:46:25 for YARP by
1.8.20