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
NumberOperations.cc File Reference

Unit test for NumberOperations utility class. More...

Include dependency graph for NumberOperations.cc:

Classes

class  NumOpsTests
 Unit Test Class for the NumberOperations. More...

Functions

 TEST_F (NumOpsTests, Clamp)
 Test the functionality of the Clamp function.
 TEST_F (NumOpsTests, Bounded)
 Test the functionality of the Bounded function.
 TEST_F (NumOpsTests, MapRange)
 Test the functionality of the MapRange function.
 TEST_F (NumOpsTests, InputAngleModulus)
 Test the functionality of the InputAngleModulus function.
 TEST_F (NumOpsTests, AngularDifference)
 Test the functionality of the AngularDifference function.
 TEST_F (NumOpsTests, CoordinateFrameRotate3D)
 Test the functionality of the CoordinateFrameRotate3D function.
 TEST_F (NumOpsTests, CoordinatePoint)
 Test the functionality of the CoordinatePoint structure.

Detailed Description

Unit test for NumberOperations 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/7]

TEST_F ( NumOpsTests ,
Clamp  )

Test the functionality of the Clamp function.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-16
79{
80 // Create array for storing input and expect output values.
81 const int nTestValuesLength = 6;
82 const double aValues[nTestValuesLength] = {1.0, 0.0, 567.0, 0.05, -1.0, -89.3};
83 const double aMinimums[nTestValuesLength] = {0.0, 0.0, -5.0, 0.05, -3.0, 50.0};
84 const double aMaximums[nTestValuesLength] = {2.0, 1.0, 0.0, 0.04, 0.0, -100.0};
85 const double aOutput[nTestValuesLength] = {1.0, 0.0, 0.0, 0.05, -1.0, 50.0};
86
87 // Loop through each value and compare inputs and outputs.
88 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
89 {
90 // Calculate clamp values.
91 double dResult = numops::Clamp(aValues[nIter], aMinimums[nIter], aMaximums[nIter]);
92
93 // Check that the expected output values were calculated.
94 EXPECT_EQ(dResult, aOutput[nIter]); // output check.
95 }
96}
constexpr T Clamp(T tValue, T tMin, T tMax)
Clamps a given value from going above or below a given threshold.
Definition NumberOperations.hpp:81
Here is the call graph for this function:

◆ TEST_F() [2/7]

TEST_F ( NumOpsTests ,
Bounded  )

Test the functionality of the Bounded function.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-16
106{
107 // Create array for storing input and expect output values.
108 const int nTestValuesLength = 6;
109 const double aValues[nTestValuesLength] = {1.0, 0.0, 567.0, 0.05, -1.0, -89.3};
110 const double aMinimums[nTestValuesLength] = {0.0, 0.0, -5.0, 0.05, -3.0, 50.0};
111 const double aMaximums[nTestValuesLength] = {2.0, 1.0, 0.0, 0.04, 0.0, -100.0};
112 const bool aOutput[nTestValuesLength] = {true, true, false, false, true, false};
113
114 // Loop through each value and compare inputs and outputs.
115 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
116 {
117 // Calculate valid bounds.
118 bool bResult = numops::Bounded(aValues[nIter], aMinimums[nIter], aMaximums[nIter]);
119
120 // Check that the expected output values were calculated.
121 EXPECT_EQ(bResult, aOutput[nIter]); // output check.
122 }
123}
bool Bounded(T tValue, T tMin, T tMax, const bool bInclusive=true)
Checks if a given value is between the given maximum and minimum ranges.
Definition NumberOperations.hpp:101
Here is the call graph for this function:

◆ TEST_F() [3/7]

TEST_F ( NumOpsTests ,
MapRange  )

Test the functionality of the MapRange function.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-08-17
133{
134 // Create array for storing input and expect output values.
135 const int nTestValuesLength = 4;
136 const double aValues[nTestValuesLength] = {0.0, -1.0, 2.0, 0};
137 const double aOldMinimums[nTestValuesLength] = {-1.0, -1.0, -4.0, -180};
138 const double aOldMaximums[nTestValuesLength] = {1.0, 1.0, 4.0, 180};
139 const double aNewMinimums[nTestValuesLength] = {0.0, 0.0, -2.0, 0};
140 const double aNewMaximums[nTestValuesLength] = {2.0, 2.0, 2.0, 360};
141 const double aOutput[nTestValuesLength] = {1.0, 0.0, 1.0, 180};
142
143 // Loop through each value and compare inputs and outputs.
144 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
145 {
146 // Calculate valid bounds.
147 double dResult = numops::MapRange(aValues[nIter], aOldMinimums[nIter], aOldMaximums[nIter], aNewMinimums[nIter], aNewMaximums[nIter]);
148
149 // Check that the expected output values were calculated.
150 EXPECT_EQ(dResult, aOutput[nIter]);
151 }
152}
constexpr T MapRange(const T tValue, const T tOldMinimum, const T tOldMaximum, const T tNewMinimum, const T tNewMaximum)
Maps a value to a new range given the old range.
Definition NumberOperations.hpp:131
Here is the call graph for this function:

◆ TEST_F() [4/7]

TEST_F ( NumOpsTests ,
InputAngleModulus  )

Test the functionality of the InputAngleModulus function.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-10-19
162{
163 // Create array for storing input and expect output values.
164 const int nTestValuesLength = 9;
165 const double aValues[nTestValuesLength] = {1.0, -1.0, 4.0, 360.0, 350.0, 170.0, -90, 360.0, -90};
166 const double aMinimums[nTestValuesLength] = {0.0, 0.0, -2.0, -180.0, -180.0, -180.0, 0.0, 0.0, 0.0};
167 const double aMaximums[nTestValuesLength] = {2.0, 2.0, 2.0, 180.0, 180.0, 180.0, 360.0, 360.0, 360.0};
168 const double aOutput[nTestValuesLength] = {1.0, 1.0, 0.0, 0.0, -10.0, 170.0, 270.0, 0.0, 270.0};
169
170 // Loop through each value and compare inputs and outputs.
171 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
172 {
173 // Calculate valid bounds.
174 double dResult = numops::InputAngleModulus(aValues[nIter], aMinimums[nIter], aMaximums[nIter]);
175 // Check that the expected output values were calculated.
176 EXPECT_EQ(dResult, aOutput[nIter]);
177 }
178}
constexpr T InputAngleModulus(T tValue, T tMinValue, T tMaxValue)
Calculates the modulus of an input angle.
Definition NumberOperations.hpp:162
Here is the call graph for this function:

◆ TEST_F() [5/7]

TEST_F ( NumOpsTests ,
AngularDifference  )

Test the functionality of the AngularDifference function.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-04-03
188{
189 // Create array for storing input and expect output values.
190 const int nTestValuesLength = 8;
191 const double aFirstValues[nTestValuesLength] = {0.0, 330.0, 30.0, 270.0, 60.0, 0.0, 170.0, 60.0};
192 const double aSecondValues[nTestValuesLength] = {0.0, 30.0, 330.0, 180.0, 120.0, 360.0, 190.0, 90.0};
193 const double aOutput[nTestValuesLength] = {0.0, 60.0, -60.0, -90.0, 60.0, 0.0, 20.0, 30.0};
194
195 // Loop through each value and compare inputs and outputs.
196 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
197 {
198 // Calculate valid bounds.
199 double dResult = numops::AngularDifference(aFirstValues[nIter], aSecondValues[nIter]);
200
201 // Check that the expected output values were calculated.
202 EXPECT_EQ(dResult, aOutput[nIter]);
203 }
204}
constexpr T AngularDifference(T tFirstValue, T tSecondValue)
Calculates the distance in degrees between two angles. This function accounts for wrap around so that...
Definition NumberOperations.hpp:201
Here is the call graph for this function:

◆ TEST_F() [6/7]

TEST_F ( NumOpsTests ,
CoordinateFrameRotate3D  )

Test the functionality of the CoordinateFrameRotate3D function.

Author
ClayJay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2024-04-03
214{
215 // Create array for storing input and expect output values.
216 const int nTestValuesLength = 8;
217 const double aX[nTestValuesLength] = {607350.5439843171, 15.0, 1.0, 1.0, 1.0, 5.0, 10.0, 420000.0};
218 const double aY[nTestValuesLength] = {314.26934576034546, 10.0, 0.0, 0.0, 0.0, 5.0, 10.0, 315.0};
219 const double aZ[nTestValuesLength] = {4201167.977962418, 40.0, 0.0, 0.0, 0.0, 5.0, 10.0, -65780.0};
220 const double aXRot[nTestValuesLength] = {0.0, 0.0, 90.0, 0.0, 0.0, 90.0, 90.0, 0.0};
221 const double aYRot[nTestValuesLength] = {0.0, 0.0, 0.0, 90.0, 0.0, 90.0, 45.0, 65.4};
222 const double aZRot[nTestValuesLength] = {0.0, 0.0, 0.0, 0.0, 90.0, 90.0, 30.0, 0.0};
223 const double aExpectedX[nTestValuesLength] = {607350.5439843171, 15.0, 1.0, 0.0, 0.0, 5.0, 17.25, 115028.38};
224 const double aExpectedY[nTestValuesLength] = {314.2693457603454, 10.0, 0.0, 0.0, 1.0, 5.0, -1.59, 315.0};
225 const double aExpectedZ[nTestValuesLength] = {4201167.977962418, 40.0, 0.0, -1.0, 0.0, -5.0, 0.0, -409262.11};
226
227 // Loop through each value and compare inputs and outputs.
228 for (int nIter = 0; nIter < nTestValuesLength; ++nIter)
229 {
230 // Pack point cloud vector.
231 std::vector<numops::CoordinatePoint<double>> vPointCloud;
232 vPointCloud.emplace_back(numops::CoordinatePoint(aX[nIter], aY[nIter], aZ[nIter]));
233
234 // Calculate new rotated point.
235 numops::CoordinateFrameRotate3D(vPointCloud, aXRot[nIter], aYRot[nIter], aZRot[nIter]);
236
237 // Check that the expected output values were calculated.
238 EXPECT_NEAR(vPointCloud[0].tX, aExpectedX[nIter], 0.01);
239 EXPECT_NEAR(vPointCloud[0].tY, aExpectedY[nIter], 0.01);
240 EXPECT_NEAR(vPointCloud[0].tZ, aExpectedZ[nIter], 0.01);
241 }
242}
constexpr void CoordinateFrameRotate3D(std::vector< CoordinatePoint< T > > &vPointCloud, const double dXRotationDegrees, const double dYRotationDegrees, const double dZRotationDegrees)
This method will rotate a list of 3D coordinate points a variable amount of degrees around the X,...
Definition NumberOperations.hpp:266
This struct represents a point in a 3D coordinate system.
Definition NumberOperations.hpp:42
Here is the call graph for this function:

◆ TEST_F() [7/7]

TEST_F ( NumOpsTests ,
CoordinatePoint  )

Test the functionality of the CoordinatePoint structure.

Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2025-01-09
251{
252 // Default Constructor Test
253 numops::CoordinatePoint<double> stDefaultPoint;
254 EXPECT_DOUBLE_EQ(stDefaultPoint.tX, 0.0);
255 EXPECT_DOUBLE_EQ(stDefaultPoint.tY, 0.0);
256 EXPECT_DOUBLE_EQ(stDefaultPoint.tZ, 0.0);
257
258 // Parameterized Constructor Test
259 numops::CoordinatePoint<double> stParamPoint(1.5, 2.5, 3.5);
260 EXPECT_DOUBLE_EQ(stParamPoint.tX, 1.5);
261 EXPECT_DOUBLE_EQ(stParamPoint.tY, 2.5);
262 EXPECT_DOUBLE_EQ(stParamPoint.tZ, 3.5);
263
264 // Test with Integer Type
265 numops::CoordinatePoint<int> stIntPoint(1, 2, 3);
266 EXPECT_EQ(stIntPoint.tX, 1);
267 EXPECT_EQ(stIntPoint.tY, 2);
268 EXPECT_EQ(stIntPoint.tZ, 3);
269
270 // Test with Float Type
271 numops::CoordinatePoint<float> stFloatPoint(1.1f, 2.2f, 3.3f);
272 EXPECT_FLOAT_EQ(stFloatPoint.tX, 1.1f);
273 EXPECT_FLOAT_EQ(stFloatPoint.tY, 2.2f);
274 EXPECT_FLOAT_EQ(stFloatPoint.tZ, 3.3f);
275
276 // Test Modifying Values
277 numops::CoordinatePoint<double> stModPoint(1.0, 2.0, 3.0);
278 stModPoint.tX = 4.0;
279 stModPoint.tY = 5.0;
280 stModPoint.tZ = 6.0;
281 EXPECT_DOUBLE_EQ(stModPoint.tX, 4.0);
282 EXPECT_DOUBLE_EQ(stModPoint.tY, 5.0);
283 EXPECT_DOUBLE_EQ(stModPoint.tZ, 6.0);
284}