test/frequency.cpp
Go to the documentation of this file.
1 
7 /*****************************************************************************
8 ** Includes
9 *****************************************************************************/
10 
11 #include <gtest/gtest.h>
12 #include <iostream>
13 #include "../../include/ecl/time/frequency.hpp"
14 #include "../../include/ecl/time/sleep.hpp"
15 #include "../../include/ecl/time/timestamp.hpp"
16 
17 /*****************************************************************************
18 ** Platform Check
19 *****************************************************************************/
20 
21 #ifdef ECL_HAS_TIMESTAMP
22 
23 /*****************************************************************************
24 ** Methods
25 *****************************************************************************/
26 
27 std::ostream& operator <<( std::ostream& ostream , const ecl::FrequencyDiagnostics& diagnostics )
28 {
29  ostream << std::fixed;
30  ostream << "hz : " << diagnostics.hz;
31  ostream << ", min : " << diagnostics.minimum_interval;
32  ostream << ", max : " << diagnostics.maximum_interval;
33  ostream << ", last_incoming : " << diagnostics.last_incoming << std::scientific;
34  // could print the others, but that would require use of std ios flags to pretty print correctly.
35  // let the user do that how they wish if they want to
36  return ostream;
37 }
38 
39 /*****************************************************************************
40 ** Tests
41 *****************************************************************************/
42 
43 TEST(FrequencyMonitorTests,silent) {
44 
45  ecl::FrequencyMonitor monitor(0.5, true);
46  ecl::FrequencyDiagnostics diagnostics;
47 
48  ecl::MilliSleep sleep_ms;
49  unsigned int period = 100;
50 
51 // std::cout << "\n**********************************************************" << std::endl;
52 // std::cout << "* Frequency Monitor Test" << std::endl;
53 // std::cout << "**********************************************************\n" << std::endl;
54  float epsilon = 0.3;
55  for ( unsigned int i = 0; i < 50; ++i ) {
56  monitor.update();
57  diagnostics = monitor.analyse();
58  if ( i == 25 ) {
59  period = 200;
60  std::cout << diagnostics << std::endl;
61  EXPECT_NEAR(diagnostics.hz, 10.0, epsilon);
62  }
63  sleep_ms(period);
64  }
65  std::cout << diagnostics << std::endl;
66  EXPECT_NEAR(diagnostics.hz, 5.0, epsilon);
67  SUCCEED();
68 }
69 
70 #endif /* ECL_HAS_TIMESTAMP */
71 
72 /*****************************************************************************
73 ** Main program
74 *****************************************************************************/
75 
76 int main(int argc, char **argv) {
77 
78  testing::InitGoogleTest(&argc,argv);
79  return RUN_ALL_TESTS();
80 }
ecl::FrequencyDiagnostics::last_incoming
float last_incoming
Definition: frequency.hpp:61
ecl::FrequencyDiagnostics::hz
float hz
Definition: frequency.hpp:57
ecl::FrequencyDiagnostics::maximum_interval
float maximum_interval
Definition: frequency.hpp:60
ecl::FrequencyDiagnostics::minimum_interval
float minimum_interval
Definition: frequency.hpp:59
ecl::operator<<
OutputStream & operator<<(OutputStream &ostream, const TimeStampBase &time_stamp)
Definition: timestamp_base.hpp:232
ecl::FrequencyDiagnostics
Data relevant to frequencies of an incoming stream.
Definition: frequency.hpp:37
main
int main(int argc, char **argv)
Definition: test/frequency.cpp:76
ecl::FrequencyMonitor
Lightweight and fast frequency monitor.
Definition: frequency.hpp:89
TEST
TEST(TimeDataTests, container)
Definition: test/time_data.cpp:27


ecl_time
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:19