Ocean
Loading...
Searching...
No Matches
TestInheritance.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_TESTBASE_TEST_INHERITANCE_H
9#define META_OCEAN_TEST_TESTBASE_TEST_INHERITANCE_H
10
13
14#include <cmath>
15
16namespace Ocean
17{
18
19namespace Test
20{
21
22namespace TestBase
23{
24
25/**
26 * This class implements an inheritance test of classes.
27 * @ingroup testbase
28 */
29class OCEAN_TEST_BASE_EXPORT TestInheritance
30{
31 private:
32
33 /**
34 * This class implements a standard base class.
35 */
37 {
38 public:
39
40 /**
41 * Creates a new object.
42 */
43 NormalBaseClass() = default;
44
45 /**
46 * Creates a new object.
47 * @param value Value to be assigned to this object
48 */
49 explicit NormalBaseClass(const double value);
50
51 /**
52 * Destructs the object.
53 */
54 virtual ~NormalBaseClass() = default;
55
56 /**
57 * Non-constant function.
58 * @param value Function parameter
59 * @return Function result
60 */
61 double baseFunction0(const double value);
62
63 /**
64 * Non-constant function.
65 * @param value Function parameter
66 * @return Function result
67 */
68 double baseFunction1(const double value);
69
70 /**
71 * Constant function.
72 * @param value Function parameter
73 * @return Function result
74 */
75 double constBaseFunction0(const double value) const;
76
77 /**
78 * Constant function.
79 * @param value Function parameter
80 * @return Function result
81 */
82 double constBaseFunction1(const double value) const;
83
84 /**
85 * Inline function.
86 * @param value Function parameter
87 * @return Function result
88 */
89 inline double inlineBaseFunction0(const double value) const;
90
91 /**
92 * Inline function.
93 * @param value Function parameter
94 * @return Function result
95 */
96 inline double inlineBaseFunction1(const double value) const;
97
98 protected:
99
100 /// Object value.
101 double classValue_ = -1.0;
102 };
103
104 /**
105 * This class implements a standard sub class.
106 */
107 class NormalSubClass final : public NormalBaseClass
108 {
109 public:
110
111 /**
112 * Creates a new object.
113 */
114 NormalSubClass() = default;
115
116 /**
117 * Destructs the object.
118 */
119 ~NormalSubClass() override = default;
120
121 /**
122 * Creates a new object.
123 * @param value Value to be assigned
124 */
125 explicit NormalSubClass(const double value);
126
127 /**
128 * Non-constant function.
129 * @param value Function parameter
130 * @return Function result
131 */
132 double subFunction0(const double value);
133
134 /**
135 * Non-constant function.
136 * @param value Function parameter
137 * @return Function result
138 */
139 double subFunction1(const double value);
140
141 /**
142 * Inline function.
143 * @param value Function parameter
144 * @return Function result
145 */
146 inline double inlineSubFunction0(const double value) const;
147
148 /**
149 * Inline function.
150 * @param value Function parameter
151 * @return Function result
152 */
153 inline double inlineSubFunction1(const double value) const;
154 };
155
156
157 /**
158 * This class implements a base class for a diamond derivation.
159 */
161 {
162 public:
163
164 /**
165 * Creates a new object.
166 */
167 DiamondBaseClass() = default;
168
169 /**
170 * Copy constructor.
171 * @param object Object to be copied
172 */
174
175 /**
176 * Creates a new object.
177 * @param value Value to be assigned
178 */
179 explicit DiamondBaseClass(const double value);
180
181 /**
182 * Destructs the object.
183 */
184 virtual ~DiamondBaseClass() = default;
185
186 /**
187 * Constant function.
188 * @param value Function parameter
189 * @return Function result
190 */
191 double baseFunction0(const double value) const;
192
193 /**
194 * Constant function.
195 * @param value Function parameter
196 * @return Function result
197 */
198 double baseFunction1(const double value) const;
199
200 /**
201 * Virtual function.
202 * @param value Function parameter
203 * @return Function result
204 */
205 virtual double virtualFunction0(const double value) const;
206
207 /**
208 * Virtual function.
209 * @param value Function parameter
210 * @return Function result
211 */
212 virtual double virtualFunction1(const double value) const;
213
214 protected:
215
216 /// Object value.
217 double classValue_ = -1.0;
218 };
219
220 /**
221 * This class implements an intermediate sub-class for a diamond derivation.
222 */
223 class DiamondSubClass0 : virtual public DiamondBaseClass
224 {
225 public:
226
227 /**
228 * Creates a new object.
229 */
230 DiamondSubClass0() = default;
231
232 /**
233 * Copy constructor.
234 * @param object Object to be copied
235 */
237
238 /**
239 * Creates a new object.
240 * @param value Value to be assigned
241 */
242 explicit DiamondSubClass0(const double value);
243
244 /**
245 * Destructs the object.
246 */
247 ~DiamondSubClass0() override = default;
248
249 /**
250 * Constant function.
251 * @param value Function parameter
252 * @return Function result
253 */
254 double subFunction0_0(const double value) const;
255
256 /**
257 * Constant function.
258 * @param value Function parameter
259 * @return Function result
260 */
261 double subFunction0_1(const double value) const;
262 };
263
264 /**
265 * This class implements a second intermediate sub-class for a diamond derivation.
266 */
267 class DiamondSubClass1 : virtual public DiamondBaseClass
268 {
269 public:
270
271 /**
272 * Creates a new object.
273 */
274 DiamondSubClass1() = default;
275
276 /**
277 * Copy constructor.
278 * @param object Object to be copied
279 */
281
282 /**
283 * Creates a new object.
284 * @param value Value to be assigned
285 */
286 explicit DiamondSubClass1(const double value);
287
288 /**
289 * Destructs the object.
290 */
291 ~DiamondSubClass1() override = default;
292
293 /**
294 * Constant function.
295 * @param value Function parameter
296 * @return Function result
297 */
298 double subFunction1_0(const double value) const;
299
300 /**
301 * Constant function.
302 * @param value Function parameter
303 * @return Function result
304 */
305 double subFunction1_1(const double value) const;
306
307 /**
308 * Virtual function.
309 * @param value Function parameter
310 * @return Function result
311 */
312 double virtualFunction0(const double value) const override;
313
314 /**
315 * Virtual function.
316 * @param value Function parameter
317 * @return Function result
318 */
319 double virtualFunction1(const double value) const override;
320 };
321
322 /**
323 * This class implements the final subclass for a diamond derivation.
324 */
325 class DiamondSubClass final :
326 public DiamondSubClass0,
327 public DiamondSubClass1
328 {
329 public:
330
331 /**
332 * Creates a new object.
333 */
334 DiamondSubClass() = default;
335
336 /**
337 * Copy constructor.
338 * @param object Object to be copied
339 */
341
342 /**
343 * Creates a new object.
344 * @param value Value to be assigned
345 */
346 explicit DiamondSubClass(const double value);
347
348 /**
349 * Destructs the object.
350 */
351 ~DiamondSubClass() override = default;
352
353 /**
354 * Constant function.
355 * @param value Function parameter
356 * @return Function result
357 */
358 double subFunction0(const double value) const;
359
360 /**
361 * Constant function.
362 * @param value Function parameter
363 * @return Function result
364 */
365 double subFunction1(const double value) const;
366
367 /**
368 * Virtual function.
369 * @param value Function parameter
370 * @return Function result
371 */
372 double virtualFunction0(const double value) const override;
373
374 /**
375 * Virtual function.
376 * @param value Function parameter
377 * @return Function result
378 */
379 double virtualFunction1(const double value) const override;
380 };
381
382 /**
383 * This class implements standard base class defining virtual functions.
384 */
386 {
387 public:
388
389 /**
390 * Creates a new object.
391 */
392 VirtualBaseClass() = default;
393
394 /**
395 * Creates a new object.
396 * @param value Value to be assigned
397 */
398 explicit VirtualBaseClass(const double value);
399
400 /**
401 * Destructs the object.
402 */
403 virtual ~VirtualBaseClass() = default;
404
405 /**
406 * Constant function.
407 * @param value Function parameter
408 * @return Function result
409 */
410 double constFunction0(const double value) const;
411
412 /**
413 * Constant function.
414 * @param value Function parameter
415 * @return Function result
416 */
417 double constFunction1(const double value) const;
418
419 /**
420 * Virtual function.
421 * @param value Function parameter
422 * @return Function result
423 */
424 virtual double virtualBaseFunction0(const double value) const;
425
426 /**
427 * Virtual function.
428 * @param value Function parameter
429 * @return Function result
430 */
431 virtual double virtualBaseFunction1(const double value) const;
432
433 /**
434 * Virtual function.
435 * @param value Function parameter
436 * @return Function result
437 */
438 virtual double virtualFunction0(const double value) const;
439
440 /**
441 * Virtual function.
442 * @param value Function parameter
443 * @return Function result
444 */
445 virtual double virtualFunction1(const double value) const;
446
447 protected:
448
449 /// Object value.
450 double classValue_ = -1.0;
451 };
452
453 /**
454 * This class implements sub-class defining virtual functions.
455 */
457 {
458 public:
459
460 /**
461 * Creates a new object.
462 */
463 VirtualSubClass() = default;
464
465 /**
466 * Creates a new object.
467 * @param value Value to be assigned
468 */
469 explicit VirtualSubClass(const double value);
470
471 /**
472 * Destructs the object.
473 */
474 ~VirtualSubClass() override = default;
475
476 /**
477 * Constant function.
478 * @param value Function parameter
479 * @return Function result
480 */
481 double constFunction0(const double value);
482
483 /**
484 * Constant function.
485 * @param value Function parameter
486 * @return Function result
487 */
488 double constFunction1(const double value);
489
490 /**
491 * Virtual function.
492 * @param value Function parameter
493 * @return Function result
494 */
495 double virtualFunction0(const double value) const override;
496
497 /**
498 * Virtual function.
499 * @param value Function parameter
500 * @return Function result
501 */
502 double virtualFunction1(const double value) const override;
503 };
504
505 public:
506
507 /**
508 * Tests all inheritance functions.
509 * @param testDuration Number of test seconds, with range (0, infinity)
510 * @param selector Selector for which tests to run
511 * @return True, if succeeded
512 */
513 static bool test(const double testDuration, const TestSelector& selector = TestSelector());
514
515 /**
516 * Tests the performance of the normal class.
517 * @param testDuration Number of test seconds, with range (0, infinity)
518 * @return True, if succeeded
519 */
520 static bool testNormal(const double testDuration);
521
522 /**
523 * Tests the performance of the virtual class.
524 * @param testDuration Number of test seconds, with range (0, infinity)
525 * @return True, if succeeded
526 */
527 static bool testVirtual(const double testDuration);
528
529 /**
530 * Tests the performance of the diamond class.
531 * @param testDuration Number of test seconds, with range (0, infinity)
532 * @return True, if succeeded
533 */
534 static bool testDiamond(const double testDuration);
535};
536
537inline double TestInheritance::NormalBaseClass::inlineBaseFunction0(const double value) const
538{
539 ocean_assert(classValue_ >= 0.0);
540 return sin(classValue_) * cos(value) * sqrt(value);
541}
542
543inline double TestInheritance::NormalBaseClass::inlineBaseFunction1(const double value) const
544{
545 ocean_assert(classValue_ >= 0.0);
546 return sqrt(value) * classValue_;
547}
548
549inline double TestInheritance::NormalSubClass::inlineSubFunction0(const double value) const
550{
551 ocean_assert(classValue_ >= 0.0);
552 return sin(classValue_) * cos(value) * sqrt(value);
553}
554
555inline double TestInheritance::NormalSubClass::inlineSubFunction1(const double value) const
556{
557 ocean_assert(classValue_ >= 0.0);
558 return sqrt(value) * classValue_;
559}
560
561}
562
563}
564
565}
566
567#endif // META_OCEAN_TEST_TESTBASE_TEST_INHERITANCE_H
This class implements a base class for a diamond derivation.
Definition TestInheritance.h:161
DiamondBaseClass(const DiamondBaseClass &object)
Copy constructor.
virtual double virtualFunction0(const double value) const
Virtual function.
double baseFunction1(const double value) const
Constant function.
double baseFunction0(const double value) const
Constant function.
virtual ~DiamondBaseClass()=default
Destructs the object.
DiamondBaseClass(const double value)
Creates a new object.
virtual double virtualFunction1(const double value) const
Virtual function.
This class implements an intermediate sub-class for a diamond derivation.
Definition TestInheritance.h:224
DiamondSubClass0(const DiamondSubClass0 &object)
Copy constructor.
~DiamondSubClass0() override=default
Destructs the object.
double subFunction0_1(const double value) const
Constant function.
double subFunction0_0(const double value) const
Constant function.
DiamondSubClass0(const double value)
Creates a new object.
This class implements a second intermediate sub-class for a diamond derivation.
Definition TestInheritance.h:268
double virtualFunction1(const double value) const override
Virtual function.
double subFunction1_1(const double value) const
Constant function.
DiamondSubClass1(const double value)
Creates a new object.
double subFunction1_0(const double value) const
Constant function.
~DiamondSubClass1() override=default
Destructs the object.
DiamondSubClass1(const DiamondSubClass1 &object)
Copy constructor.
double virtualFunction0(const double value) const override
Virtual function.
This class implements the final subclass for a diamond derivation.
Definition TestInheritance.h:328
~DiamondSubClass() override=default
Destructs the object.
DiamondSubClass(const DiamondSubClass &object)
Copy constructor.
double subFunction1(const double value) const
Constant function.
double virtualFunction0(const double value) const override
Virtual function.
DiamondSubClass(const double value)
Creates a new object.
double virtualFunction1(const double value) const override
Virtual function.
double subFunction0(const double value) const
Constant function.
This class implements a standard base class.
Definition TestInheritance.h:37
NormalBaseClass(const double value)
Creates a new object.
double baseFunction0(const double value)
Non-constant function.
double classValue_
Object value.
Definition TestInheritance.h:101
double constBaseFunction1(const double value) const
Constant function.
double inlineBaseFunction0(const double value) const
Inline function.
Definition TestInheritance.h:537
double inlineBaseFunction1(const double value) const
Inline function.
Definition TestInheritance.h:543
virtual ~NormalBaseClass()=default
Destructs the object.
double baseFunction1(const double value)
Non-constant function.
double constBaseFunction0(const double value) const
Constant function.
This class implements a standard sub class.
Definition TestInheritance.h:108
double inlineSubFunction0(const double value) const
Inline function.
Definition TestInheritance.h:549
NormalSubClass(const double value)
Creates a new object.
double inlineSubFunction1(const double value) const
Inline function.
Definition TestInheritance.h:555
~NormalSubClass() override=default
Destructs the object.
double subFunction1(const double value)
Non-constant function.
double subFunction0(const double value)
Non-constant function.
This class implements standard base class defining virtual functions.
Definition TestInheritance.h:386
double constFunction1(const double value) const
Constant function.
virtual ~VirtualBaseClass()=default
Destructs the object.
virtual double virtualBaseFunction0(const double value) const
Virtual function.
VirtualBaseClass(const double value)
Creates a new object.
virtual double virtualFunction1(const double value) const
Virtual function.
double constFunction0(const double value) const
Constant function.
virtual double virtualFunction0(const double value) const
Virtual function.
virtual double virtualBaseFunction1(const double value) const
Virtual function.
This class implements sub-class defining virtual functions.
Definition TestInheritance.h:457
double virtualFunction0(const double value) const override
Virtual function.
~VirtualSubClass() override=default
Destructs the object.
double virtualFunction1(const double value) const override
Virtual function.
double constFunction1(const double value)
Constant function.
VirtualSubClass(const double value)
Creates a new object.
double constFunction0(const double value)
Constant function.
This class implements an inheritance test of classes.
Definition TestInheritance.h:30
static bool testNormal(const double testDuration)
Tests the performance of the normal class.
static bool test(const double testDuration, const TestSelector &selector=TestSelector())
Tests all inheritance functions.
static bool testVirtual(const double testDuration)
Tests the performance of the virtual class.
static bool testDiamond(const double testDuration)
Tests the performance of the diamond class.
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