1 #include "TimerTest.hpp"
3 #include "app/IntervalTimer.hpp"
7 CPPUNIT_TEST_SUITE_REGISTRATION(gong::app::test::TimerTest);
14 void TimerTest::setUp() {
17 void TimerTest::tearDown() {
21 void TimerTest::testCoarseTimer() {
22 CoarseTimer timer(50);
23 CPPUNIT_ASSERT_MESSAGE(
24 "fresh coarse timer is running",
27 CPPUNIT_ASSERT_MESSAGE(
28 "fresh coarse timer hit",
31 CPPUNIT_ASSERT_EQUAL_MESSAGE(
32 "fresh coarse timer with non-zero elapsed time",
35 CPPUNIT_ASSERT_EQUAL_MESSAGE(
36 "fresh coarse timer at non-zero iteration",
41 CPPUNIT_ASSERT_MESSAGE(
42 "startet coarse timer is not running",
45 CPPUNIT_ASSERT_MESSAGE(
46 "started coarse timer hit without update",
49 CPPUNIT_ASSERT_EQUAL_MESSAGE(
50 "started, but not updated coarse timer with non-zero elapsed time",
53 CPPUNIT_ASSERT_EQUAL_MESSAGE(
54 "started, but not updated coarse timer at non-zero iteration",
59 CPPUNIT_ASSERT_MESSAGE(
60 "updated coarse timer is not running",
63 CPPUNIT_ASSERT_MESSAGE(
64 "coarse timer hit after update, but before it should",
67 CPPUNIT_ASSERT_EQUAL_MESSAGE(
68 "wrong elapsed time on updated coarse timer",
71 CPPUNIT_ASSERT_EQUAL_MESSAGE(
72 "wrong iteration on updated coarse timer",
77 CPPUNIT_ASSERT_MESSAGE(
78 "coarse timer not hit after updating to its exact interval time",
81 CPPUNIT_ASSERT_EQUAL_MESSAGE(
82 "wrong elapsed time on updated coarse timer",
85 CPPUNIT_ASSERT_EQUAL_MESSAGE(
86 "wrong iteration on updated coarse timer at exact interval time",
91 CPPUNIT_ASSERT_MESSAGE(
92 "coarse timer hit after updating from exact interval time to just before the next",
95 CPPUNIT_ASSERT_EQUAL_MESSAGE(
96 "wrong elapsed time on updated coarse timer",
99 CPPUNIT_ASSERT_EQUAL_MESSAGE(
100 "wrong iteration after updating coarse timer from exact interval time to just before the next",
105 CPPUNIT_ASSERT_MESSAGE(
106 "coarse timer not hit after updating across interval time boundary",
109 CPPUNIT_ASSERT_EQUAL_MESSAGE(
110 "wrong elapsed time on updated coarse timer",
113 CPPUNIT_ASSERT_EQUAL_MESSAGE(
114 "wrong iteration after updating across interval time boundary",
119 CPPUNIT_ASSERT_MESSAGE(
120 "stopped coarse timer is running",
123 CPPUNIT_ASSERT_MESSAGE(
124 "stopped coarse timer hit",
127 CPPUNIT_ASSERT_EQUAL_MESSAGE(
128 "stopped coarse timer has non-zero elapsed time",
131 CPPUNIT_ASSERT_EQUAL_MESSAGE(
132 "stopped coarse timer at non-zero iteration",
137 void TimerTest::testFineTimer() {
138 FineTimer timer(0.5f);
139 CPPUNIT_ASSERT_MESSAGE(
140 "fresh fine timer is running",
143 CPPUNIT_ASSERT_MESSAGE(
144 "fresh fine timer hit",
147 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
148 "fresh fine timer with non-zero elapsed time",
149 0.0f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
151 CPPUNIT_ASSERT_EQUAL_MESSAGE(
152 "fresh fine timer at non-zero iteration",
157 CPPUNIT_ASSERT_MESSAGE(
158 "startet fine timer is not running",
161 CPPUNIT_ASSERT_MESSAGE(
162 "started fine timer hit without update",
165 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
166 "started, but not updated fine timer with non-zero elapsed time",
167 0.0f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
169 CPPUNIT_ASSERT_EQUAL_MESSAGE(
170 "started, but not updated fine timer at non-zero iteration",
175 CPPUNIT_ASSERT_MESSAGE(
176 "updated fine timer is not running",
179 CPPUNIT_ASSERT_MESSAGE(
180 "fine timer hit after update, but before it should",
183 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
184 "wrong elapsed time on updated fine timer",
185 0.25f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
187 CPPUNIT_ASSERT_EQUAL_MESSAGE(
188 "wrong iteration on updated fine timer",
193 CPPUNIT_ASSERT_MESSAGE(
194 "fine timer not hit after updating to its exact interval time",
197 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
198 "wrong elapsed time on updated fine timer",
199 0.5f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
201 CPPUNIT_ASSERT_EQUAL_MESSAGE(
202 "wrong iteration on updated fine timer at exact interval time",
207 CPPUNIT_ASSERT_MESSAGE(
208 "fine timer hit after updating from exact interval time to just before the next",
211 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
212 "wrong elapsed time on updated fine timer",
213 0.99f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
215 CPPUNIT_ASSERT_EQUAL_MESSAGE(
216 "wrong iteration after updating fine timer from exact interval time to just before the next",
221 CPPUNIT_ASSERT_MESSAGE(
222 "fine timer not hit after updating across interval time boundary",
225 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
226 "wrong elapsed time on updated fine timer",
227 1.01f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
229 CPPUNIT_ASSERT_EQUAL_MESSAGE(
230 "wrong iteration after updating across interval time boundary",
235 CPPUNIT_ASSERT_MESSAGE(
236 "stopped fine timer is running",
239 CPPUNIT_ASSERT_MESSAGE(
240 "stopped fine timer hit",
243 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
244 "stopped fine timer has non-zero elapsed time",
245 0.0f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
247 CPPUNIT_ASSERT_EQUAL_MESSAGE(
248 "stopped fine timer at non-zero iteration",