9 #include <tst/Verify.h>
10 #include <cppunit/extensions/HelperMacros.h>
11 #include <utl/RandomSamplerFromCDF.h>
12 #include <utl/AugerException.h>
13 #include <utl/TabulatedFunction.h>
14 #include <CLHEP/Random/Randomize.h>
15 #include <boost/lexical_cast.hpp>
20 using boost::lexical_cast;
23 #define EQUAL(x, y) CPPUNIT_ASSERT(Verify<Equal>(x, y))
24 #define CLOSE(x, y) CPPUNIT_ASSERT(Verify<CloseTo>(x, y))
25 #define CLOSE_AT(x, y, eps) CPPUNIT_ASSERT(Verify<CloseTo>(x, y, eps))
34 CPPUNIT_TEST(TestTabulatedFunction);
35 CPPUNIT_TEST(TestVectors);
36 CPPUNIT_TEST(TestVectorAndNormalization);
37 CPPUNIT_TEST(TestMap);
38 CPPUNIT_TEST(TestFunction);
39 CPPUNIT_TEST(TestFunction2);
40 CPPUNIT_TEST_SUITE_END();
50 vector<double> cdf(1, 0);
57 vector<double> cdf(2, 1);
64 vector<double> cdf(3);
79 CLHEP::MTwistEngine rand;
80 for (
int i = 0; i < 1000; ++i) {
81 const double x = sampler.
shoot(rand);
82 CPPUNIT_ASSERT(-1 <= x && x <= 3 && !(1 < x && x < 2));
84 const double eps = 1e-12;
99 const double x[] = { 10, 10, 11, 11 };
100 const double y[] = { 0, 0.1, 0.1, 1 };
101 const unsigned int n =
sizeof(x) /
sizeof(x[0]);
102 vector<double> xx(x, x + n);
103 vector<double> yy(y, y + n);
105 CLHEP::MTwistEngine rand;
106 for (
int i = 0; i < 1000; ++i) {
107 const double x = sampler.
shoot(rand);
108 CPPUNIT_ASSERT(x == 10 || x == 11);
115 const double y[] = { 0, 1, 3, 7, 10 };
116 const unsigned int n =
sizeof(y) /
sizeof(y[0]);
117 const vector<double> yy(y, y + n);
119 CLHEP::MTwistEngine rand;
120 for (
int i = 0; i < 1000; ++i) {
121 const double x = sampler.
shoot(rand);
122 CPPUNIT_ASSERT(0 <= x && x <= 1);
129 const double x[] = { -5, 0, 8, 9, 9.5, 10 };
130 const double y[] = { 0, 25, 25, 50, 50, 100 };
131 map<double, double> xy;
132 const unsigned int n =
sizeof(x) /
sizeof(x[0]);
133 for (
unsigned int i = 0; i < n; ++i)
136 CLHEP::MTwistEngine rand;
137 for (
int i = 0; i < 1000; ++i) {
138 const double x = sampler.
shoot(rand);
139 CPPUNIT_ASSERT((-5 <= x && x <= 0) || (8 <= x && x <= 9) || (9.5 <= x && x <= 10));
150 CLHEP::MTwistEngine rand;
151 for (
int i = 0; i < 1000; ++i) {
152 const double x = sampler.
shoot(rand);
153 CPPUNIT_ASSERT((1 <= x && x <= 2));
160 const double min = -1.222;
161 const double max = 0.63;
162 const string func =
"sin(x) - sin(" + lexical_cast<
string>(min) +
")";
164 CLOSE(sampler.GetInverseCDF(0), min);
165 CLOSE(sampler.GetInverseCDF(1),
max);
166 CLHEP::MTwistEngine rand;
167 for (
int i = 0; i < 1000; ++i) {
168 const double x = sampler.shoot(rand);
169 CPPUNIT_ASSERT((min <= x && x <= max));
void TestTabulatedFunction()
Base class for exceptions arising because configuration data are not valid.
Class to hold collection (x,y) points and provide interpolation between them.
void PushBack(const double x, const double y)
double shoot(HepEngine &engine) const
Method to shoot random values using a given engine by-passing the static generator.
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
void TestVectorAndNormalization()
double GetInverseCDF(const double y) const
#define CLOSE_AT(x, y, eps)