GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/** |
||
2 |
* @file test_polynomes.cpp |
||
3 |
* @author Maximilien Naveau (maximilien.naveau@gmail.com) |
||
4 |
* @brief Test for the polynome.hpp classes |
||
5 |
* @version 0.1 |
||
6 |
* @date 2019-11-07 |
||
7 |
* |
||
8 |
* @copyright Copyright (c) 2019 |
||
9 |
* |
||
10 |
*/ |
||
11 |
|||
12 |
#include <fstream> |
||
13 |
#include <cmath> // std::sqrt |
||
14 |
#include <ctime> // std::time |
||
15 |
#include <cstdlib> // std::rand, std::srand |
||
16 |
#include <gtest/gtest.h> |
||
17 |
#include "blmc_robots/mathematics/polynome.hpp" |
||
18 |
|||
19 |
#define RAND_MAX_NEW 1e4 |
||
20 |
|||
21 |
/**< @brief The DISABLED_TestPolynomes class is used to disable test. */ |
||
22 |
class DISABLED_TestPolynomes : public ::testing::Test {}; |
||
23 |
|||
24 |
/**< |
||
25 |
* @brief The TestPolynomes class: test suit template for setting up |
||
26 |
* the unit tests for the Polynomes. |
||
27 |
*/ |
||
28 |
✗✓ | 2 |
class TestPolynomes : public ::testing::Test { |
29 |
|||
30 |
public: |
||
31 |
2 |
TestPolynomes(): ::testing::Test(){ |
|
32 |
// use current time as seed for random generator |
||
33 |
2 |
std::srand(std::time(nullptr)); |
|
34 |
2 |
} |
|
35 |
|||
36 |
3 |
static double rand() |
|
37 |
{ |
||
38 |
3 |
double sign = 1.0; |
|
39 |
✓✓ | 3 |
if(std::rand() % 2 == 0) |
40 |
{ |
||
41 |
1 |
sign *= -1.0; |
|
42 |
} |
||
43 |
3 |
return sign * static_cast<double>(std::rand()) / |
|
44 |
static_cast<double>(RAND_MAX) * |
||
45 |
3 |
static_cast<double>(RAND_MAX_NEW); |
|
46 |
} |
||
47 |
|||
48 |
protected: |
||
49 |
/**< @brief SetUp, is executed before the unit tests */ |
||
50 |
2 |
void SetUp() {} |
|
51 |
|||
52 |
/**< @brief TearDown, is executed after teh unit tests */ |
||
53 |
2 |
void TearDown() {} |
|
54 |
}; |
||
55 |
|||
56 |
/*! Test the compute function */ |
||
57 |
✗✓ | 5 |
TEST_F(TestPolynomes, test_order_5_constructor) |
58 |
{ |
||
59 |
// create the polynome of order 5 |
||
60 |
✓✗ | 2 |
blmc_robots::TimePolynome<5> polynome; |
61 |
|||
62 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(0.0, polynome.get_init_pose()); |
63 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(0.0, polynome.get_init_speed()); |
64 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(0.0, polynome.get_init_acc()); |
65 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(0.0, polynome.get_final_pose()); |
66 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(0.0, polynome.get_final_speed()); |
67 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(0.0, polynome.get_final_acc()); |
68 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗✓✗ |
1 |
ASSERT_EQ(0.0, polynome.get_final_time()); |
69 |
|||
70 |
} |
||
71 |
|||
72 |
/*! Test the compute function */ |
||
73 |
✗✓ | 5 |
TEST_F(TestPolynomes, test_order_5) |
74 |
{ |
||
75 |
// create the polynome of order 5 |
||
76 |
✓✗ | 2 |
blmc_robots::TimePolynome<5> polynome; |
77 |
|||
78 |
// define a random polynome |
||
79 |
1 |
double duration = std::abs(TestPolynomes::rand()); |
|
80 |
1 |
double final_pose = TestPolynomes::rand(); |
|
81 |
1 |
double init_pose = TestPolynomes::rand(); |
|
82 |
1 |
double init_speed = 0.0; |
|
83 |
1 |
double eps = 1e-8; |
|
84 |
|||
85 |
✓✗ | 1 |
polynome.set_parameters(duration, init_pose, init_speed, final_pose); |
86 |
|||
87 |
✓✗✓✗ ✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(polynome.compute(-eps), init_pose); |
88 |
✓✗✓✗ ✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(polynome.compute_derivative(-eps), init_speed); |
89 |
✓✗✓✗ ✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(polynome.compute_sec_derivative(-eps), 0.0); |
90 |
✓✗✓✗ ✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(polynome.compute(duration+eps), final_pose); |
91 |
✓✗✓✗ ✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(polynome.compute_derivative(duration+eps), 0.0); |
92 |
✓✗✓✗ ✗✓✗✗ ✗✗✗✗ ✗✗✓✗ |
1 |
ASSERT_EQ(polynome.compute_sec_derivative(duration+eps), 0.0); |
93 |
|||
94 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(init_pose, polynome.get_init_pose()); |
95 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(init_speed, polynome.get_init_speed()); |
96 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(0.0, polynome.get_init_acc()); |
97 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(final_pose, polynome.get_final_pose()); |
98 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(0.0, polynome.get_final_speed()); |
99 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(0.0, polynome.get_final_acc()); |
100 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
1 |
ASSERT_EQ(duration, polynome.get_final_time()); |
101 |
|||
102 |
1 |
double ub = std::max(init_pose, final_pose); |
|
103 |
1 |
double lb = std::min(init_pose, final_pose); |
|
104 |
|||
105 |
1 |
double init_time = -0.2 * duration; |
|
106 |
1 |
double final_time = duration + std::abs(init_time); |
|
107 |
1 |
double time_step = std::abs(final_time - init_time)/10000.0; |
|
108 |
|||
109 |
1 |
double time = init_time; |
|
110 |
✓✓✓✗ |
20021 |
while(time < (final_time + 10 * time_step)) |
111 |
{ |
||
112 |
✓✗ | 10010 |
double value = polynome.compute(time); |
113 |
10010 |
time += time_step; |
|
114 |
|||
115 |
// the data is always between the init and final pose |
||
116 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
10010 |
ASSERT_LE(value, ub); |
117 |
✓✗✗✓ ✗✗✗✗ ✗✗✗✗ ✓✗ |
10010 |
ASSERT_LE(lb, value); |
118 |
} |
||
119 |
|||
120 |
✓✗✓✗ |
3 |
} |
Generated by: GCOVR (Version 4.2) |