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

[main]

[main - data:]

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

[main - header:]

/* prototypes */

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

UNUR_DISTR *get_distr_with_data( void );
UNUR_DISTR *get_distr_with_data2( void );

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

[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_cemp_new();   /* no data given */ ]

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


[new - data missing in distribution object:
   double hist[] = {0.1,0.2,0.3,0.4,0.5,0.4,0.3,0.2,0.1};
   distr = unur_distr_cemp_new();
   unur_distr_cemp_set_hist_prob(distr,hist,9); ]

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


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

# [set]

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

# [get]

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

# [chg]

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

[init]

[init - run init:
   distr = get_distr_with_data();
   par = unur_hist_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

# this should be o.k.
	--> none --> 0x0u

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

[reinit]

#[reinit - does not exist:
#   distr = get_distr_with_data();
#   par = unur_hist_new(distr);
#   gen = unur_init( par ); <-- ! NULL ]
#
#unur_reinit( gen );
#	--> expected_setfailed --> UNUR_ERR_NO_REINIT
#
#unur_sample_cont( gen );
#	--> expected_INFINITY --> UNUR_ERR_GEN_CONDITION
#

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

[sample]

[sample - compare variants:
   UNUR_DISTR *distr1 = get_distr_with_data();
   UNUR_DISTR *distr2 = get_distr_with_data2();
   par = unur_hist_new(distr1);
   gen = unur_init( par ); <-- ! NULL ]

/* default generator object */
	-->compare_sequence_gen_start

/* variant */
unur_free(gen);
par = unur_hist_new(distr2);
gen = unur_init(par);
	-->compare_sequence_gen

unur_distr_free(distr1);
unur_distr_free(distr2);

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

[sample - compare variant:
   double hist[] = {0.1,0.2,0.3,0.4,0.5,0.4,0.3,0.2,0.1};
   double bins[] = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.};
   distr = unur_distr_cemp_new();
   unur_distr_cemp_set_hist_prob(distr,hist,9);
   unur_distr_cemp_set_hist_domain(distr,1.,10.);
   par = unur_hist_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

/* default generator object */
	-->compare_sequence_gen_start

/* variant */
unur_free(gen);
unur_distr_free(distr);
distr = unur_distr_cemp_new();
unur_distr_cemp_set_hist_prob(distr,hist,9);
unur_distr_cemp_set_hist_bins(distr,bins,10);
unur_distr_cemp_set_hist_domain(distr,1.,100.);
par = unur_hist_new(distr);
gen = unur_init(par);
	-->compare_sequence_gen

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

[sample - compare clone:
   UNUR_GEN *clone;
   double hist[] = {0.1,0.2,0.3,0.4,0.5,0.4,0.3,0.2,0.1};
   double bins[] = {1.,2.,3.,4.,5.,6.,7.,8.,9.,10.};
   distr = unur_distr_cemp_new();
   unur_distr_cemp_set_hist_prob(distr,hist,9);
   unur_distr_cemp_set_hist_bins(distr,bins,10);
   par = unur_hist_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

/* default generator object */
	-->compare_sequence_gen_start

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

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

[sample - compare clone:
   UNUR_GEN *clone;
   distr = get_distr_with_data();
   par = unur_hist_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

/* default generator object */
	-->compare_sequence_gen_start

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

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

[sample - compare stringparser:
   double hist[] = {0.1,0.2,0.3,0.4,0.5,0.4,0.3,0.2,0.1};
   distr = unur_distr_cemp_new();
   unur_distr_cemp_set_hist_prob(distr,hist,9);
   unur_distr_cemp_set_hist_domain(distr,1.,10.);
   par = unur_hist_new(distr);
   gen = unur_init( par ); <-- ! NULL ]

/* default generator object */
	-->compare_sequence_gen_start

/* string API */
unur_free(gen);
gen = unur_str2gen("cemp; hist_prob=(0.1,0.2,0.3,0.4,0.5,0.4,0.3,0.2,0.1); \
                    hist_domain=(1.,10.) & method = hist");
	-->compare_sequence_gen

/* string API */
unur_free(gen);
gen = unur_str2gen("cemp; hist_prob=(0.1,0.2,0.3,0.4,0.5,0.4,0.3,0.2,0.1); \
                    hist_bins=(1.,2.,3.,4.,5.,6.,7.,8.,9.,10.) & method = hist");
	-->compare_sequence_gen


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

[validate]

[validate - generators:]

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

[validate - distributions:]

# approximate normal distribution, bins with equal width
{ double pv[1000];
  UNUR_DISTR *normal_dist;
  int i;
  double xmin, xmax;
  double fxmin, fxmax;
  /* xmin = -5.; */
  fxmin = 0.;
  normal_dist = unur_distr_normal(NULL,0);
  for (i=0; i<1000; i++) {
    xmax = -5. + i/100.;
    fxmax = unur_distr_cont_eval_cdf(xmax,normal_dist);
    pv[i] = fxmax - fxmin;
    /* xmin = xmax; */
    fxmin = fxmax; }
  unur_distr_free(normal_dist);
  distr[0] = unur_distr_cemp_new();
  unur_distr_cemp_set_hist(distr[0],pv,1000,-5.,5.); }

# approximate normal distribution, bins with different widths
{ double pv[1000];
  double bins[1001];
  UNUR_DISTR *normal_dist;
  int i;
  double xmin, xmax;
  double fxmin, fxmax;
  normal_dist = unur_distr_normal(NULL,0);
  bins[500] = 0.;
  for (i=501; i<=1000; i++)
	bins[i] = bins[i-1] + (i-500)/25000.;
  for (i=499; i>=0; i--)
	bins[i] = bins[i+1] + (i-500)/25000.;
  xmin = bins[0];
  fxmin = unur_distr_cont_eval_cdf(xmin,normal_dist);
  pv[0] = unur_distr_cont_eval_cdf(bins[0],normal_dist);
  for (i=0; i<1000; i++) {
    xmax = bins[i+1];
    fxmax = unur_distr_cont_eval_cdf(xmax,normal_dist);
    pv[i] = fxmax - fxmin;
    xmin = xmax;
    fxmin = fxmax; }
  unur_distr_free(normal_dist);
  distr[1] = unur_distr_cemp_new();
  unur_distr_cemp_set_hist_prob(distr[1],pv,1000);
  unur_distr_cemp_set_hist_bins(distr[1],bins,1001); }


[validate - test chi2:]

#  + ... pass test
#  0 ... fail to initialize generator
#  - ... fail test
#  . ... do not run test
#  # ... comment
#
# generators:
#   [0] default
#
#	[0]  # distribution
#----------------------------------------------------------------
 <0>	 +   # approximate normal distribution, bins with equal width
 <1>	 +   # approximate normal distribution, bins with different widths


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

[verbatim]

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

UNUR_DISTR *get_distr_with_data( void )
{
\#define HIST_SIZE 20
  double hist[HIST_SIZE];
  UNUR_DISTR *distr;
  int i;

  unur_urng_fish_reset(NULL);

  for (i=0; i<HIST_SIZE; i++)
    hist[i] = (2.*i)/((double)HIST_SIZE) + unur_urng_fish(NULL);

  distr = unur_distr_cemp_new();
  unur_distr_cemp_set_hist(distr,hist,HIST_SIZE,-2.5,7.5);

  return distr;

\#undef HIST_SIZE
} /* end of get_distr_with_data() */

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

UNUR_DISTR *get_distr_with_data2( void )
{
\#define HIST_SIZE 20
  double hist[HIST_SIZE];
  UNUR_DISTR *distr;
  int i;

  unur_urng_fish_reset(NULL);

  for (i=0; i<HIST_SIZE; i++)
    hist[i] = (2.*i)/((double)HIST_SIZE) + unur_urng_fish(NULL);

  distr = unur_distr_cemp_new();
  unur_distr_cemp_set_hist_prob(distr,hist,HIST_SIZE);
  unur_distr_cemp_set_hist_domain(distr,-2.5,7.5);

  return distr;

\#undef HIST_SIZE
} /* end of get_distr_with_data2() */

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

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