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

[main]

[main - data:]

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

[main - header:]

/* prototypes */
double HR_increasing_gm31(double x, const UNUR_DISTR *distr);

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

/* we need marginal distributions for the chi2 tests */
\#define unur_distr_multinormal  unur_distr_multinormal_w_marginals

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

[new]

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

# [set]

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

# [get]

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

# [chg]

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

# [init]

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

# [reinit]

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

[sample]

[sample - run_tests for AUTO:
   distr = unur_distr_normal(NULL,0); 
   par = NULL; ]

par = unur_auto_new(distr);
unur_run_tests(par,~0u,TESTLOG);
	-->none	 --> UNUR_SUCCESS


[sample - run_tests for AUTO:
   double fpm[1] = {0.5};
   distr = unur_distr_geometric(fpm,1); 
   par = NULL; ]

par = unur_auto_new(distr);
unur_run_tests(par,~0u,TESTLOG);
	-->none	 --> UNUR_SUCCESS


[sample - run_tests for AUTO:
   double data[] = {1.,2.,3.,4.,5.,6.,7.,8.,9.};
   distr = unur_distr_cemp_new();
   unur_distr_cemp_set_data(distr,data,9);
   par = NULL; ]

par = unur_auto_new(distr);
unur_run_tests(par,~0u,TESTLOG);
	-->none	 --> UNUR_SUCCESS


[sample - run_tests for AUTO:
   const int dim = 3;
   double mean[] = {1.,2.,3.};
   double covar[] = { 2., 2., 1.,   2., 4., 3.,   1., 3., 3. };
   distr = unur_distr_multinormal( dim, mean, covar );
   par = NULL; ]

par = unur_auto_new(distr);
unur_run_tests(par,~0u,TESTLOG);
	-->none	 --> UNUR_SUCCESS


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

# [validate]

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

[special]

[special - decl:]

  int samplesize = 10000;
  double fpm[10];
  double Rsq, time_setup, time_marginal;

  UNUR_DISTR *distr;
  UNUR_PAR   *par;
  UNUR_GEN   *gen;

[special - start:]

  /* unur_test_par_count_pdf() */

  distr = unur_distr_normal(NULL,0);
  par = unur_tdr_new(distr);
  unur_tdr_set_usedars(par,0);
  unur_test_par_count_pdf(par,samplesize,1,TESTLOG);
  gen = unur_init(par);
  unur_test_count_pdf(gen,samplesize,1,TESTLOG);
  unur_free(gen);
  unur_distr_free(distr);

  distr = unur_distr_normal_wo_logpdf(NULL,0);
  par = unur_tdr_new(distr);
  unur_test_par_count_pdf(par,samplesize,1,TESTLOG);
  gen = unur_init(par);
  unur_test_count_pdf(gen,samplesize,1,TESTLOG);
  unur_free(gen);
  unur_distr_free(distr);

  distr = unur_distr_normal(NULL,0);
  par = unur_ninv_new(distr);
  unur_test_par_count_pdf(par,samplesize,1,TESTLOG);
  gen = unur_init(par);
  unur_test_count_pdf(gen,samplesize,1,TESTLOG);
  unur_free(gen);
  unur_distr_free(distr);

  distr = unur_distr_normal(NULL,0);
  par = unur_hinv_new(distr);
  unur_test_par_count_pdf(par,samplesize,1,TESTLOG);
  gen = unur_init(par);
  unur_test_count_pdf(gen,samplesize,1,TESTLOG);
  unur_free(gen);
  unur_distr_free(distr);

  distr = unur_distr_cont_new();
  unur_distr_set_name(distr,"HR");
  unur_distr_cont_set_hr(distr,HR_increasing_gm31);
  par = unur_hri_new(distr);
  unur_test_par_count_pdf(par,samplesize,1,TESTLOG);
  gen = unur_init(par);
  unur_test_count_pdf(gen,samplesize,1,TESTLOG);
  unur_free(gen);
  unur_distr_free(distr);

  fpm[0] = 0.5;
  distr = unur_distr_geometric(fpm,1);
  par = unur_dgt_new(distr);
  unur_test_par_count_pdf(par,samplesize,1,TESTLOG);
  gen = unur_init(par);
  unur_test_count_pdf(gen,samplesize,1,TESTLOG);
  unur_free(gen);
  unur_distr_free(distr);

  fpm[0] = 0.5;
  distr = unur_distr_geometric(fpm,1);
  par = unur_dari_new(distr);
  unur_test_par_count_pdf(par,samplesize,1,TESTLOG);
  gen = unur_init(par);
  unur_test_count_pdf(gen,samplesize,1,TESTLOG);
  unur_free(gen);
  unur_distr_free(distr);

  distr = unur_distr_multinormal(3,NULL,NULL);
  par = unur_vnrou_new(distr);
  unur_test_par_count_pdf(par,samplesize,1,TESTLOG);
  gen = unur_init(par);
  unur_test_count_pdf(gen,samplesize,1,TESTLOG);
  unur_free(gen);
  unur_distr_free(distr);

  distr = unur_distr_multinormal_wo_logpdf(3,NULL,NULL);
  par = unur_vnrou_new(distr);
  unur_test_par_count_pdf(par,samplesize,1,TESTLOG);
  gen = unur_init(par);
  unur_test_count_pdf(gen,samplesize,1,TESTLOG);
  unur_free(gen);
  unur_distr_free(distr);

  /* unur_test_count_urng() */

  distr = unur_distr_normal(NULL,0);
  par = unur_tdr_new(distr);
  unur_tdr_set_usedars(par,0);
  gen = unur_init(par);
  unur_test_count_urn(gen,samplesize,1,TESTLOG);
  unur_free(gen);
  unur_distr_free(distr);


  /* test timing routines */

  Rsq = unur_test_timing_R(NULL,NULL,NULL,5,&time_setup,&time_marginal);
  fprintf(TESTLOG,"\nR^2 = %g, setup time = %g, marginal generation time = %g\n",
	  Rsq, time_setup, time_marginal);

  Rsq = unur_test_timing_R(NULL,"cont","pinv",5,&time_setup,&time_marginal);
  fprintf(TESTLOG,"\nR^2 = %g, setup time = %g, marginal generation time = %g\n",
	  Rsq, time_setup, time_marginal);

  distr = unur_distr_normal(NULL,0);
  par = unur_tdr_new(distr);
  Rsq = unur_test_timing_R(par,NULL,NULL,5,&time_setup,&time_marginal);
  unur_distr_free(distr);
  fprintf(TESTLOG,"\nR^2 = %g, setup time = %g, marginal generation time = %g\n",
	  Rsq, time_setup, time_marginal);

  Rsq = unur_test_timing_R(NULL,"normal","pinv",5,&time_setup,&time_marginal);
  fprintf(TESTLOG,"\nR^2 = %g, setup time = %g, marginal generation time = %g\n",
	  Rsq, time_setup, time_marginal);


  /* test finished */
  FAILED = 0;

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

[verbatim]

double HR_increasing_gm31(double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
     /* example with increasing hazard rate: gamma (alpha=3,beta=1) */
{ return (x*x)/(x*x+2.*x+2.); }

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