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

[main]

[main - data:]

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

[main - header:]

/* prototypes */

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

const int n_pv = 36;
const double pv[36]={1,2,3,4,5,6,5,3,6,7,5,4,3,4,6,7,5,3,4,3,8,6,5,4,7,7,2,2,1,4,7,4,3,7,3,2};
const double pvsum = 158.;

const double pvre[10] = {1,2,3,4,5,6,7,8,9,10};
const double pvresum = 55.;

double my_pmf(int k, const UNUR_DISTR *distr);
double my_cdf(int k, const UNUR_DISTR *distr);

/* \#define SEED   (298346) */

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

[new]

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

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

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

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

[new - data missing in distribution object:
    distr = unur_distr_discr_new();   /* no probability vector */ ]

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

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

# [set]

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

# [get]

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

# [chg]

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

[init]

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

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


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

[reinit]

[reinit - exist:
   double fpar[2] = {10.,0.63};
   distr = unur_distr_binomial(fpar,2);
   par = unur_dss_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

unur_reinit( gen );
	--> expected_reinit


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

[sample]

[sample - compare clone:
   UNUR_GEN *clone;
   double fpar[] = {10,0.3}; 
   distr = unur_distr_binomial(fpar,2);
   par = NULL;
   gen = NULL; ]

/* original generator object */
par = unur_dss_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 reinit:
   double fpar[] = {10,0.3}; 
   distr = unur_distr_binomial(fpar,2);
   par = NULL;
   gen = NULL; ]

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

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

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

[sample - compare stringparser:
   double pvec[] = {.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.};
   distr = NULL;
   par = NULL;
   gen = NULL; ]

distr = unur_distr_discr_new();
unur_distr_discr_set_pv(distr,pvec,10);
unur_distr_discr_set_pmfsum(distr,46.);
par = unur_dss_new(distr);
gen = unur_init(par);
	-->compare_sequence_gen_start
	
unur_free(gen); gen = NULL;
unur_distr_free(distr); distr = NULL;
gen = unur_str2gen( "discr; pv = (.1, .2, .3, .4, .5, .6, .7, .8, .9, 1.); pmfsum=46 \
                     & method = dss" );
	-->compare_sequence_gen


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

[validate]

[validate - generators:]

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

# reinitialized with changed domain
{ UNUR_DISTR *dg =NULL;
par[1] = unur_dss_new(@distr@);
dg = unur_get_distr(gen);
unur_distr_discr_set_domain(dg,2,7);
unur_distr_discr_upd_pmfsum(dg);
unur_reinit(gen); }

# reinitialized with changed pdf parameters
{ UNUR_DISTR *dg =NULL;
par[2] = unur_dss_new(@distr@);
fpm[0] = 10.;
fpm[1] = 0.63;
dg = unur_get_distr(gen);
unur_distr_discr_set_pmfparams(dg,fpm,2);
unur_distr_discr_upd_pmfsum(dg);
unur_reinit(gen); }

# reinitialized with changed pv
{ UNUR_DISTR *dg =NULL;
par[3] = unur_dss_new(@distr@);
dg = unur_get_distr(gen);
unur_distr_discr_set_pv(dg,pvre,10);
unur_distr_discr_upd_pmfsum(dg);
unur_reinit(gen); }


[validate - distributions:]

# probability vector with random entries
distr[0] = unur_distr_discr_new();
unur_distr_discr_set_pv(distr[0],pv,n_pv);
unur_distr_discr_set_pmfsum(distr[0],pvsum);
unur_distr_set_name(distr[0],"pv(0..35)");

distr[1] = unur_distr_discr_new();
unur_distr_discr_set_pv(distr[1],pv,n_pv);
unur_distr_discr_set_domain(distr[1],100,135);
unur_distr_discr_set_pmfsum(distr[1],pvsum);
unur_distr_set_name(distr[1],"pv(100..135)");

## PMF instead of PV
distr[2] = unur_distr_discr_new();
unur_distr_discr_set_pmf(distr[2],my_pmf);
unur_distr_discr_set_pmfsum(distr[2],pvsum);
unur_distr_set_name(distr[2],"pmf(0..35)");

distr[14] = unur_distr_discr_new();
unur_distr_discr_set_pmf(distr[14],my_pmf);
unur_distr_discr_set_domain(distr[14],0,35);
unur_distr_discr_set_pmfsum(distr[14],pvsum);
unur_distr_set_name(distr[14],"pmf(0..35)");

## CDF instead of PV
distr[3] = unur_distr_discr_new();
unur_distr_discr_set_cdf(distr[3],my_cdf);
unur_distr_set_name(distr[3],"cdf(0..35)");

distr[15] = unur_distr_discr_new();
unur_distr_discr_set_cdf(distr[15],my_cdf);
unur_distr_discr_set_domain(distr[15],0,35);
unur_distr_set_name(distr[15],"cdf(0..35)");

# geometric disctribution
fpm[0] = 0.5;
distr[4] = unur_distr_geometric(fpm,1);

fpm[0] = 0.01;
distr[5] = unur_distr_geometric(fpm,1);

# logarithmic distribution
fpm[0] = 0.1;
distr[6] = unur_distr_logarithmic(fpm,1);

fpm[0] = 0.99;
distr[7] = unur_distr_logarithmic(fpm,1);

# negative binomial distribution
fpm[0] = 0.5;
fpm[1] = 10.;
distr[8] = unur_distr_negativebinomial(fpm,2);

fpm[0] = 0.8;
fpm[1] = 10.;
distr[9] = unur_distr_negativebinomial(fpm,2);

# poisson distribution
fpm[0] = 0.1;
distr[10] = unur_distr_poisson(fpm,1);

fpm[0] = 0.999;
distr[11] = unur_distr_poisson(fpm,1);

# binomial distribution
fpm[0] = 20.;
fpm[1] = 0.8;
distr[12] = unur_distr_binomial(fpm,2);

# binomial distribution
fpm[0] = 2000.;
fpm[1] = 0.0013;
distr[13] = unur_distr_binomial(fpm,2);


# number of distributions: 16

[validate - test chi2:]

#  + ... pass test
#  0 ... fail to initialize generator
#  - ... fail test
#  . ... do not run test
#  # ... comment
#
# [0] ... default
# [1] ... reinitialized with changed domain
# [2] ... reinitialized with changed pdf parameters
# [3] ... reinitialized with changed pv
#
#gen	 0  1  2  3	# distribution
#-------------------------------------------------------------
  <0>	 +  +  .  +	# PV on [0..35] with random entries
  <1>	 +  +  .  +	# PV on [100..135] with random entries
  <2>	 +  +  .  .	# PMF on [0..35] with random entries
 <14>	 +  +  .  .	# PMF on [0..35] with random entries
  <3>	 +  .  .  .	# CDF on [0..35] with random entries
 <15>	 +  .  .  .	# CDF on [0..35] with random entries
  <4>	 +  +  .  .	# geometric (0.5)
x <5>	 +  +  .  .	# geometric (0.01)
  <6>	 +  +  .  .	# logarithmic (0.1)
x <7>	 +  +  .  .	# logarithmic (0.99)
x <8>	 +  +  .  .	# negativebinomial (0.5, 10)
  <9>	 +  +  .  .	# negativebinomial (0.8, 10)
 <10>	 +  +  .  .	# poisson (0.1)
 <11>	 +  +  .  .	# poisson (0.999)
x<12>    +  +  +  .	# binomial (20, 0.8)
x<13>    +  +  +  .	# binomial (2000, 0.0013)


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

[verbatim]

double my_pmf(int k, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
{
  if (k<0 || k>35) return 0.;
  else return pv[k];
}

double my_cdf(int k, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
{
  double sum;
  int j;

  if (k<0) return 0.;
  if (k>=35) return 1.;

  for (sum=0.,j=0; j<=k; j++)
    sum += pv[j];

  return sum/pvsum; 
}

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

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