testShowerParticleIterator.cc
Go to the documentation of this file.
1 
11 #include <utl/ShowerParticleIterator.h>
12 
14 
15 #include <utl/AugerException.h>
16 #include <utl/CoordinateSystem.h>
17 #include <utl/Point.h>
18 #include <utl/Vector.h>
19 
20 #include <string>
21 #include <iterator>
22 #include <algorithm>
23 #include <memory>
24 
25 #include <cppunit/extensions/HelperMacros.h>
26 
27 using std::vector;
28 using utl::Particle;
30 
31 
35 bool
36 CompareNames(const Particle& p1, const Particle& p2)
37 {
38  return p1.GetName() == p2.GetName();
39 }
40 
41 
45 class TestShowerParticleIterator : public CppUnit::TestFixture
46 {
63 
64 private:
67 
69 
70  vector<Particle> fInsertedParticles;
71  vector<Particle> fRetrievedParticles;
72 
73  void
75  {
77  utl::Point(0, 0, 0,
78  utl::CoordinateSystem::GetRootCoordinateSystem()),
79  utl::Vector(0, 0, 0,
80  utl::CoordinateSystem::GetRootCoordinateSystem()),
81  utl::TimeInterval(0.0), 0.0, 0.0);
82  where.AddParticle(p);
83  fInsertedParticles.push_back(p);
84  }
85 
86  void
88  {
89  fInsertedParticles.clear();
90  AddParticle(where);
91  AddParticle(where);
92  AddParticle(where);
93  AddParticle(where); // on purpose not "e"
94  AddParticle(where);
95  }
96 public:
97  void
99  {
104  }
105 
106  void
108  {
109  delete fEnd;
110  delete fCurrent;
111  delete fFileIterator;
112  }
113 
114  void
116  {
117  CPPUNIT_ASSERT(*fCurrent != *fEnd);
119  CPPUNIT_ASSERT(*fEnd == s);
121  CPPUNIT_ASSERT(*fCurrent == iter);
122  ++iter;
123  CPPUNIT_ASSERT(*fCurrent != iter);
124  CPPUNIT_ASSERT(*fEnd != iter);
125  }
126 
127  void
129  {
130  Particle p = **fEnd;
131  }
132 
133  void
135  {
136  ++(*fEnd);
137  }
138 
139  void
141  {
142  int count = 10000; // avoid infinte loop
143 
144  while (*fCurrent != *fEnd && count) {
145  --count;
146  ++(*fCurrent);
147  }
148 
149  ++(*fCurrent);
150  }
151 
152  void
154  {
155  int count = 10000; // avoid infinte loop
156 
157  while (*fCurrent != *fEnd && count) {
158  --count;
159  ++(*fCurrent);
160  }
161 
162  CPPUNIT_ASSERT(count != 0);
163  Particle p = **fCurrent;
164  }
165 
166  void
168  {
169  vector<Particle>::iterator cur = fInsertedParticles.begin();
170  vector<Particle>::iterator end = fInsertedParticles.end();
171  while (*fCurrent != *fEnd && cur != end) {
172  CPPUNIT_ASSERT((*fCurrent)->GetName() == cur->GetName());
173  CPPUNIT_ASSERT((**fCurrent).GetName() == cur->GetName());
174  ++ *fCurrent;
175  ++ cur;
176  }
177  CPPUNIT_ASSERT(*fCurrent == *fEnd);
178  CPPUNIT_ASSERT(cur == end);
179  }
180 
181  void
183  {
184  vector<Particle>::iterator cur1 = fInsertedParticles.begin();
185  vector<Particle>::iterator end = fInsertedParticles.end();
186 
187  while (*fCurrent != *fEnd && cur1 != end) {
188  CPPUNIT_ASSERT((*fCurrent)->GetName() == cur1->GetName());
189  CPPUNIT_ASSERT((**fCurrent).GetName() == cur1->GetName());
190  ++ *fCurrent;
191  ++ cur1;
192  }
193  CPPUNIT_ASSERT(*fCurrent == *fEnd);
194  CPPUNIT_ASSERT(cur1 == end);
195 
197  vector<Particle>::iterator cur2 = fInsertedParticles.begin();
198  while (iter2 != *fEnd && cur2 != end) {
199  CPPUNIT_ASSERT((iter2)->GetName() == cur2->GetName());
200  CPPUNIT_ASSERT((*iter2).GetName() == cur2->GetName());
201  ++ iter2;
202  ++ cur2;
203  }
204  CPPUNIT_ASSERT(iter2 == *fEnd);
205  CPPUNIT_ASSERT(cur2 == end);
206  }
207 
208  void
210  {
211  std::copy(*fCurrent, *fEnd,
212  std::back_insert_iterator<vector<Particle> > (fRetrievedParticles));
213  CPPUNIT_ASSERT(fRetrievedParticles.size() == fInsertedParticles.size());
214  }
215 
216  void
218  {
219  vector<Particle>::iterator cur = fInsertedParticles.begin();
220  CPPUNIT_ASSERT(std::equal(*fCurrent, *fEnd, cur, CompareNames));
221  }
222 
223  void
225  {
227  ShowerParticleIterator it(&t);
228 
229  CPPUNIT_ASSERT(it == *fEnd);
230  }
231 
232  void
234  {
236  AddParticles(t);
237  ShowerParticleIterator it(&t);
238 
239  CPPUNIT_ASSERT(it == *fEnd);
240  }
241 
242  void
244  {
246  ShowerParticleIterator it(&t);
247 
248  *it;
249  }
250 
251  void
253  {
255  AddParticles(t);
256  ShowerParticleIterator it(&t);
257 
258  *it;
259  }
260 
261 };
262 
263 
265 
266 
267 // Configure (x)emacs for this file ...
268 // Local Variables:
269 // mode: c++
270 // compile-command: "make -C .. -k run-testShowerParticleIterator"
271 // End:
Iterator to retrieve particles from utl::VShowerParticlList.
CPPUNIT_TEST_SUITE(TestShowerParticleIterator)
Point object.
Definition: Point.h:32
void AddParticle(testShowerFileParticleIterator &where)
CPPUNIT_TEST(TestComparison)
std::string GetName() const
string with particle name
Definition: Particle.h:104
Describes a particle for Simulation.
Definition: Particle.h:26
CPPUNIT_TEST_EXCEPTION(TestDereferenceEmpty, utl::InvalidIteratorException)
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
testShowerFileParticleIterator * fFileIterator
constexpr double s
Definition: AugerUnits.h:163
bool CompareNames(const Particle &p1, const Particle &p2)
void AddParticles(testShowerFileParticleIterator &where)
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
Exception for invalid operation on Iterators.
Vector object.
Definition: Vector.h:30

, generated on Tue Sep 26 2023.