10 #include <utl/Vector.h>
11 #include <utl/AxialVector.h>
12 #include <utl/TransformationMatrix.h>
13 #include <utl/GeometryException.h>
14 #include <tst/Verify.h>
15 #include <utl/Triple.h>
18 #include <cppunit/extensions/HelperMacros.h>
27 #define TEST_COLLECTION(Type_) \
28 CPPUNIT_TEST_EXCEPTION(testConstructorThrow<Type_>, CoordinateSystemException); \
29 CPPUNIT_TEST(testConstructor<Type_>); \
30 CPPUNIT_TEST(testConstructorCylindrical<Type_>); \
31 CPPUNIT_TEST(testConstructorSpherical<Type_>); \
32 CPPUNIT_TEST_EXCEPTION(testTransformation<Type_>, CoordinateSystemException); \
33 CPPUNIT_TEST(testOperations<Type_>)
45 CPPUNIT_TEST(testNormalize);
46 CPPUNIT_TEST_SUITE_END();
49 template<
class VectorType>
54 const VectorType v(0,0,0, CsNull);
57 template<
class VectorType>
62 const VectorType
p(0,0,0, cs);
64 CPPUNIT_ASSERT(Verify<CloseTo>(p.GetX(cs), 0.));
65 CPPUNIT_ASSERT(Verify<CloseTo>(p.GetY(cs), 0.));
66 CPPUNIT_ASSERT(Verify<CloseTo>(p.GetZ(cs), 0.));
67 CPPUNIT_ASSERT(Verify<CloseTo>(
68 p.GetCoordinates(cs),
Triple(0,0,0)
71 const VectorType q(1,2,3, cs);
72 CPPUNIT_ASSERT(Verify<CloseTo>(q.GetX(cs), 1.));
73 CPPUNIT_ASSERT(Verify<CloseTo>(q.GetY(cs), 2.));
74 CPPUNIT_ASSERT(Verify<CloseTo>(q.GetZ(cs), 3.));
75 CPPUNIT_ASSERT(Verify<CloseTo>(
76 q.GetCoordinates(cs),
Triple(1,2,3)
79 const VectorType x(1,0,0, cs);
80 CPPUNIT_ASSERT(Verify<CloseTo>(
81 x.GetSphericalCoordinates(cs),
Triple(1,M_PI/2,0)
84 const VectorType x2(1,0,0, cs, VectorType::kCartesian);
85 CPPUNIT_ASSERT(Verify<CloseTo>((x-x2).GetR(cs), 0.));
87 const VectorType x3(1,0,0, cs, tst::cartesian<VectorType>());
88 CPPUNIT_ASSERT(Verify<CloseTo>((x-x3).GetR(cs), 0.));
91 template<
class VectorType>
99 const VectorType
p(1,M_PI/4,2, cs, VectorType::kCylindrical);
100 CPPUNIT_ASSERT(Verify<CloseTo>(
101 p.GetCoordinates(cs),
Triple(root2/2,root2/2,2)
104 const VectorType q(1,M_PI/4,2, cs, tst::cylindrical<VectorType>());
105 CPPUNIT_ASSERT(Verify<CloseTo>(
106 q.GetCoordinates(cs),
Triple(root2/2,root2/2,2)
110 template<
class VectorType>
118 const VectorType p1(1,M_PI/2,M_PI/4, cs, VectorType::kSpherical);
119 CPPUNIT_ASSERT(Verify<CloseTo>(
120 p1.GetCoordinates(cs),
Triple(root2/2,root2/2,0)
123 const VectorType p2(1,M_PI/4,M_PI/3, cs, VectorType::kSpherical);
124 CPPUNIT_ASSERT(Verify<CloseTo>(
125 p2.GetCoordinates(cs),
126 Triple(root2/2*cos(M_PI/3), root2/2*sin(M_PI/3), root2/2)
129 const VectorType p3(1,M_PI/4,M_PI/3, cs, tst::spherical<VectorType>());
130 CPPUNIT_ASSERT(Verify<CloseTo>(
131 p3.GetCoordinates(cs),
132 Triple(root2/2*cos(M_PI/3), root2/2*sin(M_PI/3), root2/2)
136 template<
class VectorType>
142 const VectorType v(0, 0, 0, cs);
143 v.TransformTo(csNull);
146 template<
class VectorType>
152 const VectorType v1(0,0,0, cs);
153 CPPUNIT_ASSERT(Verify<CloseTo>(v1.GetR(cs), 0.));
155 VectorType v2(1,0,0, cs);
157 CPPUNIT_ASSERT(Verify<CloseTo>(
158 v2.GetCoordinates(cs),
Triple(2,0,0)
161 CPPUNIT_ASSERT(Verify<CloseTo>(
162 v2.GetCoordinates(cs),
Triple(0.5,0,0)
165 CPPUNIT_ASSERT(v1 != v2);
166 const VectorType v3(0.5, 0, 0, cs);
167 CPPUNIT_ASSERT(v2 == v3);
169 CPPUNIT_ASSERT(v1 == v1);
171 v1.GetCoordinates(cs), v2.GetCoordinates(cs)
181 CPPUNIT_ASSERT(Verify<CloseTo>(v1.
GetR2(cs), 1.));
182 CPPUNIT_ASSERT(Verify<CloseTo>(v1.
GetR(cs), 1.));
186 CPPUNIT_ASSERT(Verify<CloseTo>(v2.GetR2(cs), 1.));
187 CPPUNIT_ASSERT(Verify<CloseTo>(v2.GetR(cs), 1.));
void testConstructorCylindrical()
#define TEST_COLLECTION(Type_)
double GetR(const CoordinateSystemPtr &coordinateSystem) const
radius r in spherical coordinates coordinates (distance to origin)
void testTransformation()
void testConstructorThrow()
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
boost::tuple< double, double, double > Triple
Coordinate triple for easy getting or setting of coordinates.
bool Verify(const Predicate &pred, const T &lhs, const T &rhs)
Test condition by evaluating a predicate and print on failure.
void testConstructorSpherical()
double GetR2(const CoordinateSystemPtr &coordinateSystem) const
radius r^2 in spherical coordinates coordinates (distance to origin)^2