11#include < catch2/catch.hpp>
22
3- #include " rtbot/std/CosineResampler.h"
43#include " rtbot/std/HermiteResampler.h"
54
65using namespace rtbot ;
76using namespace std ;
87
9- TEST_CASE (" Cosine Resampler test emit at right frequencies" ) {
10- auto i1 = CosineResampler<uint64_t , double >(" i1" , 99 );
11- auto i2 = CosineResampler<uint64_t , double >(" i2" , 99 );
12-
13- SECTION (" emits once" ) {
14- for (int i = 0 ; i < 20 ; i++) {
15- i1.receiveData (Message<uint64_t , double >(i * 100 , i * i));
16- map<string, map<string, vector<Message<uint64_t , double >>>> emitted = i1.executeData ();
17-
18- if (i == 0 )
19- REQUIRE (emitted.empty ());
20- else {
21- REQUIRE (emitted.find (" i1" )->second .find (" o1" )->second .at (0 ).time == 99 * i);
22- }
23- }
24- }
25-
26- SECTION (" emits twice" ) {
27- for (int i = 0 ; i < 20 ; i++) {
28- i2.receiveData (Message<uint64_t , double >(i * 200 , i * i));
29- map<string, map<string, vector<Message<uint64_t , double >>>> emitted = i2.executeData ();
30-
31- if (i == 0 )
32- REQUIRE (emitted.empty ());
33- else {
34- REQUIRE (emitted.find (" i2" )->second .find (" o1" )->second .at (0 ).time == 99 * (2 * i - 1 ));
35- REQUIRE (emitted.find (" i2" )->second .find (" o1" )->second .at (1 ).time == 99 * (2 * i));
36- }
37- }
38- }
39- }
40-
418TEST_CASE (" Hermite Resampler test emit at right frequencies" ) {
429 auto i1 = HermiteResampler<uint64_t , double >(" i1" , 99 );
4310 auto i2 = HermiteResampler<uint64_t , double >(" i2" , 99 );
4411 auto i3 = HermiteResampler<int64_t , double >(" i3" , 99 );
12+ auto i4 = HermiteResampler<int64_t , double >(" i4" , 1 );
4513
4614 SECTION (" emits once" ) {
4715 for (int i = 0 ; i < 20 ; i++) {
@@ -80,8 +48,8 @@ TEST_CASE("Hermite Resampler test emit at right frequencies") {
8048
8149 SECTION (" emits right values" ) {
8250 for (int i = 0 ; i < 20 ; i++) {
83- i3.receiveData (Message<std:: int64_t , double >(i * 100 , i * i));
84- map<string, map<string, vector<Message<std:: int64_t , double >>>> emitted = i3.executeData ();
51+ i3.receiveData (Message<int64_t , double >(i * 100 , i * i));
52+ map<string, map<string, vector<Message<int64_t , double >>>> emitted = i3.executeData ();
8553
8654 if (i == 0 || i == 1 || i == 2 )
8755 REQUIRE (emitted.empty ());
@@ -94,4 +62,38 @@ TEST_CASE("Hermite Resampler test emit at right frequencies") {
9462 }
9563 }
9664 }
65+
66+ SECTION (" emits every time, one next to the next one" ) {
67+ srand (time (nullptr ));
68+ vector<int > v;
69+ int start = 0 ;
70+ int end = 2000 ;
71+ int last = start;
72+ v.push_back (start);
73+ for (int i = start + 1 ; i < end; i++) {
74+ int random_value = rand ();
75+ if (random_value < (RAND_MAX / 2 )) {
76+ v.push_back (i);
77+ }
78+ }
79+ v.push_back (end);
80+
81+ for (int i = 0 ; i < v.size (); i++) {
82+ i4.receiveData (Message<int64_t , double >(v.at (i), v.at (i) * v.at (i)));
83+ map<string, map<string, vector<Message<int64_t , double >>>> emitted = i4.executeData ();
84+
85+ if (i == 0 || i == 1 || i == 2 ) {
86+ // cout << "******* (" << v.at(i) << ") *******" << endl;
87+ REQUIRE (emitted.empty ());
88+ } else {
89+ // cout << "******* (" << v.at(i) << ") *******" << endl;
90+ for (int j = 0 ; j < emitted.find (" i4" )->second .find (" o1" )->second .size (); j++) {
91+ int now = emitted.find (" i4" )->second .find (" o1" )->second .at (j).time ;
92+ REQUIRE (now - 1 == last);
93+ last = now;
94+ // cout << now << endl;
95+ }
96+ }
97+ }
98+ }
9799}
0 commit comments