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