1 #include "TimerTest.hpp"
3 #include "app/IntervalTimer.hpp"
7 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::TimerTest);
13 void TimerTest::setUp() {
16 void TimerTest::tearDown() {
20 void TimerTest::testCoarseTimer() {
21 CoarseTimer timer(50);
22 CPPUNIT_ASSERT_MESSAGE(
23 "fresh coarse timer is running",
26 CPPUNIT_ASSERT_MESSAGE(
27 "fresh coarse timer hit",
30 CPPUNIT_ASSERT_EQUAL_MESSAGE(
31 "fresh coarse timer with non-zero elapsed time",
34 CPPUNIT_ASSERT_EQUAL_MESSAGE(
35 "fresh coarse timer at non-zero iteration",
40 CPPUNIT_ASSERT_MESSAGE(
41 "startet coarse timer is not running",
44 CPPUNIT_ASSERT_MESSAGE(
45 "started coarse timer hit without update",
48 CPPUNIT_ASSERT_EQUAL_MESSAGE(
49 "started, but not updated coarse timer with non-zero elapsed time",
52 CPPUNIT_ASSERT_EQUAL_MESSAGE(
53 "started, but not updated coarse timer at non-zero iteration",
58 CPPUNIT_ASSERT_MESSAGE(
59 "updated coarse timer is not running",
62 CPPUNIT_ASSERT_MESSAGE(
63 "coarse timer hit after update, but before it should",
66 CPPUNIT_ASSERT_EQUAL_MESSAGE(
67 "wrong elapsed time on updated coarse timer",
70 CPPUNIT_ASSERT_EQUAL_MESSAGE(
71 "wrong iteration on updated coarse timer",
76 CPPUNIT_ASSERT_MESSAGE(
77 "coarse timer not hit after updating to its exact interval time",
80 CPPUNIT_ASSERT_EQUAL_MESSAGE(
81 "wrong elapsed time on updated coarse timer",
84 CPPUNIT_ASSERT_EQUAL_MESSAGE(
85 "wrong iteration on updated coarse timer at exact interval time",
90 CPPUNIT_ASSERT_MESSAGE(
91 "coarse timer hit after updating from exact interval time to just before the next",
94 CPPUNIT_ASSERT_EQUAL_MESSAGE(
95 "wrong elapsed time on updated coarse timer",
98 CPPUNIT_ASSERT_EQUAL_MESSAGE(
99 "wrong iteration after updating coarse timer from exact interval time to just before the next",
104 CPPUNIT_ASSERT_MESSAGE(
105 "coarse timer not hit after updating across interval time boundary",
108 CPPUNIT_ASSERT_EQUAL_MESSAGE(
109 "wrong elapsed time on updated coarse timer",
112 CPPUNIT_ASSERT_EQUAL_MESSAGE(
113 "wrong iteration after updating across interval time boundary",
118 CPPUNIT_ASSERT_MESSAGE(
119 "stopped coarse timer is running",
122 CPPUNIT_ASSERT_MESSAGE(
123 "stopped coarse timer hit",
126 CPPUNIT_ASSERT_EQUAL_MESSAGE(
127 "stopped coarse timer has non-zero elapsed time",
130 CPPUNIT_ASSERT_EQUAL_MESSAGE(
131 "stopped coarse timer at non-zero iteration",
136 void TimerTest::testFineTimer() {
137 FineTimer timer(0.5f);
138 CPPUNIT_ASSERT_MESSAGE(
139 "fresh fine timer is running",
142 CPPUNIT_ASSERT_MESSAGE(
143 "fresh fine timer hit",
146 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
147 "fresh fine timer with non-zero elapsed time",
148 0.0f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
150 CPPUNIT_ASSERT_EQUAL_MESSAGE(
151 "fresh fine timer at non-zero iteration",
156 CPPUNIT_ASSERT_MESSAGE(
157 "startet fine timer is not running",
160 CPPUNIT_ASSERT_MESSAGE(
161 "started fine timer hit without update",
164 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
165 "started, but not updated fine timer with non-zero elapsed time",
166 0.0f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
168 CPPUNIT_ASSERT_EQUAL_MESSAGE(
169 "started, but not updated fine timer at non-zero iteration",
174 CPPUNIT_ASSERT_MESSAGE(
175 "updated fine timer is not running",
178 CPPUNIT_ASSERT_MESSAGE(
179 "fine timer hit after update, but before it should",
182 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
183 "wrong elapsed time on updated fine timer",
184 0.25f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
186 CPPUNIT_ASSERT_EQUAL_MESSAGE(
187 "wrong iteration on updated fine timer",
192 CPPUNIT_ASSERT_MESSAGE(
193 "fine timer not hit after updating to its exact interval time",
196 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
197 "wrong elapsed time on updated fine timer",
198 0.5f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
200 CPPUNIT_ASSERT_EQUAL_MESSAGE(
201 "wrong iteration on updated fine timer at exact interval time",
206 CPPUNIT_ASSERT_MESSAGE(
207 "fine timer hit after updating from exact interval time to just before the next",
210 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
211 "wrong elapsed time on updated fine timer",
212 0.99f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
214 CPPUNIT_ASSERT_EQUAL_MESSAGE(
215 "wrong iteration after updating fine timer from exact interval time to just before the next",
220 CPPUNIT_ASSERT_MESSAGE(
221 "fine timer not hit after updating across interval time boundary",
224 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
225 "wrong elapsed time on updated fine timer",
226 1.01f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
228 CPPUNIT_ASSERT_EQUAL_MESSAGE(
229 "wrong iteration after updating across interval time boundary",
234 CPPUNIT_ASSERT_MESSAGE(
235 "stopped fine timer is running",
238 CPPUNIT_ASSERT_MESSAGE(
239 "stopped fine timer hit",
242 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
243 "stopped fine timer has non-zero elapsed time",
244 0.0f, timer.Elapsed(), std::numeric_limits<float>::epsilon()
246 CPPUNIT_ASSERT_EQUAL_MESSAGE(
247 "stopped fine timer at non-zero iteration",