testVShowerFileParticleIterator.cc
Go to the documentation of this file.
1 
11 #include <string>
12 
13 #include <cppunit/extensions/HelperMacros.h>
14 
16 
17 #include <utl/VShowerFileParticleIterator.h>
18 #include <utl/CoordinateSystem.h>
19 #include <utl/ShowerParticleIterator.h>
20 #include <utl/Particle.h>
21 #include <utl/Point.h>
22 #include <utl/TimeInterval.h>
23 #include <utl/Vector.h>
24 #include <utl/AugerException.h>
25 #include <tst/Verify.h>
26 
27 using namespace utl;
28 using namespace tst;
29 
30 
34 class testVShowerFileParticleIterator : public CppUnit::TestFixture
35 {
36  CPPUNIT_TEST_SUITE(testVShowerFileParticleIterator);
37  CPPUNIT_TEST(testConstruction);
38  CPPUNIT_TEST(testGetParticles);
39  CPPUNIT_TEST_EXCEPTION(testUninitialisedException, utl::IOFailureException);
40  CPPUNIT_TEST_EXCEPTION(testGetTooMany, utl::IOFailureException);
41  //CPPUNIT_TEST(testSetExternalShowerCS);
42  //CPPUNIT_TEST_EXCEPTION(testGetExternalShowerCSUnset,
43  // utl::IOFailureException);
44  CPPUNIT_TEST(testWithSkip);
45  CPPUNIT_TEST(testWithSkipAll);
46  CPPUNIT_TEST_SUITE_END();
47 
48 private:
52  unsigned int fInserted;
54 
55 public:
56  void setUp()
57  {
59  addParticles(*fIter);
60  fShowerParticleIterator1 = new ShowerParticleIterator;
61  fShowerParticleIterator2 = new ShowerParticleIterator;
62  fCS = utl::CoordinateSystem::GetRootCoordinateSystem();
63  }
64 
65  void tearDown()
66  {
67  delete fIter;
68  delete fShowerParticleIterator1;
69  delete fShowerParticleIterator2;
70  }
71 
73  {
74  Particle* p =
76  utl::Point(0, 0, 0,
77  utl::CoordinateSystem::GetRootCoordinateSystem()),
78  utl::Vector(0, 0, 0,
79  utl::CoordinateSystem::GetRootCoordinateSystem()),
80  utl::TimeInterval(0.0), 0.0, 0.0);
81  where.AddParticle(*p);
82  delete p;
83  ++fInserted;
84  }
85 
87  {
88  fInserted = 0;
89  addParticle(where);
90  addParticle(where);
91  addParticle(where);
92  addParticle(where);
93  addParticle(where);
94  }
95 
97  {
98  CPPUNIT_ASSERT(fIter !=0);
99  }
100 
102  {
103  fIter->GetOneParticle(fCS);
104  }
105 
107  {
108  fIter->Rewind();
109  unsigned int count = 0;
110  while (fIter->GetOneParticle(fCS)) count++;
111  CPPUNIT_ASSERT(Verify<Equal>(count, fInserted));
112  }
113 
115  {
116  int count = 10000; // large but finite to avoid an infinit loop
117  // in case Rewind is implemented wrongly.
118  fIter->Rewind();
119  while (count--) fIter->GetOneParticle(fCS);
120  }
121 
122  /*
123  void testSetExternalShowerCS()
124  {
125  CoordinateSystemPtr cs(utl::CoordinateSystem::GetRootCoordinateSystem());
126  fIter->SetExternalShowerCoordinateSystem(cs);
127  CPPUNIT_ASSERT(Verify<Equal>(fIter->GetExternalShowerCoordinateSystem(),
128  cs));
129  }
130 
131  void testGetExternalShowerCSUnset()
132  {
133  CoordinateSystemPtr cs;
134  cs = fIter->GetExternalShowerCoordinateSystem();
135  }
136  */
137 
139  {
140  const unsigned int toSkip = 2;
142  addParticles(t);
143  t.Rewind();
144  unsigned int count = 0;
145  while (t.GetOneParticle(fCS))
146  ++count;
147  CPPUNIT_ASSERT(Verify<Equal>(count, fInserted - toSkip));
148  }
149 
151  {
152  const unsigned int toSkip = fInserted;
154  addParticles(t);
155  t.Rewind();
156  CPPUNIT_ASSERT(!t.GetOneParticle(fCS));
157  }
158 
159 };
160 
162 
163 // Configure (x)emacs for this file ...
164 // Local Variables:
165 // mode:c++
166 // compile-command: "make -C .. -k run-testVShowerFileParticleIterator"
167 // End:
Iterator to retrieve particles from utl::VShowerParticlList.
Point object.
Definition: Point.h:32
testShowerFileParticleIterator * fIter
Describes a particle for Simulation.
Definition: Particle.h:26
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
Base class to report exceptions in IO.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
void addParticles(testShowerFileParticleIterator &where)
virtual void Rewind()
Rewind the particle list in the shower file to the beginning.
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
virtual utl::Particle * GetOneParticle(const utl::CoordinateSystemPtr &cs)
Member function to fetch the next particle.
void addParticle(testShowerFileParticleIterator &where)
Vector object.
Definition: Vector.h:30

, generated on Tue Sep 26 2023.