Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
IPS.cc File Reference

Unit test for IPS utility class. More...

Include dependency graph for IPS.cc:

Classes

class  IPSTests
 Unit Test Class for the IPS. More...

Functions

 TEST_F (IPSTests, DoesNotLeak)
 Check that IPS doesn't leak any memory.
 TEST_F (IPSTests, Leaks)
 This should fail when the –check_for_leaks command line flag is specified.
 TEST_F (IPSTests, IterationCounter)
 Test IPS counting functionality.
 TEST_F (IPSTests, MetricsFunctionality)
 Test IPS metrics accuracy.
 TEST_F (IPSTests, ResetFunction)
 Test the functionality of the reset method.

Detailed Description

Unit test for IPS utility class.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17

Function Documentation

◆ TEST_F() [1/5]

TEST_F ( IPSTests ,
DoesNotLeak  )

Check that IPS doesn't leak any memory.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
79{
80 // Create a new IPS object.
81 IPS* pIPS = new IPS();
82 // Delete object.
83 delete pIPS;
84 // Point to null.
85 pIPS = nullptr;
86}
This util class provides an easy way to keep track of iterations per second for any body of code.
Definition IPS.hpp:30

◆ TEST_F() [2/5]

TEST_F ( IPSTests ,
Leaks  )

This should fail when the –check_for_leaks command line flag is specified.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
96{
97 // Create a new IPS object.
98 IPS* pIPS = new IPS();
99 EXPECT_TRUE(pIPS != nullptr);
100}

◆ TEST_F() [3/5]

TEST_F ( IPSTests ,
IterationCounter  )

Test IPS counting functionality.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
110{
111 // Create a new IPS object.
112 std::unique_ptr<IPS> pIPS = std::make_unique<IPS>();
113
114 // Call tick method, wait 16.666 ms, call tick method.
115 pIPS->Tick();
116 std::this_thread::sleep_for(std::chrono::microseconds(16666));
117 pIPS->Tick();
118
119 // Get the calculated FPS.
120 double dFPS = pIPS->GetExactIPS();
121
122 // Check if FPS is within 5 frames of 60.
123 EXPECT_TRUE(dFPS <= 65 && dFPS >= 55);
124}

◆ TEST_F() [4/5]

TEST_F ( IPSTests ,
MetricsFunctionality  )

Test IPS metrics accuracy.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
134{
135 // Create a new IPS object.
136 std::unique_ptr<IPS> pIPS = std::make_unique<IPS>();
137
138 // Declare a start time, current time, elapsed time.
139 std::chrono::time_point tStartTime = std::chrono::high_resolution_clock::now();
140 std::chrono::time_point tCurrentTime = std::chrono::high_resolution_clock::now();
141 std::chrono::duration<double> tElapsedTime = tCurrentTime - tStartTime;
142
143 // Loop for a second.
144 while (tElapsedTime.count() < 1)
145 {
146 // For the first 500ms, sleep for 2ms per iteration.
147 if (tElapsedTime.count() < 0.5)
148 {
149 // Call tick method.
150 pIPS->Tick();
151
152 // Sleep for 2ms.
153 std::this_thread::sleep_for(std::chrono::milliseconds(2));
154 }
155 // For the next 400ms, sleep for 10ms.
156 else if (tElapsedTime.count() < 0.9)
157 {
158 // Call tick method.
159 pIPS->Tick();
160
161 // Sleep for 2ms.
162 std::this_thread::sleep_for(std::chrono::milliseconds(10));
163 }
164
165 // Update elapsed time.
166 tCurrentTime = std::chrono::high_resolution_clock::now();
167 tElapsedTime = tCurrentTime - tStartTime;
168 }
169
170 // Retrieve IPS stats.
171 double dAverage = pIPS->GetAverageIPS();
172 double dHigh = pIPS->GetHighestIPS();
173 double dLow = pIPS->GetLowestIPS();
174 double d1Percent = pIPS->Get1PercentLow();
175
176 // Test that the returned average makes sense.
177 EXPECT_TRUE(dAverage <= dHigh && dAverage >= dLow);
178 // Test that the returned minimum makes sense.
179 EXPECT_TRUE(dLow >= -1 && dLow <= dHigh);
180 // Test that the returned maximum makes sense.
181 EXPECT_TRUE(dHigh >= dLow);
182 // Test that the returned 1% low makes sense.
183 EXPECT_TRUE(d1Percent <= dHigh && d1Percent >= dLow);
184}

◆ TEST_F() [5/5]

TEST_F ( IPSTests ,
ResetFunction  )

Test the functionality of the reset method.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
194{
195 // Create a new IPS object.
196 std::unique_ptr<IPS> pIPS = std::make_unique<IPS>();
197
198 // Call tick method, wait 16.666 ms, call tick method.
199 pIPS->Tick();
200 std::this_thread::sleep_for(std::chrono::microseconds(16666));
201 pIPS->Tick();
202
203 // Get the calculated values and check that they are not equal to zero.
204 EXPECT_NE(pIPS->GetAverageIPS(), 0);
205 EXPECT_NE(pIPS->GetHighestIPS(), 0);
206 EXPECT_NE(pIPS->GetLowestIPS(), 9999999);
207 EXPECT_NE(pIPS->Get1PercentLow(), 0);
208
209 // Reset the counter.
210 pIPS->Reset();
211
212 // Get the calculated values and check that they are equal to zero.
213 EXPECT_EQ(pIPS->GetAverageIPS(), 0);
214 EXPECT_EQ(pIPS->GetHighestIPS(), 0);
215 EXPECT_EQ(pIPS->GetLowestIPS(), 9999999);
216 EXPECT_EQ(pIPS->Get1PercentLow(), 0);
217}