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

[main]

[main - data:]

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

[main - header:]

/* prototypes */

double HR_decreasing(double x, const UNUR_DISTR *distr);
double CDF_decreasing(double x, const UNUR_DISTR *distr);
double HR_constant(double x, const UNUR_DISTR *distr);
double CDF_constant(double x, const UNUR_DISTR *distr);
double HR_increasing(double x, const UNUR_DISTR *distr);
double CDF_increasing(double x, const UNUR_DISTR *distr);

int unur_hrd_set_pedantic( UNUR_PAR *par, int pedantic );

\#define COMPARE_SAMPLE_SIZE   (10000)
\#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 - data missing in distribution object:
   distr = unur_distr_cont_new(); ]

/* hazard rate */
~( distr );
	--> expected_NULL --> UNUR_ERR_DISTR_REQUIRED

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

[set]

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

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


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

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

unur_par_free(par);


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

# [get]

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

[chg]

[chg - invalid generator object:
   distr = unur_distr_normal(NULL,0);
   par = unur_arou_new(distr);
   unur_set_debug(par,0);
   gen = unur_init( par ); <-- ! NULL ]

~_verify(gen,1);
	--> expected_setfailed --> UNUR_ERR_GEN_INVALID


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

[init]

[init - left border no valid upper bound:
   gen = NULL;
   distr = unur_distr_cont_new();
   unur_distr_cont_set_hr(distr,HR_increasing);
   par = unur_hrd_new(distr); <-- ! NULL]

gen = unur_init( par );
        --> expected_NULL --> UNUR_ERR_GEN_CONDITION


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

[reinit]

[reinit - does not exist:
   distr = unur_distr_cont_new();
   unur_distr_cont_set_hr(distr,HR_decreasing);
   par = unur_hrd_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

unur_reinit( gen );
	--> expected_reinit

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

[sample]

[sample - compare:
    distr = unur_distr_cont_new();
    unur_distr_cont_set_hr(distr,HR_decreasing);
    par = NULL; ]

/* default algorithm */
par = unur_hrd_new(distr);
	-->compare_sequence_par_start

/* default algorithm - verifying mode */
par = unur_hrd_new(distr);
unur_hrd_set_verify(par,1);
	-->compare_sequence_par

/* default algorithm - ignore invalid boundary */
unur_distr_cont_set_domain(distr,-10.,10.);
par = unur_hrd_new(distr);
	-->compare_sequence_par_start

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

[sample - compare reinit:
   distr = unur_distr_cont_new();
   unur_distr_cont_set_hr(distr,HR_decreasing);
   par = NULL;
   gen = NULL; ]

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

/* reinit */
unur_reinit(gen);
        -->compare_sequence_gen

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

[sample - compare stringparser:
   distr = NULL;
   par = NULL;
   gen = NULL; ]

distr = unur_distr_cont_new();
unur_distr_cont_set_hrstr(distr,"1/(1+x)");
par = unur_hrd_new(distr);
gen = unur_init(par);
	-->compare_sequence_gen_start

unur_free(gen); gen = NULL;
unur_distr_free(distr); distr = NULL;
gen = unur_str2gen( "cont; hr = \"1/(1+x)\"; domain = (0,inf)& \
	             method = hrd" );
	-->compare_sequence_gen

unur_free(gen); gen = NULL;
distr = unur_distr_cont_new();
unur_distr_cont_set_hrstr(distr,"1/(1+x)");
par = unur_hrd_new(distr);
gen = unur_init(par);
	-->compare_sequence_gen_start

unur_free(gen); gen = NULL;
unur_distr_free(distr); distr = NULL;
gen = unur_str2gen( "cont; hr = \"1/(1+x)\"; domain = (0,inf)& \
		     method = hrd" );
	-->compare_sequence_gen


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

[validate]

[validate - generators:]

# default program
par[0] = unur_hrd_new(@distr@);


[validate - distributions:]

# decreasing hazard rate
distr[0] = unur_distr_cont_new();
unur_distr_set_name(distr[0],"decreasing HR");
unur_distr_cont_set_hr(distr[0],HR_decreasing);
unur_distr_cont_set_cdf(distr[0],CDF_decreasing);

# constant hazard rate
distr[1] = unur_distr_cont_new();
unur_distr_set_name(distr[1],"constant HR");
unur_distr_cont_set_hr(distr[1],HR_constant);
unur_distr_cont_set_cdf(distr[1],CDF_constant);

# increasing hazard rate
distr[2] = unur_distr_cont_new();
unur_distr_set_name(distr[2],"increasing HR");
unur_distr_cont_set_hr(distr[2],HR_increasing);
unur_distr_cont_set_cdf(distr[2],CDF_increasing);

# number of distributions: 3

[validate - test chi2:]

#  + ... pass test
#  0 ... fail to initialize generator
#  - ... fail test
#  . ... do not run test
#  # ... comment
#
# generators:
#  [0] ... default variant
#
#gen	0   # distribution
#---------------------------------------------
 <0>	+   # hazard rate decreasing 
 <1>	+   # hazard rate constant
 <2>	-   # hazard rate increasing 

[validate - verify hat:]

#  + ... pass test
#  ~ ... fail in at most 1% of samples
#  0 ... fail to initialize generator
#  - ... fail test
#  . ... do not run test
#  # ... comment
#
# generators:
#  [0] ... default variant
#
#gen	0   # distribution
#---------------------------------------------
 <0>	+   # hazard rate decreasing 
 <1>	+   # hazard rate constant
 <2>	-   # hazard rate increasing 


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

[verbatim]

double HR_decreasing(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* example with decreasing hazard rate */
{ return (1./(1.+x)); }

double CDF_decreasing(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* CDF for example with decreasing hazard rate */
{ return (x/(1. + x)); }

double HR_constant(double x ATTRIBUTE__UNUSED, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* example with constant hazard rate: standard expontential */
{ return 1.; }

double CDF_constant(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* CDF for example with constant hazard rate: standard expontential */
{ return (1.-exp(-x)); }

double HR_increasing(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* example with increasing hazard rate: Weibull (alpha=3,beta=1) */
{ return (3*x*x); }

double CDF_increasing(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* CDF for example with increasing hazard rate: Weibull (alpha=3,beta=1) */
{ return (1.-exp(-x*x*x)); }


/* dummy function */
int unur_hrd_set_pedantic( UNUR_PAR *par ATTRIBUTE__UNUSED, int pedantic ATTRIBUTE__UNUSED)
{ return 1; }

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