testShowerParticleList.cc
Go to the documentation of this file.
1 
12 #include <utl/ShowerParticleList.h>
13 #include <utl/ShowerParticleIterator.h>
15 
16 #include <utl/CoordinateSystem.h>
17 #include <utl/Point.h>
18 #include <utl/Vector.h>
19 #include <utl/AugerException.h>
20 
21 #include <tst/Verify.h>
22 
23 #include <cppunit/extensions/HelperMacros.h>
24 
25 using namespace utl;
26 using namespace tst;
27 using std::vector;
28 
29 
33 static bool compareNames(const Particle& p1, const Particle& p2)
34 {
35  return p1.GetName() == p2.GetName();
36 }
37 
38 
42 class testShowerParticleList : public CppUnit::TestFixture
43 {
44  CPPUNIT_TEST_SUITE(testShowerParticleList);
45  CPPUNIT_TEST(testConstruction);
46  CPPUNIT_TEST(testSettingInterface);
47  CPPUNIT_TEST(testSize);
48  CPPUNIT_TEST(testSTLEqualInitialised);
49  CPPUNIT_TEST(testSTLEqual);
50  CPPUNIT_TEST_SUITE_END();
51 private:
55 
57 
58  vector <Particle> fInsertedParticles;
59 
60  void addParticle(const std::string& /*name*/)
61  {
63  utl::Point(0, 0, 0,
64  utl::CoordinateSystem::GetRootCoordinateSystem()),
65  utl::Vector(0, 0, 0,
66  utl::CoordinateSystem::GetRootCoordinateSystem()),
67  utl::TimeInterval(0.0), 0.0, 0.0);
68  fFileIterator->AddParticle(p);
69  fInsertedParticles.push_back(p);
70  }
71 
72 public:
73  void setUp()
74  {
75  fCS = utl::CoordinateSystem::GetRootCoordinateSystem();
76  fFileIterator = new testShowerFileParticleIterator;
77  addParticle("a");
78  addParticle("b");
79  addParticle("c");
80  addParticle("f"); // on purpose not "e"
81  addParticle("d");
82  fParticleList = new ShowerParticleList();
83  fInitialisedParticleList = new ShowerParticleList(fFileIterator);
84  }
85 
86  void tearDown()
87  {
88  delete fInitialisedParticleList;
89  delete fParticleList;
90  delete fFileIterator;
91  }
92 
94  {
95  CPPUNIT_ASSERT(fParticleList->ParticlesBegin(fCS) == fParticleList->ParticlesEnd(fCS));
96  CPPUNIT_ASSERT(fInitialisedParticleList->ParticlesBegin(fCS) != fInitialisedParticleList->ParticlesEnd(fCS));
97  }
98 
100  {
101  CPPUNIT_ASSERT(fParticleList->ParticlesBegin(fCS) == fParticleList->ParticlesEnd(fCS));
102  fParticleList->SetFileInterface(fFileIterator);
103  CPPUNIT_ASSERT(fParticleList->ParticlesBegin(fCS) != fParticleList->ParticlesEnd(fCS));
104  fParticleList->SetFileInterface(0);
105  CPPUNIT_ASSERT(fParticleList->ParticlesBegin(fCS) == fParticleList->ParticlesEnd(fCS));
106  }
107 
108  void testSize()
109  {
110  CPPUNIT_ASSERT(std::distance(fInitialisedParticleList->ParticlesBegin(fCS), fInitialisedParticleList->ParticlesEnd(fCS)) == int(fInsertedParticles.size()));
111 
112  fParticleList->SetFileInterface(fFileIterator);
113  CPPUNIT_ASSERT(std::distance(fParticleList->ParticlesBegin(fCS), fParticleList->ParticlesEnd(fCS)) == int(fInsertedParticles.size()));
114  }
115 
117  {
118  vector<Particle>::iterator cur = fInsertedParticles.begin();
119 
120  CPPUNIT_ASSERT(std::equal(fInitialisedParticleList->ParticlesBegin(fCS), fInitialisedParticleList->ParticlesEnd(fCS), cur, compareNames));
121  }
122 
124  {
125  vector<Particle>::iterator cur = fInsertedParticles.begin();
126 
127  CPPUNIT_ASSERT(std::equal(fParticleList->ParticlesBegin(fCS), fParticleList->ParticlesEnd(fCS), cur, compareNames));
128  }
129 
130 };
131 
133 
134 // Configure (x)emacs for this file ...
135 // Local Variables:
136 // mode:c++
137 // compile-command: "make -C .. -k run-testShowerParticleList"
138 // End:
Point object.
Definition: Point.h:32
std::string GetName() const
string with particle name
Definition: Particle.h:104
Describes a particle for Simulation.
Definition: Particle.h:26
ShowerParticleList * fParticleList
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
static bool compareNames(const Particle &p1, const Particle &p2)
vector< Particle > fInsertedParticles
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
Vector object.
Definition: Vector.h:30
ShowerParticleList * fInitialisedParticleList
testShowerFileParticleIterator * fFileIterator
void addParticle(const std::string &)
Interface class for accessing a list of particles from a shower file.

, generated on Tue Sep 26 2023.