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