Directory: | ./ |
---|---|
File: | tests/filters/test_filter_differentiator.cpp |
Date: | 2024-08-13 12:13:25 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 31 | 31 | 100.0% |
Branches: | 71 | 140 | 50.7% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright 2019, | ||
3 | * Olivier Stasse, | ||
4 | * | ||
5 | * CNRS/AIST | ||
6 | * | ||
7 | */ | ||
8 | |||
9 | #include <iostream> | ||
10 | #include <sot/core/debug.hh> | ||
11 | |||
12 | #ifndef WIN32 | ||
13 | #include <unistd.h> | ||
14 | #endif | ||
15 | |||
16 | using namespace std; | ||
17 | |||
18 | #include <dynamic-graph/entity.h> | ||
19 | #include <dynamic-graph/factory.h> | ||
20 | |||
21 | #include <sot/core/filter-differentiator.hh> | ||
22 | #include <sstream> | ||
23 | |||
24 | using namespace dynamicgraph; | ||
25 | using namespace dynamicgraph::sot; | ||
26 | |||
27 | #define BOOST_TEST_MODULE test - filter - differentiator | ||
28 | |||
29 | #include <boost/test/output_test_stream.hpp> | ||
30 | #include <boost/test/unit_test.hpp> | ||
31 | |||
32 | using boost::test_tools::output_test_stream; | ||
33 | |||
34 |
33/66✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
|
4 | BOOST_AUTO_TEST_CASE(test_filter_differentiator) { |
35 | sot::FilterDifferentiator *aFilterDiff = | ||
36 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | new FilterDifferentiator("filter_differentiator"); |
37 | |||
38 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | Eigen::VectorXd filter_num(7), filter_den(7); |
39 | |||
40 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_num(0) = 2.16439898e-05; |
41 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_num(1) = 4.43473520e-05; |
42 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_num(2) = -1.74065002e-05; |
43 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_num(3) = -8.02197247e-05; |
44 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_num(4) = -1.74065002e-05; |
45 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_num(5) = 4.43473520e-05; |
46 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_num(6) = 2.16439898e-05; |
47 | |||
48 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_den(0) = 1.; |
49 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_den(1) = -5.32595322; |
50 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_den(2) = 11.89749109; |
51 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_den(3) = -14.26803139; |
52 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_den(4) = 9.68705647; |
53 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_den(5) = -3.52968633; |
54 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | filter_den(6) = 0.53914042; |
55 | |||
56 | 2 | double timestep = 0.001; | |
57 | 2 | int xSize = 16; | |
58 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | aFilterDiff->init(timestep, xSize, filter_num, filter_den); |
59 | |||
60 | 2 | srand(0); | |
61 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | dynamicgraph::Vector aVec(16); |
62 |
3/4✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 1 times.
|
34 | for (unsigned int i = 0; i < 16; i++) aVec(i) = (double)(i + rand() % 100); |
63 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | aFilterDiff->m_xSIN = aVec; |
64 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | aFilterDiff->m_x_filteredSOUT.recompute(0); |
65 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | output_test_stream output; |
66 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ostringstream anoss; |
67 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | dynamicgraph::Vector outVec; |
68 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | aFilterDiff->m_x_filteredSOUT.get(output); |
69 | |||
70 |
7/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✗ Branch 25 not taken.
✓ Branch 26 taken 1 times.
|
2 | BOOST_CHECK( |
71 | output.is_equal("82.5614 " | ||
72 | "86.5403 " | ||
73 | "78.5826 " | ||
74 | "17.9049 " | ||
75 | "96.4874 " | ||
76 | "39.7886 " | ||
77 | "91.5139 " | ||
78 | "98.4769 " | ||
79 | "56.6988 " | ||
80 | "29.8415 " | ||
81 | "71.6195 " | ||
82 | "37.7992 " | ||
83 | "101.461 " | ||
84 | "71.6195 " | ||
85 | "76.5931 " | ||
86 | "40.7834")); | ||
87 | 2 | } | |
88 |