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

[main]

[main - data:]

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

[main - header:]

/* prototypes */

int check_init(UNUR_GEN *gen);
double check_sample(UNUR_GEN *gen);

double exp1_sample(UNUR_GEN *gen);

double expa_sample(UNUR_GEN *gen);

int expb_init(UNUR_GEN *gen);
double expb_sample(UNUR_GEN *gen);

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

/* \#define SEED   (298346) */


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

[new]

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

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


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

[set]

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

~_init(par,NULL);
	--> expected_setfailed --> UNUR_ERR_NULL

~_sample(par,NULL);
	--> expected_setfailed --> UNUR_ERR_NULL


[set - invalid parameter object:
   distr = unur_distr_normal(NULL,0);
   par = unur_arou_new(distr); ]

~_init(par,NULL);
	--> expected_setfailed --> UNUR_ERR_PAR_INVALID

~_sample(par,NULL);
	--> expected_setfailed --> UNUR_ERR_NULL

~_sample(par,check_sample);
	--> expected_setfailed --> UNUR_ERR_PAR_INVALID

unur_par_free(par);


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

[get]

[get - invalid NULL ptr: 
   gen = NULL; ]

~_params(gen,(size_t)0);
	--> expected_NULL --> UNUR_ERR_NULL

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

# [chg]

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

[init]

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

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


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

[reinit]

[reinit - does not exist:
   distr = unur_distr_exponential(NULL,0);
   par = unur_cext_new(distr);
   unur_cext_set_sample(par,exp1_sample);
   gen = unur_init(par); <-- ! NULL ]

unur_reinit( gen );
	--> expected_reinit


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

[sample]

[sample - compare clone:
   UNUR_GEN *clone;
   distr = unur_distr_exponential(NULL,0);
   par = NULL;
   gen = NULL; ]

/* external generator 1 */
par = unur_cext_new(distr);
unur_cext_set_sample(par,exp1_sample);
gen = unur_init(par);
	-->compare_sequence_gen_start

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

/* cstd */
unur_free(gen);
par = unur_cstd_new(distr);
gen = unur_init(par);
	-->compare_sequence_gen


/* external generator A */
unur_free(gen);
par = unur_cext_new(distr);
unur_cext_set_sample(par,expa_sample);
gen = unur_init(par);
	-->compare_sequence_gen

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

/* external generator B */
unur_free(gen);
par = unur_cext_new(distr);
unur_cext_set_init(par,expb_init);
unur_cext_set_sample(par,expb_sample);
gen = unur_init(par);
	-->compare_sequence_gen

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

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

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

/* external generator 1 */
par = unur_cext_new(distr);
unur_cext_set_sample(par,exp1_sample);
gen = unur_init(par);
	-->compare_sequence_gen_start

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

/* cstd */
unur_free(gen);
par = unur_cstd_new(distr);
gen = unur_init(par);
	-->compare_sequence_gen

/* external generator A */
unur_free(gen);
par = unur_cext_new(distr);
unur_cext_set_sample(par,expa_sample);
gen = unur_init(par);
	-->compare_sequence_gen

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

/* external generator B */
unur_free(gen);
par = unur_cext_new(distr);
unur_cext_set_init(par,expb_init);
unur_cext_set_sample(par,expb_sample);
gen = unur_init(par);
	-->compare_sequence_gen

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

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

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

/* external generator A */
unur_free(gen);
par = unur_cext_new(distr);
unur_cext_set_sample(par,expa_sample);
gen = unur_init(par);
	-->compare_sequence_gen_start

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

/* external generator B */
unur_free(gen);
par = unur_cext_new(distr);
unur_cext_set_init(par,expb_init);
unur_cext_set_sample(par,expb_sample);
gen = unur_init(par);
	-->compare_sequence_gen

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

/* cstd */
unur_free(gen);
par = unur_cstd_new(distr);
gen = unur_init(par);
	-->compare_sequence_gen


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

[validate]

[validate - generators:]

# exponential(1):
#	standard distribution; do not read any parameters
par[0] = unur_cext_new(@distr@);
unur_cext_set_sample(par,exp1_sample);

# exponential(lambda): 
#	use pointer to parameter of distribution in sampling routine
par[1] = unur_cext_new(@distr@);
unur_cext_set_sample(par,expa_sample);

# exponential(lambda): 
#	store parameter of distribution in generator object during init
par[2] = unur_cext_new(@distr@);
unur_cext_set_init(par,expb_init);
unur_cext_set_sample(par,expb_sample);

# exponential
#	store parameter of distribution in generator object during init
#      change parameters
{ UNUR_DISTR *dg =NULL;
par[3] = unur_cext_new(@distr@);
unur_cext_set_init(par,expb_init);
unur_cext_set_sample(par,expb_sample);
fpm[0] = 2.;
dg = unur_get_distr(gen);
unur_distr_cont_set_pdfparams(dg,fpm,1);
unur_reinit(gen); }


[validate - distributions:]

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

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

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


## number of distributions: 3

[validate - test chi2:]

#  + ... pass test
#  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] ... Exponential(0)
#   [1] ... Exponential(lambda): use pointer to distribution
#   [2] ... Exponential(lambda): store distrparams in object
#   [3] ... Exponential, reinit with changed parameters
#
#gen	0  1  2  3	# distribution
#-------------------------------------------------------------
 <0>	+  +  +  +	# standard exponential
 <1>	-  +  +  +	# exponential (5)
 <2>	+  +  +  +	# exponential (1)


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

[verbatim]

int check_init(UNUR_GEN *gen ATTRIBUTE__UNUSED) { return UNUR_SUCCESS; }
double check_sample(UNUR_GEN *gen ATTRIBUTE__UNUSED) { return 0.; }

/* ............. */

double exp1_sample(UNUR_GEN *gen) { 
	double U = unur_sample_urng(gen);
	return (-log(1. - U));
}

/* ............. */

double expa_sample(UNUR_GEN *gen) { 
\#	define sigma (params[0])     /* scale */
	double U = unur_sample_urng(gen);
	double X = -log(1. - U);
	double *params = unur_cext_get_distrparams(gen);
	if (params) 
		return sigma * X;
	else
		return X;
\#	undef sigma
}

/* ............. */

int expb_init(UNUR_GEN *gen) { 
\#	define sigma (params[0])     /* scale */
	double *params = unur_cext_get_distrparams(gen);
	double *genpar = unur_cext_get_params(gen, sizeof(double));
	genpar[0] = (params) ? sigma : 1.;
	return UNUR_SUCCESS;
\#	undef sigma
}

double expb_sample(UNUR_GEN *gen) { 
\#	define sigma (params[0])     /* scale */
	double U = unur_sample_urng(gen);
	double X = -log(1. - U);
	double *params = unur_cext_get_params(gen,(size_t)0);
	return sigma * X;
\#	undef sigma
}

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