1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
|
// -*- C++ -*-
// $Id: testDistCopy.cc,v 1.3 2011/05/31 20:57:01 garren Exp $
// ----------------------------------------------------------------------
// ======================================================================
//
//
// testDistCopy -- test copied random distributions
//
// ======================================================================
#include "CLHEP/Units/GlobalPhysicalConstants.h" // used to provoke shadowing warnings
// ----------------------------------------------------------------------
// Engines:
#include "CLHEP/Random/DualRand.h" // CLHEP::DualRand
#include "CLHEP/Random/MTwistEngine.h" // CLHEP::MTwistEngine
// ----------------------------------------------------------------------
// Distributions:
#include "CLHEP/Random/RandBinomial.h" // CLHEP::RandBinomial
#include "CLHEP/Random/RandBreitWigner.h" // CLHEP::RandBreitWigner
#include "CLHEP/Random/RandChiSquare.h" // CLHEP::RandChiSquare
#include "CLHEP/Random/RandExponential.h" // CLHEP::RandExponential
#include "CLHEP/Random/RandFlat.h" // CLHEP::RandFlat
#include "CLHEP/Random/RandGamma.h" // CLHEP::RandGamma
#include "CLHEP/Random/RandGauss.h" // CLHEP::RandGauss
#include "CLHEP/Random/RandGaussQ.h" // CLHEP::RandGaussQ
#include "CLHEP/Random/RandGaussT.h" // CLHEP::RandGaussT
#include "CLHEP/Random/RandGeneral.h" // CLHEP::RandGeneral
#include "CLHEP/Random/RandLandau.h" // CLHEP::RandLandau
#include "CLHEP/Random/RandPoissonQ.h" // CLHEP::RandPoissonQ
#include "CLHEP/Random/RandPoissonT.h" // CLHEP::RandPoissonT
#include "CLHEP/Random/RandSkewNormal.h" // CLHEP::RandSkewNormal
#include "CLHEP/Random/RandStudentT.h" // CLHEP::RandStudentT
// ----------------------------------------------------------------------
// Standard library:
#include <sstream> // for ostringstream
#include <string> // for string
using namespace CLHEP;
typedef unsigned int uint;
// ----------------------------------------------------------------------
// copy-construction test
template< typename Dist >
bool
copy_constructor_is_okay( Dist & d1 )
{
// prime the distribution
for( uint i = 0u; i != 17u; ++i )
(void) d1.fire();
// capture its state
std::ostringstream os1;
d1.put( os1 );
HepRandomEngine * e1 = & d1.engine();
// make a copy and capture the copy's state
Dist d2( d1 );
std::ostringstream os2;
d2.put( os2 );
HepRandomEngine * e2 = & d2.engine();
// do the saved states match and is the underlying engine shared?
return os1.str() == os2.str() && e1 == e2;
} // copy_constructor_is_okay<>()
// ----------------------------------------------------------------------
// copy-construction test
template< typename Dist >
bool
copy_assignment_is_okay( Dist & d1, Dist & d2 )
{
// prime the distributions
for( uint i = 0u; i != 17u; ++i )
(void) d1.fire();
for( uint i = 0u; i != 19u; ++i )
(void) d2.fire();
// capture d1's state
std::ostringstream os1;
d1.put( os1 );
HepRandomEngine * e1 = & d1.engine();
// make a copy and capture the copy's state
d2 = d1;
std::ostringstream os2;
d2.put( os2 );
HepRandomEngine * e2 = & d2.engine();
// do the saved states match and is the underlying engine shared?
return os1.str() == os2.str() && e1 == e2;
} // copy_assignment_is_okay<>()
// ----------------------------------------------------------------------
// Mask bits to form a word identifying dists that failed their test
static uint const success = 0u;
static uint const Binomial_failure = 1u << 1;
static uint const BreitWigner_failure = 1u << 2;
static uint const ChiSquare_failure = 1u << 3;
static uint const Exponential_failure = 1u << 4;
static uint const Flat_failure = 1u << 5;
static uint const Gamma_failure = 1u << 6;
static uint const Gauss_failure = 1u << 7;
static uint const GaussQ_failure = 1u << 8;
static uint const GaussT_failure = 1u << 9;
static uint const General_failure = 1u << 10;
static uint const Landau_failure = 1u << 11;
static uint const Poisson_failure = 1u << 12;
static uint const PoissonQ_failure = 1u << 13;
static uint const PoissonT_failure = 1u << 14;
static uint const StudentT_failure = 1u << 15;
static uint const SkewNormal_failure = 1u << 16;
// ----------------------------------------------------------------------
// RandBinomial
uint testRandBinomial()
{
MTwistEngine r1( 97531L );
RandBinomial d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return Binomial_failure;
DualRand r2( 13579L );
RandBinomial d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return Binomial_failure;
return 0u;
}
// ----------------------------------------------------------------------
// RandBreitWigner
uint testRandBreitWigner()
{
MTwistEngine r1( 97531L );
RandBreitWigner d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return BreitWigner_failure;
DualRand r2( 13579L );
RandBreitWigner d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return BreitWigner_failure;
return 0u;
} // testRandBreitWigner
// ----------------------------------------------------------------------
// RandChiSquare
uint testRandChiSquare()
{
MTwistEngine r1( 97531L );
RandChiSquare d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return ChiSquare_failure;
DualRand r2( 13579L );
RandChiSquare d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return ChiSquare_failure;
return 0u;
} // testRandChiSquare
// ----------------------------------------------------------------------
// RandExponential
uint testRandExponential()
{
MTwistEngine r1( 97531L );
RandExponential d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return Exponential_failure;
DualRand r2( 13579L );
RandExponential d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return Exponential_failure;
return 0u;
} // testRandExponential
// ----------------------------------------------------------------------
// RandFlat
uint testRandFlat()
{
MTwistEngine r1( 97531L );
RandFlat d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return Flat_failure;
DualRand r2( 13579L );
RandFlat d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return Flat_failure;
return 0u;
} // testRandFlat
// ----------------------------------------------------------------------
// RandGamma
uint testRandGamma()
{
MTwistEngine r1( 97531L );
RandGamma d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return Gamma_failure;
DualRand r2( 13579L );
RandGamma d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return Gamma_failure;
return 0u;
} // testRandGamma
// ----------------------------------------------------------------------
// RandGauss
uint testRandGauss()
{
MTwistEngine r1( 97531L );
RandGauss d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return Gauss_failure;
DualRand r2( 13579L );
RandGauss d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return Gauss_failure;
return 0u;
} // testRandGauss
// ----------------------------------------------------------------------
// RandGaussQ
uint testRandGaussQ()
{
MTwistEngine r1( 97531L );
RandGaussQ d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return GaussQ_failure;
DualRand r2( 13579L );
RandGaussQ d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return GaussQ_failure;
return 0u;
} // testRandGaussQ
// ----------------------------------------------------------------------
// RandGaussT
uint testRandGaussT()
{
MTwistEngine r1( 97531L );
RandGaussT d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return GaussT_failure;
DualRand r2( 13579L );
RandGaussT d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return GaussT_failure;
return 0u;
} // testRandGaussT
// ----------------------------------------------------------------------
// RandGeneral
uint testRandGeneral()
{
MTwistEngine r1( 97531L );
double pdf1[] = { 1.5, 2.5, 3.0, 4.25, 5.65 };
RandGeneral d1( r1, pdf1, sizeof(pdf1)/sizeof(pdf1[0]) );
if( ! copy_constructor_is_okay(d1) ) return General_failure;
DualRand r2( 13579L );
double pdf2[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 0.60 };
RandGeneral d2( r2, pdf2, sizeof(pdf2)/sizeof(pdf2[0]) );
if( ! copy_assignment_is_okay(d1,d2) ) return General_failure;
return 0u;
} // testRandGeneral
// ----------------------------------------------------------------------
// RandLandau
uint testRandLandau()
{
MTwistEngine r1( 97531L );
RandLandau d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return Landau_failure;
DualRand r2( 13579L );
RandLandau d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return Landau_failure;
return 0u;
} // testRandLandau
// ----------------------------------------------------------------------
// RandPoisson
uint testRandPoisson()
{
MTwistEngine r1( 97531L );
RandPoisson d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return Poisson_failure;
DualRand r2( 13579L );
RandPoisson d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return Poisson_failure;
return 0u;
} // testRandPoisson
// ----------------------------------------------------------------------
// RandPoissonQ
uint testRandPoissonQ()
{
MTwistEngine r1( 97531L );
RandPoissonQ d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return PoissonQ_failure;
DualRand r2( 13579L );
RandPoissonQ d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return PoissonQ_failure;
return 0u;
} // testRandPoissonQ
// ----------------------------------------------------------------------
// RandPoissonT
uint testRandPoissonT()
{
MTwistEngine r1( 97531L );
RandPoissonT d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return PoissonT_failure;
DualRand r2( 13579L );
RandPoissonT d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return PoissonT_failure;
return 0u;
} // testRandPoissonT
// ----------------------------------------------------------------------
// RandSkewNormal
uint testRandSkewNormal()
{
MTwistEngine r1( 97531L );
RandSkewNormal d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return SkewNormal_failure;
DualRand r2( 13579L );
RandSkewNormal d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return SkewNormal_failure;
return 0u;
} // testRandSkewNormal
// ----------------------------------------------------------------------
// RandStudentT
uint testRandStudentT()
{
MTwistEngine r1( 97531L );
RandStudentT d1( r1 );
if( ! copy_constructor_is_okay(d1) ) return StudentT_failure;
DualRand r2( 13579L );
RandStudentT d2( r2 );
if( ! copy_assignment_is_okay(d1,d2) ) return StudentT_failure;
return 0u;
} // testRandStudentT
// ----------------------------------------------------------------------
// main
int main()
{
uint mask = 0u
| testRandBinomial ()
| testRandBreitWigner()
| testRandChiSquare ()
| testRandExponential()
| testRandFlat ()
| testRandGamma ()
| testRandGauss ()
| testRandGaussQ ()
| testRandGaussT ()
| testRandGeneral ()
| testRandLandau ()
| testRandPoisson ()
| testRandPoissonQ ()
| testRandPoissonT ()
| testRandSkewNormal ()
| testRandStudentT ()
;
return - int(mask);
}
|