Helios++
Helios software for LiDAR simulations
NoiseTest.h
1 #pragma once
2 
3 #include <noise/NormalNoiseSource.h>
4 #include <noise/UniformNoiseSource.h>
5 
6 namespace HeliosTests{
7 
8 
14 class NoiseTest : public BaseTest {
15 public:
16  // *** CONSTRUCTION *** //
17  // ********************** //
21  NoiseTest() : BaseTest("Noise sources test"){}
22 
23  // *** R U N *** //
24  // *************** //
28  bool run() override;
29 };
30 
32  // Randomness generators
35 
36  // Noise sources
42  NormalNoiseSource<double> nns1(rg1);
43  NormalNoiseSource<double> nns2(rg2);
44  NormalNoiseSource<double> nns3(rg1);
45  NormalNoiseSource<double> nns4(rg1);
46 
47 
48  // Configuration
49  uns3.setFixedLifespan(3); // Fixed, renew each 3 uses
50  uns4.setFixedLifespan(0); // Fixed, eternal
51  uns4.fixedRenew();
52  uns5.configureUniformNoise(-3, 3);
53 
54  // Vars
55  double cache;
56 
57 
58  // Noise tests
59  if(uns1.next()!=uns3.next()) return false;
60  if(uns2.next()==uns3.next()) return false;
61  if(uns3.next()!=uns4.next()) return false;
62  if(uns1.next()!=uns3.next()) return false;
63  if(uns1.next()==uns3.next()) return false;
64  if(nns4.next()==uns4.next()) return false;
65  if(nns4.next()==nns4.next()) return false;
66  if(uns2.next()==uns2.next()) return false;
67 
68  cache = uns4.next();
69  if(uns4.next()!=cache) return false;
70  uns4.fixedRenew();
71  if(uns4.next()==cache) return false;
72  if(uns4.next()!=uns4.next()) return false;
73 
74  nns1.configureNormalNoise(4.0, 2.0);
75  nns3.configureNormalNoise(4.0, 2.0);
76  if(nns1.next()!=nns3.next()) return false;
77  nns1.next();
78  if(nns1.next()==nns3.next()) return false;
79 
80  for(size_t i = 0 ; i < 32 ; i++){
81  cache = uns5.next();
82  if(cache < -3.0 || cache > 3.0) return false;
83  }
84  uns5.setClipEnabled(true).setClipMin(-1.0).setClipMax(1.0); // Enable clip
85  for(size_t i = 0 ; i < 32 ; i++){
86  cache = uns5.next();
87  if(cache < -1.0 || cache > 1.0) return false;
88  }
89 
90  // Copy-move tests
91  UniformNoiseSource<double> uns1c = uns1;
92  if(uns1.next() != uns1c.next()) return false;
93  uns1c.next();
94  if(uns1.next() == uns1c.next()) return false;
95  uns1.next();
96  UniformNoiseSource<double> uns1m = std::move(uns1c);
97  if(uns1.next() != uns1m.next()) return false;
98  uns1m.next();
99  if(uns1.next() == uns1m.next()) return false;
100  NormalNoiseSource<double> nns1c(nns1);
101  if(nns1.next() != nns1c.next()) return false;
102  nns1c.next();
103  if(nns1.next() == nns1c.next()) return false;
104  nns1.next();
105  NormalNoiseSource<double> nns1m(std::move(nns1c));
106  if(nns1.next() != nns1m.next()) return false;
107  nns1m.next();
108  if(nns1.next() == nns1m.next()) return false;
109 
110 
111  // Successfully reached end of test
112  return true;
113 }
114 
115 }
BaseTest class.
Definition: BaseTest.h:20
Test for noise generation.
Definition: NoiseTest.h:14
NoiseTest()
Noise test constructor.
Definition: NoiseTest.h:21
bool run() override
Definition: NoiseTest.h:31
RealType next()
Obtain the next default noise value.
Definition: NoiseSource.h:258
NoiseSource & setFixedLifespan(unsigned long fixedLifespan)
Set the fixed value lifespan.
Definition: NoiseSource.h:168
NoiseSource & fixedRenew()
Forces a renewal of fixed value and its remaining uses.
Definition: NoiseSource.h:248
NoiseSource & setClipMax(RealType clipMax)
Set the clip max value.
Definition: NoiseSource.h:117
NoiseSource & setClipEnabled(bool clipEnabled)
Enable clipping by setting it to true or disable it by setting to false.
Definition: NoiseSource.h:132
NoiseSource & setClipMin(RealType clipMin)
Set the clip min value.
Definition: NoiseSource.h:102
Class for normal noise handling.
Definition: NormalNoiseSource.h:16
NormalNoiseSource & configureNormalNoise(RealType mean, RealType stdev)
Configure normal noise.
Definition: NormalNoiseSource.h:176
UniformNoiseSource & configureUniformNoise(RealType min, RealType max)
Configure uniform noise.
Definition: UniformNoiseSource.h:184