Ocean
Loading...
Searching...
No Matches
TestNumeric.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TEST_TESTMATH_NUMERIC_H
9#define META_OCEAN_TEST_TESTMATH_NUMERIC_H
10
12
14
15#include "ocean/math/Numeric.h"
16
17namespace Ocean
18{
19
20namespace Test
21{
22
23namespace TestMath
24{
25
26/**
27 * This class implements a test for the numeric class for the math library.
28 * @ingroup testmath
29 */
30class OCEAN_TEST_MATH_EXPORT TestNumeric
31{
32 public:
33
34 /**
35 * Tests numeric math functions.
36 * @param testDuration Number of seconds for each test, with range (0, infinity)
37 * @param selector The test selector
38 * @return True, if succeeded
39 */
40 static bool test(const double testDuration, const TestSelector& selector);
41
42 /**
43 * Tests the eps() function.
44 * @return True, if succeeded
45 */
46 static bool testEps();
47
48 /**
49 * Tests the weakEps() function.
50 * @return True, if succeeded
51 */
52 static bool testWeakEps();
53
54 /**
55 * Tests the isEqual function with dynamic epsilon values.
56 * @return True, if succeeded
57 */
58 static bool testIsEqualDynamic();
59
60 /**
61 * Tests the round function.
62 * @return True, if succeeded
63 */
64 static bool testRound();
65
66 /**
67 * Tests the angle conversion functions.
68 * @param testDuration Number of seconds for each test, with range (0, infinity)
69 * @return True, if succeeded
70 * @tparam T The data type to be used
71 */
72 template <typename T>
73 static bool testAngleConversion(const double testDuration);
74
75 /**
76 * Tests the angle adjust function with positive range.
77 * @param testDuration Number of seconds for each test, with range (0, infinity)
78 * @return True, if succeeded
79 */
80 static bool testAngleAdjustPositive(const double testDuration);
81
82 /**
83 * Tests the angle adjust function with range around the zero angle.
84 * @param testDuration Number of seconds for each test, with range (0, infinity)
85 * @return True, if succeeded
86 */
87 static bool testAngleAdjustNull(const double testDuration);
88
89 /**
90 * Tests the is equal function for angles.
91 * @param testDuration Number of seconds for each test, with range (0, infinity)
92 * @return True, if succeeded
93 */
94 static bool testAngleIsEqual(const double testDuration);
95
96 /**
97 * Tests the below threshold function for angles.
98 * @param testDuration Number of seconds for each test, with range (0, infinity)
99 * @return True, if succeeded
100 */
101 static bool testAngleIsBelowThreshold(const double testDuration);
102
103 /**
104 * Tests the gaussian distribution 1D function.
105 * @param testDuration Number of seconds for each test, with range (0, infinity)
106 * @return True, if succeeded
107 */
108 static bool testGaussianDistribution1(const double testDuration);
109
110 /**
111 * Tests the Gaussian distribution 2D function.
112 * @param testDuration Number of seconds for each test, with range (0, infinity)
113 * @return True, if succeeded
114 */
115 static bool testGaussianDistribution2(const double testDuration);
116
117 /**
118 * Tests the Gaussian distribution 3D function.
119 * @param testDuration Number of seconds for each test, with range (0, infinity)
120 * @return True, if succeeded
121 */
122 static bool testGaussianDistribution3(const double testDuration);
123
124 /**
125 * Tests the abs function.
126 * @return True, if succeeded
127 */
128 static bool testAbs();
129
130 /**
131 * Tests the secure abs function.
132 * @return True, if succeeded
133 */
134 static bool testSecureAbs();
135
136 /**
137 * Tests the floor function.
138 * @param testDuration Number of seconds for each test, with range (0, infinity)
139 * @return True, if succeeded
140 */
141 static bool testFloor(const double testDuration);
142
143 /**
144 * Tests the ceil function.
145 * @param testDuration Number of seconds for each test, with range (0, infinity)
146 * @return True, if succeeded
147 */
148 static bool testCeil(const double testDuration);
149
150 /**
151 * Tests the log2 function.
152 * @param testDuration Number of seconds for each test, with range (0, infinity)
153 * @return True, if succeeded
154 */
155 static bool testLog2(const double testDuration);
156
157 /**
158 * Tests the dot product function.
159 * @param testDuration Number of seconds for each test, with range (0, infinity)
160 * @return True, if succeeded
161 * @tparam T The data type of the individual vector elements
162 */
163 template <typename T>
164 static bool testDotProduct(const double testDuration);
165
166 /**
167 * Tests the sign function.
168 * @param testDuration Number of seconds for each test, with range (0, infinity)
169 * @return True, if succeeded
170 */
171 static bool testSign(const double testDuration);
172
173 /**
174 * Tests the copySign function.
175 * @return True, if succeeded
176 */
177 static bool testCopySign();
178
179 /**
180 * Tests the invertSign function.
181 * @return True, if succeeded
182 */
183 static bool testInvertSign();
184
185 /**
186 * Tests the invertSign function.
187 * @return True, if succeeded
188 */
189 static bool testFactorial();
190
191 /**
192 * Tests the isNan function.
193 * @param testDuration Number of seconds for each test, with range (0, infinity)
194 * @return True, if succeeded
195 * @tparam T The data type to be used when testing
196 */
197 template <typename T>
198 static bool testIsNan(const double testDuration);
199
200 /**
201 * Tests the isInf function.
202 * @param testDuration Number of seconds for each test, with range (0, infinity)
203 * @return True, if succeeded
204 * @tparam T The data type to be used when testing
205 */
206 template <typename T>
207 static bool testIsInf(const double testDuration);
208
209 /**
210 * Tests the pow function.
211 * @return True, if succeeded
212 */
213 static bool testPow();
214
215 /**
216 * Tests the isInsideValueRange() function.
217 * @param testDuration Number of seconds for each test, with range (0, infinity)
218 * @return True, if succeeded
219 */
220 static bool testIsInsideValueRange(const double testDuration);
221
222 private:
223
224 /**
225 * Tests the dot product function with specific vector size.
226 * @param testDuration Number of seconds for each test, with range (0, infinity)
227 * @return True, if succeeded
228 * @tparam T The data type of the individual vector elements
229 * @tparam tSize The size of the vector, with range [1, infinity)
230 */
231 template <typename T, size_t tSize>
232 static bool testDotProduct(const double testDuration);
233
234 /**
235 * Standard implementation of a dot between two vectors.
236 * @param vectorA The first vector to be used
237 * @param vectorB The second vector to be used
238 * @param size The number of elements each vector holds, with range [0, infinity)
239 * @return The resulting dot product
240 * @tparam T The data type of the elements
241 */
242 template <typename T>
243 static OCEAN_FORCE_INLINE T dotProduct(const T* vectorA, const T* vectorB, const size_t size);
244
245 /**
246 * Verifies the insideValueRange() function based on a cast to a double value.
247 * @param value The value to be checked
248 * @return True, if succeeded
249 * @tparam T The data type of the value range
250 * @tparam TValue The value
251 */
252 template <typename T, typename TValue>
253 static bool verifyInsideValueRangeWithCast(const TValue value);
254};
255
256template <typename T>
257OCEAN_FORCE_INLINE T TestNumeric::dotProduct(const T* vectorA, const T* vectorB, const size_t size)
258{
259 T result = T(0);
260
261 for (size_t n = 0; n < size; ++n)
262 {
263 result += vectorA[n] * vectorB[n];
264 }
265
266 return result;
267}
268
269}
270
271}
272
273}
274
275#endif // META_OCEAN_TEST_TESTMATH_NUMERIC_H
This class implements a test for the numeric class for the math library.
Definition TestNumeric.h:31
static bool testCopySign()
Tests the copySign function.
static bool testRound()
Tests the round function.
static bool testIsEqualDynamic()
Tests the isEqual function with dynamic epsilon values.
static bool testAbs()
Tests the abs function.
static bool test(const double testDuration, const TestSelector &selector)
Tests numeric math functions.
static bool testPow()
Tests the pow function.
static bool testIsInf(const double testDuration)
Tests the isInf function.
static bool testSecureAbs()
Tests the secure abs function.
static bool verifyInsideValueRangeWithCast(const TValue value)
Verifies the insideValueRange() function based on a cast to a double value.
static OCEAN_FORCE_INLINE T dotProduct(const T *vectorA, const T *vectorB, const size_t size)
Standard implementation of a dot between two vectors.
Definition TestNumeric.h:257
static bool testLog2(const double testDuration)
Tests the log2 function.
static bool testAngleIsBelowThreshold(const double testDuration)
Tests the below threshold function for angles.
static bool testInvertSign()
Tests the invertSign function.
static bool testDotProduct(const double testDuration)
Tests the dot product function.
static bool testGaussianDistribution2(const double testDuration)
Tests the Gaussian distribution 2D function.
static bool testGaussianDistribution3(const double testDuration)
Tests the Gaussian distribution 3D function.
static bool testAngleAdjustNull(const double testDuration)
Tests the angle adjust function with range around the zero angle.
static bool testCeil(const double testDuration)
Tests the ceil function.
static bool testAngleConversion(const double testDuration)
Tests the angle conversion functions.
static bool testAngleIsEqual(const double testDuration)
Tests the is equal function for angles.
static bool testEps()
Tests the eps() function.
static bool testFactorial()
Tests the invertSign function.
static bool testIsNan(const double testDuration)
Tests the isNan function.
static bool testDotProduct(const double testDuration)
Tests the dot product function with specific vector size.
static bool testIsInsideValueRange(const double testDuration)
Tests the isInsideValueRange() function.
static bool testSign(const double testDuration)
Tests the sign function.
static bool testWeakEps()
Tests the weakEps() function.
static bool testGaussianDistribution1(const double testDuration)
Tests the gaussian distribution 1D function.
static bool testFloor(const double testDuration)
Tests the floor function.
static bool testAngleAdjustPositive(const double testDuration)
Tests the angle adjust function with positive range.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
The namespace covering the entire Ocean framework.
Definition Accessor.h:15