Go to the documentation of this file.00001
00007
00008
00009
00010
00011 #include <gtest/gtest.h>
00012 #include <iostream>
00013 #include "../../include/ecl/time/frequency.hpp"
00014 #include "../../include/ecl/time/sleep.hpp"
00015 #include "../../include/ecl/time/timestamp.hpp"
00016
00017
00018
00019
00020
00021 #ifdef ECL_HAS_TIMESTAMP
00022
00023
00024
00025
00026
00027 std::ostream& operator <<( std::ostream& ostream , const ecl::FrequencyDiagnostics& diagnostics )
00028 {
00029 ostream << std::fixed;
00030 ostream << "hz : " << diagnostics.hz;
00031 ostream << ", min : " << diagnostics.minimum_interval;
00032 ostream << ", max : " << diagnostics.maximum_interval;
00033 ostream << ", last_incoming : " << diagnostics.last_incoming << std::scientific;
00034
00035
00036 return ostream;
00037 }
00038
00039
00040
00041
00042
00043 TEST(FrequencyMonitorTests,silent) {
00044
00045 ecl::FrequencyMonitor monitor(0.5, true);
00046 ecl::FrequencyDiagnostics diagnostics;
00047
00048 ecl::MilliSleep sleep_ms;
00049 unsigned int period = 100;
00050
00051
00052
00053
00054 float epsilon = 0.3;
00055 for ( unsigned int i = 0; i < 50; ++i ) {
00056 monitor.update();
00057 diagnostics = monitor.analyse();
00058 if ( i == 25 ) {
00059 period = 200;
00060 std::cout << diagnostics << std::endl;
00061 EXPECT_NEAR(diagnostics.hz, 10.0, epsilon);
00062 }
00063 sleep_ms(period);
00064 }
00065 std::cout << diagnostics << std::endl;
00066 EXPECT_NEAR(diagnostics.hz, 5.0, epsilon);
00067 SUCCEED();
00068 }
00069
00070 #endif
00071
00072
00073
00074
00075
00076 int main(int argc, char **argv) {
00077
00078 testing::InitGoogleTest(&argc,argv);
00079 return RUN_ALL_TESTS();
00080 }