17 #ifndef TimeMeasure_cpp 18 #define TimeMeasure_cpp 20 #include <cppunit/ui/text/TestRunner.h> 21 #include <cppunit/TextOutputter.h> 22 #include <cppunit/extensions/TestFactoryRegistry.h> 23 #include <cppunit/extensions/HelperMacros.h> 24 #include <cppunit/TestAssert.h> 25 #include <coil/Time.h> 26 #include <coil/TimeMeasure.h> 35 :
public CppUnit::TestFixture
81 CPPUNIT_ASSERT(tm.
count() == 0);
83 const unsigned long int count0(10);
84 for (
unsigned int i(0); i < count0; ++i)
89 CPPUNIT_ASSERT(tm.
count() == count0);
93 CPPUNIT_ASSERT(tm.
count() == 0);
95 const unsigned long int count1(53);
96 for (
unsigned int i(0); i < count1; ++i)
101 CPPUNIT_ASSERT(tm.
count() == count1);
107 double maxi, mini, mean, stdev;
108 CPPUNIT_ASSERT(tm.
getStatistics(maxi, mini, mean, stdev) ==
false);
110 CPPUNIT_ASSERT(tm.
getStatistics(maxi, mini, mean, stdev) ==
false);
112 CPPUNIT_ASSERT(tm.
getStatistics(maxi, mini, mean, stdev) ==
true);
114 CPPUNIT_ASSERT(tm.
getStatistics(maxi, mini, mean, stdev) ==
false);
121 CPPUNIT_ASSERT(tm0.
count() == 0);
124 CPPUNIT_ASSERT(tm0.
count() == 1);
128 const unsigned int count(1024);
131 for (
unsigned int i(0); i < count; ++i)
133 CPPUNIT_ASSERT(tm1.
count() == i);
137 for (
unsigned int i(0); i < count; ++i)
141 CPPUNIT_ASSERT(tm1.
count() == (count + 1));
150 const double wait(0.03);
152 for (
int i(0); i < 10; ++i)
158 double maxi, mini, mean, stdev;
166 CPPUNIT_ASSERT(maxi < (wait + 0.030));
167 CPPUNIT_ASSERT(mini > (wait - 0.010));
168 CPPUNIT_ASSERT(fabs(mean - wait) < 0.03);
169 CPPUNIT_ASSERT(stdev < (wait / 5.0));
173 const double wait(1.0);
175 for (
int i(0); i < 1; ++i)
181 double maxi, mini, mean, stdev;
189 CPPUNIT_ASSERT(maxi < (wait + 0.030));
190 CPPUNIT_ASSERT(mini > (wait - 0.010));
191 CPPUNIT_ASSERT(fabs(mean - wait) < 0.03);
192 CPPUNIT_ASSERT(stdev < (wait / 5.0));
203 int main(
int argc,
char* argv[])
205 CppUnit::TextUi::TestRunner runner;
206 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
207 CppUnit::Outputter* outputter =
208 new CppUnit::TextOutputter(&runner.result(), std::cout);
209 runner.setOutputter(outputter);
214 #endif // TimeMeasure_cpp int main(int argc, char **argv)
bool getStatistics(double &max_interval, double &min_interval, double &mean_interval, double &stddev)
Get total statistics.
unsigned int sleep(unsigned int seconds)
Stop a processing at specified second time.
virtual void setUp()
Test initialization.
CPPUNIT_TEST_SUITE_REGISTRATION(TimeMeasure::TimeMeasureTests)
CPPUNIT_TEST_SUITE(TimeMeasureTests)
TimeMeasureTests()
Constructor.
~TimeMeasureTests()
Destructor.
void tack()
Finish time measurement for time statistics.
virtual void tearDown()
Test finalization.
void reset()
Initialize for statistics related data.
unsigned long int count() const
Get number of time measurement buffer.
void tick()
Begin time measurement for time statistics.
int usleep(useconds_t usec)
Stop a processing at specified micro second time.