#############################################################################

[main]

[main - data:]

# method (for information only: the program scans the file name)
method: CSTD

[main - header:]

/* -- prototypes -- */

int estimate_uerror( UNUR_DISTR *distr, double u_resolution, int samplesize );

double cdf_exp(double x, const UNUR_DISTR *distr);
double invcdf_exp(double u, const UNUR_DISTR *distr);

/* -- constants -- */

/* sample size */
static const int    UERROR_SAMPLESIZE = 100000;
static const double UERROR_RESOLUTION = 1.e-14;

\#define COMPARE_SAMPLE_SIZE  (500)
\#define VIOLATE_SAMPLE_SIZE  (20)

#############################################################################

[new]

[new - invalid NULL ptr: 
   distr = NULL; ]

~( distr );
	--> expected_NULL --> UNUR_ERR_NULL

[new - invalid distribution type:
   distr = unur_distr_discr_new(); ]

~( distr );
	 --> expected_NULL --> UNUR_ERR_DISTR_INVALID

[new - not a standard distribution and missing inverse CDF:
   distr = unur_distr_cont_new(); ]

~( distr );
	--> expected_NULL --> UNUR_ERR_DISTR_REQUIRED

#############################################################################

[set]

[set - invalid NULL ptr: 
   par = NULL; ]

~_variant(par,1);
	--> expected_setfailed --> UNUR_ERR_NULL

[set - invalid parameter object:
   double fpar[2] = {0.,1.};
   distr = unur_distr_normal(fpar,2);
   par = unur_arou_new(distr); ]

~_variant(par,1);
	--> expected_setfailed --> UNUR_ERR_PAR_INVALID

unur_par_free(par);

[set - invalid parameters:
   distr = unur_distr_normal(NULL,0);
   par = unur_cstd_new(distr); ]

~_variant(par,9999);
	--> expected_setfailed --> UNUR_ERR_PAR_VARIANT

unur_par_free(par);

#############################################################################

# [get]

#############################################################################

[chg]

[chg - invalid generator object:
   double fpar[2] = {0.,1.};
   distr = unur_distr_normal(fpar,2);
   par = unur_arou_new(distr);
   unur_set_debug(par,0);
   gen = unur_init( par ); <-- ! NULL ]

~_truncated(gen, 0., 1.);
	--> expected_setfailed --> UNUR_ERR_GEN_INVALID


#############################################################################

[init]

[init - invalid NULL ptr: 
   par = NULL; ]

unur_init( par );
	--> expected_NULL --> UNUR_ERR_NULL


#############################################################################

[reinit]

[reinit - does not exist:
   distr = unur_distr_normal(NULL,0);
   par = unur_cstd_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

unur_reinit( gen );
	--> expected_reinit

#############################################################################

[sample]

[sample - compare clone:
   UNUR_GEN *clone;
   double fpar[] = { 1., 2.};
   distr = unur_distr_normal(fpar,2); 
   par = NULL;
   gen = NULL; ]

/* original generator object */
par = unur_cstd_new(distr);
gen = unur_init(par);
        -->compare_sequence_gen_start

/* clone */
clone = unur_gen_clone(gen);
unur_free(gen);
gen = clone;
        -->compare_sequence_gen

#.....................................................................

[sample - compare stringparser:
   double fpar[] = {3., 4.};
   distr = NULL;
   par = NULL;
   gen = NULL; ]

distr = unur_distr_gamma(fpar,2);
par = unur_cstd_new(distr);
unur_cstd_set_variant(par,2);
gen = unur_init(par);
	-->compare_sequence_gen_start
	
unur_free(gen); gen = NULL;
unur_distr_free(distr); distr = NULL;
gen = unur_str2gen( "gamma(3.,4.) & method = cstd; variant = 2" );
	-->compare_sequence_gen


#############################################################################

[validate]

[validate - generators:]

# inversion      
par[0] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,UNUR_STDGEN_INVERSION)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }

par[1] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,1)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }

par[2] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,2)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }

par[3] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,3)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }

par[4] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,4)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }

par[5] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,5)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }

par[6] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,6)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }

par[7] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,7)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }

par[8] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,8)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }

par[9] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,9)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }

# change domain
par[10] = unur_cstd_new(@distr@);
if (unur_cstd_set_variant(par,UNUR_STDGEN_INVERSION)!=UNUR_SUCCESS) { if (par) unur_par_free(par); par = NULL; }
unur_cstd_chg_truncated(gen,0.5,0.55);

## change parameters (use default variant)
{ UNUR_DISTR *dg =NULL;
par[11] = unur_cstd_new(@distr@);
fpm[0] = 2.;
fpm[1] = 5.;
dg = unur_get_distr(gen);
unur_distr_cont_set_pdfparams(dg,fpm,2);
unur_reinit(gen); }


[validate - distributions:]

# Beta distributions
fpm[0] = 1.;
fpm[1] = 2.;
distr[0] = unur_distr_beta(fpm,2);

fpm[0] = 1.;
fpm[1] = 5.;
distr[1] = unur_distr_beta(fpm,2);

fpm[0] = 5.;
fpm[1] = 1.;
distr[80] = unur_distr_beta(fpm,2);

fpm[0] = 1.;
fpm[1] = 1.;
distr[81] = unur_distr_beta(fpm,2);

fpm[0] = 7.;
fpm[1] = 0.5;
distr[60] = unur_distr_beta(fpm,2);

fpm[0] = 0.7;
fpm[1] = 0.5;
distr[61] = unur_distr_beta(fpm,2);

fpm[0] = 7.;
fpm[1] = 0.1;
fpm[2] = -1.;
fpm[3] = 2.;
distr[62] = unur_distr_beta(fpm,4);

fpm[0] = 1.;
fpm[1] = 100.;
distr[2] = unur_distr_beta(fpm,2);

fpm[0] = 3.;
fpm[1] = 4.;
distr[3] = unur_distr_beta(fpm,2);

fpm[0] = 5.;
fpm[1] = 100.;
distr[4] = unur_distr_beta(fpm,2);

fpm[0] = 500.;
fpm[1] = 300.;
distr[5] = unur_distr_beta(fpm,2);

fpm[0] = 5.;
fpm[1] = 10.;
fpm[2] = -3.;
fpm[3] = 15.;
distr[6] = unur_distr_beta(fpm,4);

# Burr distributions
fpm[0] = 1;
distr[66] = unur_distr_burr(fpm,1);

fpm[0] = 2;
fpm[1] = 2;
distr[67] = unur_distr_burr(fpm,2);

fpm[0] = 3;
fpm[1] = 2;
fpm[2] = 2;
distr[68] = unur_distr_burr(fpm,3);

fpm[0] = 4;
fpm[1] = 2;
fpm[2] = 2;
distr[69] = unur_distr_burr(fpm,3);

fpm[0] = 5;
fpm[1] = 2;
fpm[2] = 2;
distr[70] = unur_distr_burr(fpm,3);

fpm[0] = 6;
fpm[1] = 2;
fpm[2] = 2;
distr[71] = unur_distr_burr(fpm,3);

fpm[0] = 7;
fpm[1] = 2;
distr[72] = unur_distr_burr(fpm,2);

fpm[0] = 8;
fpm[1] = 2;
distr[73] = unur_distr_burr(fpm,2);

fpm[0] = 9;
fpm[1] = 2;
fpm[2] = 2;
distr[74] = unur_distr_burr(fpm,3);

fpm[0] = 10;
fpm[1] = 2;
distr[75] = unur_distr_burr(fpm,2);

fpm[0] = 11;
fpm[1] = 2;
distr[76] = unur_distr_burr(fpm,2);

fpm[0] = 12;
fpm[1] = 2;
fpm[2] = 2;
distr[77] = unur_distr_burr(fpm,3);


# Cauchy distributions
distr[7] = unur_distr_cauchy(NULL,0);

fpm[0] = 1.;
fpm[1] = 20.;
distr[8] = unur_distr_cauchy(fpm,2);

# Chi distribution
fpm[0] = 0.5;
distr[23] = unur_distr_chi(fpm,1);

fpm[0] = 1.;
distr[24] = unur_distr_chi(fpm,1);

fpm[0] = 2.;
distr[25] = unur_distr_chi(fpm,1);

fpm[0] = 50.;
distr[26] = unur_distr_chi(fpm,1);

# Exponential distribution
distr[27] = unur_distr_exponential(NULL,0);

fpm[0] = 0.5;
distr[28] = unur_distr_exponential(fpm,1);

fpm[0] = 5.;
fpm[1] = -3.;
distr[29] = unur_distr_exponential(fpm,2);

# Extreme value type I
distr[30] = unur_distr_extremeI(NULL,0);

fpm[0] = -3.;
distr[31] = unur_distr_extremeI(fpm,1);

fpm[0] = -1.;
fpm[1] = 5.;
distr[32] = unur_distr_extremeI(fpm,2);

# Extreme value type II
fpm[0] = 3.;
distr[33] = unur_distr_extremeII(fpm,1);

fpm[0] = 0.5;
fpm[1] = -3.;
distr[34] = unur_distr_extremeII(fpm,2);

fpm[0] = 0.8;
fpm[1] = -1.;
fpm[2] = 5.;
distr[35] = unur_distr_extremeII(fpm,3);

# Gamma distributions
fpm[0] = 1.;
distr[9] = unur_distr_gamma(fpm,1);

fpm[0] = 2.;
distr[10] = unur_distr_gamma(fpm,1);

fpm[0] = 3.;
distr[11] = unur_distr_gamma(fpm,1);

fpm[0] = 10.;
distr[12] = unur_distr_gamma(fpm,1);

fpm[0] = 1000.;
distr[13] = unur_distr_gamma(fpm,1);

fpm[0] = 5.;
fpm[1] = 1000.;
distr[14] = unur_distr_gamma(fpm,2);

fpm[0] = 5.;
fpm[1] = 1.e-5;
distr[15] = unur_distr_gamma(fpm,2);

fpm[0] = 5.;
fpm[1] = 10.;
fpm[2] = 1000;
distr[16] = unur_distr_gamma(fpm,3);

fpm[0] = 0.5;
distr[63] = unur_distr_gamma(fpm,1);

fpm[0] = 0.2;
distr[64] = unur_distr_gamma(fpm,1);

# Generalized Inverse Gaussian 
fpm[0] = 0.5;
fpm[1] = 7;
fpm[2] = 1;
distr[83] = unur_distr_gig(fpm,3);

fpm[0] = 0.5;
fpm[1] = 0.5;
fpm[2] = 1;
distr[86] = unur_distr_gig(fpm,3);

# Laplace distribution
distr[36] = unur_distr_laplace(NULL,0);

fpm[0] = -3.;
distr[37] = unur_distr_laplace(fpm,1);

fpm[0] = -1.;
fpm[1] = 5.;
distr[38] = unur_distr_laplace(fpm,2);

# Logistic distribution
distr[39] = unur_distr_logistic(NULL,0);

fpm[0] = -3.;
distr[40] = unur_distr_logistic(fpm,1);

fpm[0] = -1.;
fpm[1] = 5.;
distr[41] = unur_distr_logistic(fpm,2);

# Lomax
fpm[0] = 2.;
fpm[1] = 3.;
distr[56] = unur_distr_lomax(fpm,2);

fpm[0] = 20.;
fpm[1] = 0.4;
distr[57] = unur_distr_lomax(fpm,2);

fpm[0] = 0.2;
fpm[1] = 40.;
distr[58] = unur_distr_lomax(fpm,2);

fpm[0] = 0.2;
fpm[1] = 0.5;
distr[59] = unur_distr_lomax(fpm,2);

# Normal distributions
distr[17] = unur_distr_normal(NULL,0);

fpm[0] = 1.;
fpm[1] = 1.e-5;
distr[18] = unur_distr_normal(fpm,2);

fpm[0] = 0.;
fpm[1] = 1.e+5;
distr[19] = unur_distr_normal(fpm,2);

# Pareto
fpm[0] = 2.;
fpm[1] = 3.;
distr[52] = unur_distr_pareto(fpm,2);

fpm[0] = 20.;
fpm[1] = 0.4;
distr[53] = unur_distr_pareto(fpm,2);

fpm[0] = 0.2;
fpm[1] = 40.;
distr[54] = unur_distr_pareto(fpm,2);

fpm[0] = 0.2;
fpm[1] = 0.5;
distr[55] = unur_distr_pareto(fpm,2);

# Power exponential distribution
fpm[0] = 0.5;
distr[42] = unur_distr_powerexponential(fpm,1);

fpm[0] = 1.;
distr[43] = unur_distr_powerexponential(fpm,1);

fpm[0] = 2.;
distr[44] = unur_distr_powerexponential(fpm,1);

fpm[0] = 10.;
distr[45] = unur_distr_powerexponential(fpm,1);

# Rayleigh
fpm[0] = 1.;
distr[65] = unur_distr_rayleigh(fpm,1);

# Slash
distr[82] = unur_distr_slash(NULL,0);

# Student t
fpm[0] = 2;
distr[84] = unur_distr_student(fpm,1);

fpm[0] = 0.5;
distr[85] = unur_distr_student(fpm,1);

# Triangular
fpm[0] = 0.7;
distr[46] = unur_distr_triangular(fpm,1);

fpm[0] = 0.;
distr[47] = unur_distr_triangular(fpm,1);

fpm[0] = 1.;
distr[48] = unur_distr_triangular(fpm,1);

# Uniform distributions
distr[20] = unur_distr_uniform(NULL,0);

fpm[0] = 1.;
fpm[1] = 20.;
distr[21] = unur_distr_uniform(fpm,2);

# Weibull
fpm[0] = 3.;
distr[49] = unur_distr_weibull(fpm,1);

fpm[0] = 0.5;
fpm[1] = 3.;
distr[50] = unur_distr_weibull(fpm,2);

fpm[0] = 1.5;
fpm[1] = 2.;
fpm[2] = -5.;
distr[51] = unur_distr_weibull(fpm,3);


# truncated distributions
distr[22] = unur_distr_cauchy(NULL,0);
unur_distr_cont_set_domain(distr[22],0.1,1.);
unur_distr_cont_upd_mode(distr[22]);
unur_distr_cont_upd_pdfarea(distr[22]);

# distributions from scratch
distr[78] = unur_distr_cont_new();
unur_distr_set_name( distr[78], "CDF_only" );
unur_distr_cont_set_domain( distr[78], 0, UNUR_INFINITY );
unur_distr_cont_set_cdf( distr[78], cdf_exp );

distr[79] = unur_distr_cont_new();
unur_distr_set_name( distr[79], "CDF&invCDF" );
unur_distr_cont_set_domain( distr[79], 0, UNUR_INFINITY );
unur_distr_cont_set_cdf( distr[79], cdf_exp );
unur_distr_cont_set_invcdf( distr[79], invcdf_exp );


# number of distributions: 87


[validate - test chi2:]

#  + ... pass test
#  % ... initialize generator and draw small sample
#        (for memory debugging when the CDF is not available)
#  0 ... fail to initialize generator (given variant does not exist)
#  - ... fail test
#  / ... either init fails or test passes
#  . ... do not run test
#  # ... comment
#
# generators:
#   [0]         ... Inversion
#   [1] -- [9]  ... Variants 1 to 9
#   [10]        ... inversion domain changed after initialization
#   [11]        ... change parameters to {2., 5.}  (use default variant)
#
#                                     1  1
#gen	0  1  2  3  4  5  6  7  8  9  0  1	# distribution
#-------------------------------------------------------------
  <0>	0  +  +  .  .  .  .  .  .  .  .  .	# beta (1, 2)
  <1>	.  +  +  .  .  .  .  .  .  .  .  .	# beta (1, 5)
 <80>	.  +  +  .  .  .  .  .  .  .  .  .	# beta (5, 1)
 <81>	.  +  +  .  .  .  .  .  .  .  .  .	# beta (1, 1)
x <2>	.  +  .  .  .  .  .  .  .  .  .  .	# beta (1, 100)
  <3>	.  +  +  .  .  .  .  .  .  .  .  .	# beta (3, 4)
 <60>	.  +  +  .  .  .  .  .  .  .  .  .	# beta (7, 0.5)
 <61>	.  +  +  .  .  .  .  .  .  .  .  .	# beta (0.7, 0.5)
#<62>	.  +  +  .  .  .  .  .  .  .  .  .	# beta (7, 0.1, -1, 2)
x <4>	.  +  .  .  .  .  .  .  .  .  .  .	# beta (5, 100)
x <5>	.  +  .  .  .  .  .  .  .  .  .  .	# beta (500, 300)
x <6>	.  +  .  .  .  .  .  .  .  .  .  .	# beta (5, 10, -3, 15)
 <66>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (1)
 <67>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (2,2)
 <68>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (3,2,2)
 <69>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (4,2,2)
 <70>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (5,2,2)
 <71>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (6,2,2)
 <72>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (7,2)
 <73>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (8,2)
 <74>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (9,2,2)
 <75>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (10,2)
 <76>	0  .  .  .  .  .  .  .  .  .  .  .	# burr (11,2)
 <77>	+  .  .  .  .  .  .  .  .  .  .  .	# burr (12,2,2)
  <7>	+  .  .  .  .  .  .  .  .  .  +  +	# cauchy ()
  <8>	+  .  .  .  .  .  .  .  .  .  +  +	# cauchy (1, 20)
 <23>	0  -  .  .  .  .  .  .  .  .  .  .	# chi (0.5)
x<24>	.  +  .  .  .  .  .  .  .  .  .  +	# chi (1)
 <25>	0  +  .  .  .  .  .  .  .  .  .  .	# chi (2)
x<26>	.  +  .  .  .  .  .  .  .  .  .  +	# chi (50)
 <27>	+  .  .  .  .  .  .  .  .  .  +  +	# exponential ()
x<28>	+  .  .  .  .  .  .  .  .  .  +  +	# exponential (0.5)
 <29>	+  .  .  .  .  .  .  .  .  .  +  +	# exponential (5, -3)
 <30>	+  .  .  .  .  .  .  .  .  .  +  +	# extremeI ()
 <31>	+  .  .  .  .  .  .  .  .  .  +  +	# extremeI (-3)
 <32>	+  .  .  .  .  .  .  .  .  .  +  +	# extremeI (-1, 5)
 <33>	+  .  .  .  .  .  .  .  .  .  +  +	# extremeII (3)
 <34>	+  .  .  .  .  .  .  .  .  .  +  +	# extremeII (0.5, -3)
 <35>	+  .  .  .  .  .  .  .  .  .  +  +	# extremeII (0.8, -1, 5)
  <9>	0  +  +  .  .  .  .  .  .  .  .  +	# gamma (1)
x<10>	.  +  +  .  .  .  .  .  .  .  .  +	# gamma (2)
 <11>	.  +  +  .  .  .  .  .  .  .  .  +	# gamma (3)
 <12>	.  +  +  .  .  .  .  .  .  .  .  +	# gamma (10)
x<13>	.  +  +  .  .  .  .  .  .  .  .  +	# gamma (1000)
 <14>	.  +  +  .  .  .  .  .  .  .  .  +	# gamma (5, 1000, 0)
x<15>	.  +  +  .  .  .  .  .  .  .  .  +	# gamma (5, 1e-05, 0)
x<16>	.  +  +  .  .  .  .  .  .  .  .  +	# gamma (5, 10, 100000)
 <63>	.  +  +  .  .  .  .  .  .  .  .  +	# gamma (0.5)
x<64>	.  +  +  .  .  .  .  .  .  .  .  +	# gamma (0.2)
 <83>   .  %  .  .  .  .  .  .  .  .  .  .      # gig (0.5, 7, 1)
 <86>   .  %  .  .  .  .  .  .  .  .  .  .      # gig (0.5, 0.5, 1)
 <36>	+  .  .  .  .  .  .  .  .  .  +  +	# laplace ()
 <37>	+  .  .  .  .  .  .  .  .  .  +  +	# laplace (-3)
 <38>	+  .  .  .  .  .  .  .  .  .  +  +	# laplace (-1, 5)
 <39>	+  .  .  .  .  .  .  .  .  .  +  +	# logistic ()
 <40>	+  .  .  .  .  .  .  .  .  .  +  +	# logistic (-3)
 <41>	+  .  .  .  .  .  .  .  .  .  +  +	# logistic (-1, 5)
 <56>	+  .  .  .  .  .  .  .  .  .  +  +	# lomax (2, 3)
 <57>	+  .  .  .  .  .  .  .  .  .  +  +	# lomax (20, 0.4)
 <58>	+  .  .  .  .  .  .  .  .  .  +  +	# lomax (0.2, 40)
 <59>	+  .  .  .  .  .  .  .  .  .  +  +	# lomax (0.2, 0.5)
 <17>	+  +  +  +  +  +  +  +  .  .  /  +	# normal ()
x<18>	+  +  +  +  +  +  +  +  .  .  .  +	# normal (1, 1e-05)
 <19>	+  +  +  +  +  +  +  +  .  .  /  +	# normal (1, 1e+05)
 <52>	+  .  .  .  .  .  .  .  .  .  .  +	# pareto (2, 3)
 <53>	+  .  .  .  .  .  .  .  .  .  .  +	# pareto (20, 0.4)
 <54>	+  .  .  .  .  .  .  .  .  .  .  +	# pareto (0.2, 40)
 <55>	+  .  .  .  .  .  .  .  .  .  +  +	# pareto (0.2, 0.5)
 <42>	0  -  .  .  .  .  .  .  .  .  .  .	# powerexponential (0.5)
 <43>	.  +  .  .  .  .  .  .  .  .  .  +	# powerexponential (1)
 <44>	0  +  .  .  .  .  .  .  .  .  .  .	# powerexponential (2)
 <45>	.  +  .  .  .  .  .  .  .  .  .  .	# powerexponential (10)
 <65>	0  -  .  .  .  .  .  .  .  .  .  .	# rayleigh (1.)
 <82>	0  %  .  .  .  .  .  .  .  .  .  .	# slash ()
 <84>	0  +  +  .  .  .  .  .  .  .  .  .	# student (2)
 <85>	0  +  0  .  .  .  .  .  .  .  .  .	# student (0.5)
 <46>	+  .  .  .  .  .  .  .  .  .  +  .	# triangular (0.7)
x<47>	+  .  .  .  .  .  .  .  .  .  +  .	# triangular (0)
x<48>	+  .  .  .  .  .  .  .  .  .  +  .	# triangular (1)
 <49>	+  .  .  .  .  .  .  .  .  .  +  +	# weibull (3)
 <50>	+  .  .  .  .  .  .  .  .  .  +  +	# weibull (0.5, 3)
 <51>	+  .  .  .  .  .  .  .  .  .  +  +	# weibull (1.5, 2, -5.)
 <20>	+  .  .  .  .  .  .  .  .  .  +  +	# uniform (1.5, 2, -5)
 <21>	+  .  .  .  .  .  .  .  .  .  .  +	# uniform (1, 20)
 <22>	+  .  .  .  .  .  .  .  .  .  +  +	# cauchy () - truncated

 <78>	0  .  .  .  .  .  .  .  .  .  .  .	# given CDF
 <79>	+  .  .  .  .  .  .  .  .  .  .  .	# given CDF + invCDF


## F
## chisquare
## ghyp
## hyperbolic
## ig
## lognormal


#############################################################################

[special]

## Remark:
## 
## In this section we merely test the existence of inversion.
## A few implementations seem to be rather inaccurate with respect to
## their u-errors.
##

[special - decl:]

  int samplesize = UERROR_SAMPLESIZE;
  double ures = UERROR_RESOLUTION;

  int errorsum = 0;
  double fpar[5];

  UNUR_DISTR *distr;

[special - start:]

  /* test for maximal u-error */
  printf("\n[test maximal u-error for inversion method]\n"); 
  fprintf(TESTLOG,"\n* Test maximal u-error for inversion method *\n"); 

## ----------------------------------------------------

  printf(" beta");

  fpar[0] = 3.;
  fpar[1] = 4.;
  distr = unur_distr_beta(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 1.;
  fpar[1] = 2.;
  fpar[2] = 3.;
  fpar[3] = 4.;
  distr = unur_distr_beta(fpar,4);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" burr");

  fpar[0] = 1.;
  distr = unur_distr_burr(fpar,1);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 2.;
  fpar[1] = 2.;
  distr = unur_distr_burr(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 3.;
  fpar[1] = 2.;
  fpar[2] = 3.;
  distr = unur_distr_burr(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 4.;
  fpar[1] = 1.;
  fpar[2] = 2.;
  distr = unur_distr_burr(fpar,3);
  errorsum += estimate_uerror(distr,1e-10,samplesize);
  /* computation of CDF and /or inverse CDF is not seem very accurate */

  fpar[0] = 5.;
  fpar[1] = 2.;
  fpar[2] = 3.;
  distr = unur_distr_burr(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 6.;
  fpar[1] = 2.;
  fpar[2] = 3.;
  distr = unur_distr_burr(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 7.;
  fpar[1] = 2.;
  fpar[2] = 3.;
  distr = unur_distr_burr(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 8.;
  fpar[1] = 2.;
  distr = unur_distr_burr(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 9.;
  fpar[1] = 2.;
  fpar[2] = 3.;
  distr = unur_distr_burr(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 10.;
  fpar[1] = 2.;
  distr = unur_distr_burr(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 11.;
  fpar[1] = 2.;
  distr = unur_distr_burr(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 12.;
  fpar[1] = 2.;
  fpar[2] = 3.;
  distr = unur_distr_burr(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" cauchy");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_cauchy(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" chi");
  fpar[0] = 3.;
  distr = unur_distr_chi(fpar,1);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" chisquare");
  fpar[0] = 3.;
  distr = unur_distr_chisquare(fpar,1);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" exponential");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_exponential(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" extremeI");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_extremeI(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" extremeII");
  fpar[0] = 1.;
  fpar[1] = 2.;
  fpar[2] = 3.;
  distr = unur_distr_extremeII(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" F");
  fpar[0] = 3.;
  fpar[1] = 4.;
  distr = unur_distr_F(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" gamma");

  fpar[0] = 5.;
  distr = unur_distr_gamma(fpar,1);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 4.;
  fpar[1] = 3.;
  distr = unur_distr_gamma(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

  fpar[0] = 3.;
  fpar[1] = 2.;
  fpar[2] = 1.;
  distr = unur_distr_gamma(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" gig");
  fpar[0] = 1.;
  fpar[1] = 2.;
  fpar[1] = 3.;
  distr = unur_distr_gig(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" gig2");
  fpar[0] = 1.;
  fpar[1] = 2.;
  fpar[2] = 3.;
  distr = unur_distr_gig2(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" ghyp");
  fpar[0] = 1.;
  fpar[1] = 3.;
  fpar[2] = 2.;
  fpar[3] = 4.;
  fpar[4] = 5.;
  distr = unur_distr_ghyp(fpar,5);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" hyperbolic");
  fpar[0] = 3.;
  fpar[1] = 2.;
  fpar[2] = 2.;
  fpar[3] = 2.;
  distr = unur_distr_hyperbolic(fpar,4);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" ig");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_ig(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" laplace");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_laplace(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" logistic");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_logistic(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" lognormal");
  fpar[0] = 1.;
  fpar[1] = 2.;
  fpar[2] = 3.;
  distr = unur_distr_lognormal(fpar,3);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" lomax");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_lomax(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" normal");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_normal(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" pareto");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_pareto(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" powerexponential");
  fpar[0] = 3.;
  distr = unur_distr_powerexponential(fpar,1);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" rayleigh");
  fpar[0] = 2.;
  distr = unur_distr_rayleigh(fpar,1);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" slash");
  distr = unur_distr_slash(NULL,0);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" student");
  fpar[0] = 4.4;
  distr = unur_distr_student(fpar,1);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" triangular");
  fpar[0] = 0.7;
  distr = unur_distr_triangular(fpar,1);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" uniform");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_uniform(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

  printf(" weibull");
  fpar[0] = 1.;
  fpar[1] = 2.;
  distr = unur_distr_weibull(fpar,2);
  errorsum += estimate_uerror(distr,ures,samplesize);

## ----------------------------------------------------

/*---------------------------------------------------------------------------*/

  /* test finished */
  FAILED = (errorsum < 2) ? 0 : 1;

#############################################################################

[verbatim]

#############################################################################
#
# routines for special tests
#
#############################################################################

int
estimate_uerror( UNUR_DISTR *distr,     /* distribution object */
		 double u_resolution,   /* maximal tolerated u-error */
  		 int samplesize )       /* sample size for error experiment */
/* returns 0 if maxerror < u_resolution, errorcode otherwise */
{
  UNUR_PAR *par;
  UNUR_GEN *gen;
  int i, nfpar;
  const double *fpar;
  double score;

  /* print data about distribution */
  fprintf(TESTLOG,"> %s (",unur_distr_get_name(distr));
  nfpar = unur_distr_cont_get_pdfparams(distr,&fpar);
  for(i=0;i<nfpar;i++) fprintf(TESTLOG,"%s %g", (i?",":""), fpar[i]);
  fprintf(TESTLOG,")\n");

  /* create parameter object for inversion method */
  par = unur_cstd_new(distr);
  if (par==NULL || 
      unur_cstd_set_variant(par,UNUR_STDGEN_INVERSION)!=UNUR_SUCCESS) {
    fprintf(TESTLOG,"\t--> inversion method not implemented !!\n\n");
    printf("0"); fflush(stdout);
    if (par) unur_par_free(par);
    unur_distr_free(distr);
    return 0; 
  }

  /* initialize generator object */
  gen = unur_init(par);

  /* run test */
  score = run_validate_u_error( TESTLOG, gen, distr, u_resolution, samplesize );

  /* clear working space */
  unur_distr_free(distr);
  unur_free(gen);

  /* return */
  fprintf(TESTLOG,"\n");
  return score;

} /* end of estimate_uerror() */

#############################################################################
#
# PDFs and CDF for test distributions
#
#############################################################################

double cdf_exp(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED) { 
	return ((x<0.) ? 0. : 1.-exp(-x));
}

double invcdf_exp(double u, const UNUR_DISTR *distr ATTRIBUTE__UNUSED) { 
	return (-log(1.- u)); 
}

#############################################################################
