1 /*
2 file automatically generated by make_test_files.pl
3 Tue Apr 19 14:01:03 2011
4 */
5
6 /*****************************************************************************
7 * *
8 * UNU.RAN -- Universal Non-Uniform Random number generator *
9 * *
10 *****************************************************************************/
11
12 /**
13 ** Tests for PINV
14 **/
15
16 /*---------------------------------------------------------------------------*/
17 #include "testunuran.h"
18
19 #ifdef UNUR_URNG_DEFAULT_RNGSTREAM
20 #include <RngStream.h>
21 #endif
22 /*---------------------------------------------------------------------------*/
23
24 /*---------------------------------------------------------------------------*/
25 /* global variables */
26
27 static FILE *TESTLOG; /* test log file */
28 static FILE *UNURANLOG; /* unuran log file */
29
30 static int test_ok = TRUE; /* all tests ok (boolean) */
31 static int fullcheck = FALSE; /* whether all checks are performed */
32
33 static TIMER watch; /* stop watch */
34
35 /*---------------------------------------------------------------------------*/
36
37 void run_verify_generator( FILE *LOG, int line, UNUR_PAR *par );
38
39 int unur_pinv_set_verify( UNUR_PAR *par, int verify);
40
41
42 /*---------------------------------------------------------------------------*/
43
44 void test_new (void);
45 void test_set (void);
46 void test_get (void);
47 void test_chg (void);
48 void test_init (void);
49 void test_reinit (void);
50 void test_sample (void);
51 void test_validate (void);
52 void test_special(void);
53
54 /*---------------------------------------------------------------------------*/
55
56
57
58 /* header files */
59 #include <methods/x_gen_source.h>
60
61 /* -- which tests for u-error should be performed (for development) -- */
62
63 #define DEVEL (0) /* whether to run tests in development mode */
64 #define ALL (1)
65
66 #define UERROR_STANDARDDIST (1)
67 #define UERROR_QUASIPDF DEVEL
68 #define UERROR_VANISHINGPDF DEVEL
69 #define UERROR_TRUNCATED (1)
70 #define UERROR_UNBOUNDEDPDF (0)
71 #define UERROR_MULTIMODAL DEVEL
72 #define UERROR_MULTIMODAL_VANISHINGPDF DEVEL
73
74 /* variants */
75 static int UERROR_PDF = TRUE;
76 static int UERROR_CDF = TRUE;
77
78 /* orders */
79 static int UERROR_ORDER_MIN = 3;
80 static int UERROR_ORDER_MAX = 17;
81 static int UERROR_ORDER_STEP = 1;
82
83 /* smoothness */
84 static int SMOOTHNESS_MAX = 2;
85
86 /* u-resolutions */
87 static double UERROR_URESOLUTION_MAX = 1.e-8;
88 static double UERROR_URESOLUTION_MIN = 0.99e-13;
89 static double UERROR_URESOLUTION_STEP = 0.1;
90
91 /* we run all tests only in 'fullcheck' mode */
92 #define set_uerror_tests() \
93 if (!fullcheck) { \
94 /* UERROR_ORDER_STEP = 3; */ \
95 UERROR_URESOLUTION_MAX = 1.e-8; \
96 UERROR_URESOLUTION_MIN = 0.99e-12; \
97 UERROR_URESOLUTION_STEP = 0.01; \
98 }
99 /* see also SKIPORDER in routine pinv_error_experiment() below */
100
101 /* sample size */
102 static const int UERROR_SAMPLESIZE = 100000;
103
104
105 /* -- constants -- */
106
107 #define COMPARE_SAMPLE_SIZE (500)
108 #define VIOLATE_SAMPLE_SIZE (20)
109
110 /* #define SEED (298346) */
111
112 #ifndef M_PI
113 #define M_PI 3.14159265358979323846264338328 /* pi */
114 #endif
115
116
117 /* -- macros -- */
118
119 #define set_debug_flag(par) \
120 do { \
121 if (fullcheck) unur_set_debug((par),~0u); \
122 else unur_set_debug((par),1u); \
123 } while (0);
124
125
126 /* -- prototypes -- */
127
128 int pinv_error_experiment( UNUR_PAR *par, int samplesize );
129 int pinv_error_gen_experiment( UNUR_GEN *gen,
130 double u_resolution, int order, int samplesize );
131
132 double neg_exponential_cdf( double x, const UNUR_DISTR *distr );
133 double neg_exponential_pdf( double x, const UNUR_DISTR *distr );
134
135 double neg_exponential_1_cdf( double x, const UNUR_DISTR *distr );
136 double neg_exponential_1_pdf( double x, const UNUR_DISTR *distr );
137
138 double sin_2_cdf( double x, const UNUR_DISTR *distr );
139 double sin_2_pdf( double x, const UNUR_DISTR *distr );
140
141 double sin_10_cdf( double x, const UNUR_DISTR *distr );
142 double sin_10_pdf( double x, const UNUR_DISTR *distr );
143
144
145
146
147
148
149
150 /*---------------------------------------------------------------------------*/
151
152 #ifndef CHI2_FAILURES_TOLERATED
153 # define CHI2_FAILURES_TOLERATED DEFAULT_CHI2_FAILURES_TOLERATED
154 #endif
155
156 /*---------------------------------------------------------------------------*/
157 /* [verbatim] */
158
159
160
161
162
163 /*****************************************************************************/
164 /* run unur_test_u_error for a particular generator object and print result */
165
166 int
pinv_error_gen_experiment(UNUR_GEN * gen,double u_resolution,int order,int samplesize)167 pinv_error_gen_experiment( UNUR_GEN *gen, /* generator object */
168 double u_resolution, /* maximal tolerated u-error */
169 int order, /* order of polynomial */
170 int samplesize ) /* sample size for error experiment */
171 /* returns 0 if maxerror < u_resolution, errorcode otherwise */
172 {
173 int i, nfpar;
174 const double *fpar;
175 const UNUR_DISTR *distr;
176 const char *genid;
177 int score;
178
179 /* check for invalid NULL pointer */
180 if (gen==NULL) {
181 fprintf(TESTLOG,"\n--setup failed !! --\n");
182 printf("(!!+)"); fflush(stdout);
183 return 100;
184 }
185
186 /* get data about generator object */
187 distr = unur_get_distr(gen);
188 genid = unur_get_genid(gen);
189
190 /* print data about distribution */
191 fprintf(TESTLOG,"%s: %s distribution",genid,unur_distr_get_name(distr));
192 nfpar = unur_distr_cont_get_pdfparams(distr,&fpar);
193 if (nfpar) {
194 fprintf(TESTLOG," with parameters ");
195 for(i=0;i<nfpar;i++) fprintf(TESTLOG," | %g",fpar[i]);
196 fprintf(TESTLOG," |");
197 }
198 fprintf(TESTLOG,":\n");
199
200 /* print chosen parameter for method PINV and for experiment */
201 fprintf(TESTLOG,"%s: setting: order = %d, u-error <= %g, samplesize = %d\n",
202 genid,order,u_resolution,samplesize);
203 /* number of intervals */
204 fprintf(TESTLOG,"%s: #intervals = %d", genid, unur_pinv_get_n_intervals(gen));
205 /* number of function calls */
206 if (get_counter_pdf() > 0) {
207 fprintf(TESTLOG,"\t#PDF calls = %d\t(per interval = %d)",
208 get_counter_pdf(),
209 ( (unur_pinv_get_n_intervals(gen)!=0) ?
210 get_counter_pdf() / unur_pinv_get_n_intervals(gen) : -1 ) );
211 }
212 if (get_counter_logpdf() > 0) {
213 fprintf(TESTLOG,"\t#logPDF calls = %d\t(per interval = %d)",
214 get_counter_logpdf(),
215 ( (unur_pinv_get_n_intervals(gen)!=0) ?
216 get_counter_logpdf() / unur_pinv_get_n_intervals(gen) : -1 ) );
217 }
218 if (get_counter_cdf() > 0) {
219 fprintf(TESTLOG,"\t#CDF calls = %d\t(per interval = %d)",
220 get_counter_cdf(),
221 ( (unur_pinv_get_n_intervals(gen)!=0) ?
222 get_counter_cdf() / unur_pinv_get_n_intervals(gen) : -1 ) );
223 }
224 fprintf(TESTLOG,"\n");
225
226 /* run test */
227 score = run_validate_u_error( TESTLOG, gen, distr, u_resolution, samplesize );
228
229 /* return score */
230 fprintf(TESTLOG,"\n"); fflush(TESTLOG);
231 return score;
232
233 } /* end of pinv_error_gen_experiment() */
234
235 /*****************************************************************************/
236 /* run experiment for a particular distribution object */
237
238 int
pinv_error_experiment(UNUR_PAR * par,int samplesize)239 pinv_error_experiment( UNUR_PAR *par, /* parameter object */
240 int samplesize ) /* samplesize for error experiment */
241 /* returns 0 if maxerror < u_resolution, errorcode otherwise */
242 {
243 UNUR_PAR *par_clone; /* working copy of parameter object */
244 UNUR_GEN *gen; /* generator object */
245
246 int order = 3;
247 int smooth = 0;
248 double u_resolution = 1.e-8; /* maximal tolerated u-error */
249 int errorsum = 0;
250
251 int variant;
252
253 /* check for invalid NULL pointer */
254 if (par==NULL) {
255 printf(" NULL! ");
256 return 1000;
257 }
258
259 /* -- loop smoothness -- */
260 for (smooth=0; smooth <= SMOOTHNESS_MAX; smooth++) {
261
262 /* -- loop variante -- */
263 for (variant=0; variant<2; ++variant) {
264 /* variant==0 --> use PDF */
265 /* variant==1 --> use CDF */
266
267 switch (variant) {
268
269 case 0: /* run variant PDF+Lobatto */
270 if (UERROR_PDF) printf("<PDF:%d>",smooth);
271 else continue;
272 break;
273
274 case 1: /* run variant CDF */
275 if (UERROR_CDF) printf("<CDF:%d>",smooth);
276 else continue;
277 break;
278
279 default:
280 continue;
281 }
282
283 /* -- loop order -- */
284 for ( order=UERROR_ORDER_MIN; order<=UERROR_ORDER_MAX; order+=UERROR_ORDER_STEP) {
285
286 /* prevent warning from invalid order */
287 if (smooth==1 && order % 2 != 1) continue;
288 if (smooth==2 && order % 3 != 2) continue;
289
290 /* SKIPORDER:
291 * when we do not run in fullcheck mode, we skip some orders. */
292 if (!fullcheck) {
293 switch (smooth) {
294 case 0:
295 if (! (order==3 || order==5 || order==8 || order==12 || order==17) )
296 continue;
297 break;
298 case 1:
299 if (order==7 || order==11 || order==15)
300 continue;
301 break;
302 case 2:
303 if (order == 14)
304 continue;
305 break;
306 }
307 }
308
309 /* -- loop u-resolution -- */
310 for ( u_resolution = UERROR_URESOLUTION_MAX;
311 u_resolution > UERROR_URESOLUTION_MIN; u_resolution *= UERROR_URESOLUTION_STEP ) {
312
313 if (!fullcheck) {
314 if (smooth==2 && u_resolution < 0.99e-10)
315 /* setup fails for some truncated distributions. */
316 /* so we skip it when not run in fullcheck mode. */
317 continue;
318 }
319
320 /* make a working copy */
321 par_clone = _unur_par_clone(par);
322
323 /* set variant */
324 switch (variant) {
325 case 0: unur_pinv_set_usepdf(par_clone); break;
326 case 1: unur_pinv_set_usecdf(par_clone); break;
327 }
328
329 /* maximum number of subintervals */
330 /**/ if (order <= 3 && u_resolution < 1.e-12) {
331 unur_pinv_set_max_intervals(par_clone,100000);
332 } else if (u_resolution < 1.e13) {
333 unur_pinv_set_max_intervals(par_clone,100000);
334 }
335
336 /* start counter for PDF calls */
337 start_counter_fcalls(par_clone);
338
339 /* create generator object */
340 unur_pinv_set_order(par_clone,order);
341 unur_pinv_set_smoothness(par_clone,smooth);
342 unur_pinv_set_u_resolution(par_clone,u_resolution);
343 set_debug_flag(par_clone);
344 gen = unur_init(par_clone);
345
346 /* run test */
347 errorsum += pinv_error_gen_experiment(gen, u_resolution, order, samplesize);
348
349 /* clear memory */
350 unur_free(gen);
351 stop_counter_fcalls();
352
353 } /* -- end loop u-resolution -- */
354
355 } /* -- end end loop order -- */
356
357 } /* -- end loop variant */
358
359 } /* -- end loop smoothness -- */
360
361 unur_par_free(par);
362
363 return errorsum;
364 } /* end of pinv_error_experiment() */
365
366 /*****************************************************************************/
367
368
369 /*---------------------------------------------------------------------------*/
370 /* "negative" exponential distribution */
371 /* */
372 /* / exp(x) if x <= 0 */
373 /* f(x) = < */
374 /* \ 0 otherwise */
375 /* */
neg_exponential_pdf(double x,const UNUR_DISTR * distr ATTRIBUTE__UNUSED)376 double neg_exponential_pdf( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
377 {
378 if (x>0.)
379 return 0.;
380 else
381 return (exp(x));
382 }
383
neg_exponential_cdf(double x,const UNUR_DISTR * distr ATTRIBUTE__UNUSED)384 double neg_exponential_cdf( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
385 {
386 if (x>0.)
387 return 1.;
388 else
389 return (exp(x));
390 }
391
392 /*---------------------------------------------------------------------------*/
393 /* "shifted negative" exponential distribution */
394 /* */
395 /* / exp(x-s) if x <= s */
396 /* f(x) = < */
397 /* \ 0 otherwise */
398 /* */
399
400 #define shift (-1.)
401
neg_exponential_1_pdf(double x,const UNUR_DISTR * distr ATTRIBUTE__UNUSED)402 double neg_exponential_1_pdf( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
403 {
404 x = x-shift;
405
406 if (x>0.)
407 return 0.;
408 else
409 return (exp(x));
410 }
411
neg_exponential_1_cdf(double x,const UNUR_DISTR * distr ATTRIBUTE__UNUSED)412 double neg_exponential_1_cdf( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
413 {
414 x = x-shift;
415
416 if (x>=0.)
417 return 1.;
418 else
419 return (exp(x));
420 }
421
422 #undef shift
423
424
425 /*---------------------------------------------------------------------------*/
426 /* */
427 /* / 0.05 + 0.45*(1 +sin(2 Pi x)) if |x| <= 1 */
428 /* f(x) = < */
429 /* \ 0 otherwise */
430 /* */
sin_2_pdf(double x,const UNUR_DISTR * distr ATTRIBUTE__UNUSED)431 double sin_2_pdf( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
432 {
433 if (fabs(x) > 1.)
434 return 0.;
435 else
436 return (0.05 + 0.45*(1.+sin(2.*M_PI*x)));
437 } /* end of sin_pdf() */
438
439 /* The CDF of our distribution: */
sin_2_cdf(double x,const UNUR_DISTR * distr ATTRIBUTE__UNUSED)440 double sin_2_cdf( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
441 {
442 if (x < -1.)
443 return 0.;
444 else if(x<=1.)
445 return (0.05*(x+1) + 0.9*(1.+2.*M_PI*(1+x)-cos((2.*M_PI)*x))/(4.*M_PI));
446 else return 1.;
447 } /* end of sin_cdf() */
448
449
450 /*---------------------------------------------------------------------------*/
451 /* */
452 /* / 0.05 + 0.45*(1 +sin(2 Pi x)) if |x| <= 5 */
453 /* f(x) = < */
454 /* \ 0 otherwise */
455 /* */
sin_10_pdf(double x,const UNUR_DISTR * distr ATTRIBUTE__UNUSED)456 double sin_10_pdf( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
457 {
458 if (fabs(x) > 5.)
459 return 0.;
460 else
461 return (0.05 + 0.45*(1.+sin(2.*M_PI*x)));
462 } /* end of sin_pdf() */
463
464 /* The CDF of our distribution: */
sin_10_cdf(double x,const UNUR_DISTR * distr ATTRIBUTE__UNUSED)465 double sin_10_cdf( double x, const UNUR_DISTR *distr ATTRIBUTE__UNUSED)
466 {
467 if (x < -5.)
468 return 0.;
469 else if(x<=5.)
470 return ((x/10.+0.5) + 0.09/(2*M_PI)*(cos(10*M_PI)-cos(2*M_PI*x)));
471 else return 1.;
472 } /* end of sin_cdf() */
473
474 /*---------------------------------------------------------------------------*/
475 /*---------------------------------------------------------------------------*/
476 /* [new] */
477
test_new(void)478 void test_new (void)
479 {
480 int n_tests_failed; /* number of failed tests */
481
482 /* start test */
483 printf("[new "); fflush(stdout);
484 fprintf(TESTLOG,"\n[new]\n");
485
486 /* reset counter */
487 n_tests_failed = 0;
488
489 /* set stop watch */
490 stopwatch_lap(&watch);
491
492 { /* invalid NULL ptr */
493 UNUR_DISTR *distr = NULL;
494 distr = NULL;
495
496
497 unur_reset_errno();
498 n_tests_failed += (check_expected_NULL(TESTLOG,109,(unur_pinv_new( distr )))==UNUR_SUCCESS)?0:1;
499 n_tests_failed += (check_errorcode(TESTLOG,109,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
500 unur_distr_free(distr);
501 }
502
503 { /* invalid distribution type */
504 UNUR_DISTR *distr = NULL;
505 distr = unur_distr_discr_new();
506
507
508 unur_reset_errno();
509 n_tests_failed += (check_expected_NULL(TESTLOG,115,(unur_pinv_new( distr )))==UNUR_SUCCESS)?0:1;
510 n_tests_failed += (check_errorcode(TESTLOG,115,UNUR_ERR_DISTR_INVALID)==UNUR_SUCCESS)?0:1;
511 unur_distr_free(distr);
512 }
513
514 { /* data missing in distribution object */
515 UNUR_DISTR *distr = NULL;
516 distr = unur_distr_cont_new();
517
518
519 unur_reset_errno();
520 /* pdf */
521 n_tests_failed += (check_expected_NULL(TESTLOG,122,(unur_pinv_new( distr )))==UNUR_SUCCESS)?0:1;
522 n_tests_failed += (check_errorcode(TESTLOG,122,UNUR_ERR_DISTR_REQUIRED)==UNUR_SUCCESS)?0:1;
523 unur_distr_free(distr);
524 }
525
526
527 /* timing */
528 stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
529
530 /* test finished */
531 test_ok &= (n_tests_failed) ? 0 : 1;
532 (n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
533
534 } /* end of test_new() */
535
536 /*---------------------------------------------------------------------------*/
537 /* [set] */
538
test_set(void)539 void test_set (void)
540 {
541 int n_tests_failed; /* number of failed tests */
542
543 /* start test */
544 printf("[set "); fflush(stdout);
545 fprintf(TESTLOG,"\n[set]\n");
546
547 /* reset counter */
548 n_tests_failed = 0;
549
550 /* set stop watch */
551 stopwatch_lap(&watch);
552
553 { /* invalid NULL ptr */
554 UNUR_PAR *par = NULL;
555 /* double stp[] = {1.,2.,3.}; */
556 par = NULL;
557
558
559 unur_reset_errno();
560 n_tests_failed += (check_expected_setfailed(TESTLOG,133,(unur_pinv_set_order( par, 3 )))==UNUR_SUCCESS)?0:1;
561 n_tests_failed += (check_errorcode(TESTLOG,133,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
562
563 unur_reset_errno();
564 n_tests_failed += (check_expected_setfailed(TESTLOG,136,(unur_pinv_set_smoothness( par, 1 )))==UNUR_SUCCESS)?0:1;
565 n_tests_failed += (check_errorcode(TESTLOG,136,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
566
567 unur_reset_errno();
568 n_tests_failed += (check_expected_setfailed(TESTLOG,139,(unur_pinv_set_u_resolution( par, 1.e-8 )))==UNUR_SUCCESS)?0:1;
569 n_tests_failed += (check_errorcode(TESTLOG,139,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
570
571 unur_reset_errno();
572 n_tests_failed += (check_expected_setfailed(TESTLOG,142,(unur_pinv_set_use_upoints( par, TRUE )))==UNUR_SUCCESS)?0:1;
573 n_tests_failed += (check_errorcode(TESTLOG,142,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
574
575 unur_reset_errno();
576 n_tests_failed += (check_expected_setfailed(TESTLOG,145,(unur_pinv_set_usepdf( par )))==UNUR_SUCCESS)?0:1;
577 n_tests_failed += (check_errorcode(TESTLOG,145,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
578
579 unur_reset_errno();
580 n_tests_failed += (check_expected_setfailed(TESTLOG,148,(unur_pinv_set_usecdf( par )))==UNUR_SUCCESS)?0:1;
581 n_tests_failed += (check_errorcode(TESTLOG,148,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
582
583 unur_reset_errno();
584 n_tests_failed += (check_expected_setfailed(TESTLOG,151,(unur_pinv_set_boundary(par,1.,3.)))==UNUR_SUCCESS)?0:1;
585 n_tests_failed += (check_errorcode(TESTLOG,151,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
586
587 unur_reset_errno();
588 n_tests_failed += (check_expected_setfailed(TESTLOG,154,(unur_pinv_set_searchboundary(par, TRUE, TRUE )))==UNUR_SUCCESS)?0:1;
589 n_tests_failed += (check_errorcode(TESTLOG,154,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
590
591 unur_reset_errno();
592 n_tests_failed += (check_expected_setfailed(TESTLOG,157,(unur_pinv_set_max_intervals(par,1000)))==UNUR_SUCCESS)?0:1;
593 n_tests_failed += (check_errorcode(TESTLOG,157,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
594
595 unur_reset_errno();
596 n_tests_failed += (check_expected_setfailed(TESTLOG,160,(unur_pinv_set_keepcdf(par,TRUE)))==UNUR_SUCCESS)?0:1;
597 n_tests_failed += (check_errorcode(TESTLOG,160,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
598 }
599
600 { /* invalid parameter object */
601 UNUR_DISTR *distr = NULL;
602 UNUR_PAR *par = NULL;
603 /* double stp[] = {1.,2.,3.}; */
604 distr = unur_distr_normal(NULL,0);
605 par = unur_arou_new(distr);
606
607
608 unur_reset_errno();
609 n_tests_failed += (check_expected_setfailed(TESTLOG,169,(unur_pinv_set_order( par, 3 )))==UNUR_SUCCESS)?0:1;
610 n_tests_failed += (check_errorcode(TESTLOG,169,UNUR_ERR_PAR_INVALID)==UNUR_SUCCESS)?0:1;
611
612 unur_reset_errno();
613 n_tests_failed += (check_expected_setfailed(TESTLOG,172,(unur_pinv_set_smoothness( par, 1 )))==UNUR_SUCCESS)?0:1;
614 n_tests_failed += (check_errorcode(TESTLOG,172,UNUR_ERR_PAR_INVALID)==UNUR_SUCCESS)?0:1;
615
616 unur_reset_errno();
617 n_tests_failed += (check_expected_setfailed(TESTLOG,175,(unur_pinv_set_u_resolution( par, 1.e-8 )))==UNUR_SUCCESS)?0:1;
618 n_tests_failed += (check_errorcode(TESTLOG,175,UNUR_ERR_PAR_INVALID)==UNUR_SUCCESS)?0:1;
619
620 unur_reset_errno();
621 n_tests_failed += (check_expected_setfailed(TESTLOG,178,(unur_pinv_set_use_upoints( par, TRUE )))==UNUR_SUCCESS)?0:1;
622 n_tests_failed += (check_errorcode(TESTLOG,178,UNUR_ERR_PAR_INVALID)==UNUR_SUCCESS)?0:1;
623
624 unur_reset_errno();
625 n_tests_failed += (check_expected_setfailed(TESTLOG,181,(unur_pinv_set_usepdf( par )))==UNUR_SUCCESS)?0:1;
626 n_tests_failed += (check_errorcode(TESTLOG,181,UNUR_ERR_PAR_INVALID)==UNUR_SUCCESS)?0:1;
627
628 unur_reset_errno();
629 n_tests_failed += (check_expected_setfailed(TESTLOG,184,(unur_pinv_set_usecdf( par )))==UNUR_SUCCESS)?0:1;
630 n_tests_failed += (check_errorcode(TESTLOG,184,UNUR_ERR_PAR_INVALID)==UNUR_SUCCESS)?0:1;
631
632 unur_reset_errno();
633 n_tests_failed += (check_expected_setfailed(TESTLOG,187,(unur_pinv_set_boundary(par,1.,3.)))==UNUR_SUCCESS)?0:1;
634 n_tests_failed += (check_errorcode(TESTLOG,187,UNUR_ERR_PAR_INVALID)==UNUR_SUCCESS)?0:1;
635
636 unur_reset_errno();
637 n_tests_failed += (check_expected_setfailed(TESTLOG,190,(unur_pinv_set_searchboundary(par, TRUE, TRUE )))==UNUR_SUCCESS)?0:1;
638 n_tests_failed += (check_errorcode(TESTLOG,190,UNUR_ERR_PAR_INVALID)==UNUR_SUCCESS)?0:1;
639
640 unur_reset_errno();
641 n_tests_failed += (check_expected_setfailed(TESTLOG,193,(unur_pinv_set_max_intervals(par,1000)))==UNUR_SUCCESS)?0:1;
642 n_tests_failed += (check_errorcode(TESTLOG,193,UNUR_ERR_PAR_INVALID)==UNUR_SUCCESS)?0:1;
643
644 unur_reset_errno();
645 n_tests_failed += (check_expected_setfailed(TESTLOG,196,(unur_pinv_set_keepcdf(par,TRUE)))==UNUR_SUCCESS)?0:1;
646 n_tests_failed += (check_errorcode(TESTLOG,196,UNUR_ERR_PAR_INVALID)==UNUR_SUCCESS)?0:1;
647 unur_par_free(par);
648 unur_distr_free(distr);
649 }
650
651 { /* invalid parameters */
652 UNUR_DISTR *distr = NULL;
653 UNUR_PAR *par = NULL;
654 distr = unur_distr_normal(NULL,0);
655 par = unur_pinv_new(distr);
656
657
658 unur_reset_errno();
659 n_tests_failed += (check_expected_setfailed(TESTLOG,206,(unur_pinv_set_order( par, 30 )))==UNUR_SUCCESS)?0:1;
660 n_tests_failed += (check_errorcode(TESTLOG,206,UNUR_ERR_PAR_SET)==UNUR_SUCCESS)?0:1;
661
662 unur_reset_errno();
663 n_tests_failed += (check_expected_setfailed(TESTLOG,209,(unur_pinv_set_order( par, 1 )))==UNUR_SUCCESS)?0:1;
664 n_tests_failed += (check_errorcode(TESTLOG,209,UNUR_ERR_PAR_SET)==UNUR_SUCCESS)?0:1;
665
666 unur_reset_errno();
667 n_tests_failed += (check_expected_setfailed(TESTLOG,212,(unur_pinv_set_smoothness( par, 4 )))==UNUR_SUCCESS)?0:1;
668 n_tests_failed += (check_errorcode(TESTLOG,212,UNUR_ERR_PAR_SET)==UNUR_SUCCESS)?0:1;
669
670 unur_reset_errno();
671 n_tests_failed += (check_expected_setfailed(TESTLOG,215,(unur_pinv_set_boundary(par,1.,-3.)))==UNUR_SUCCESS)?0:1;
672 n_tests_failed += (check_errorcode(TESTLOG,215,UNUR_ERR_PAR_SET)==UNUR_SUCCESS)?0:1;
673
674 unur_reset_errno();
675 n_tests_failed += (check_expected_setfailed(TESTLOG,218,(unur_pinv_set_boundary(par,1.,UNUR_INFINITY)))==UNUR_SUCCESS)?0:1;
676 n_tests_failed += (check_errorcode(TESTLOG,218,UNUR_ERR_PAR_SET)==UNUR_SUCCESS)?0:1;
677
678 unur_reset_errno();
679 n_tests_failed += (check_expected_setfailed(TESTLOG,221,(unur_pinv_set_max_intervals(par,1)))==UNUR_SUCCESS)?0:1;
680 n_tests_failed += (check_errorcode(TESTLOG,221,UNUR_ERR_PAR_SET)==UNUR_SUCCESS)?0:1;
681
682 unur_reset_errno();
683 n_tests_failed += (check_expected_setfailed(TESTLOG,224,(unur_pinv_set_max_intervals(par,10000000)))==UNUR_SUCCESS)?0:1;
684 n_tests_failed += (check_errorcode(TESTLOG,224,UNUR_ERR_PAR_SET)==UNUR_SUCCESS)?0:1;
685 unur_par_free(par);
686 unur_distr_free(distr);
687 }
688
689 { /* invalid parameters */
690 UNUR_DISTR *distr = NULL;
691 UNUR_PAR *par;
692 UNUR_GEN *gen;
693 distr = unur_distr_normal(NULL,0);
694
695
696 unur_reset_errno();
697 par = unur_pinv_new(distr);
698 unur_pinv_set_order( par, 4 );
699 unur_pinv_set_smoothness( par, 1 );
700 gen = unur_init(par);
701 n_tests_failed += (check_errorcode(TESTLOG,238,UNUR_ERR_GENERIC)==UNUR_SUCCESS)?0:1;
702
703 unur_reset_errno();
704 unur_free(gen);
705 par = unur_pinv_new(distr);
706 unur_pinv_set_order( par, 4 );
707 unur_pinv_set_smoothness( par, 2 );
708 gen = unur_init(par);
709 n_tests_failed += (check_errorcode(TESTLOG,245,UNUR_ERR_GENERIC)==UNUR_SUCCESS)?0:1;
710
711 unur_reset_errno();
712 unur_free(gen);
713 par = unur_pinv_new(distr);
714 unur_pinv_set_order( par, 6 );
715 unur_pinv_set_smoothness( par, 2 );
716 gen = unur_init(par);
717 n_tests_failed += (check_errorcode(TESTLOG,252,UNUR_ERR_GENERIC)==UNUR_SUCCESS)?0:1;
718 unur_free(gen);
719 unur_distr_free(distr);
720 }
721
722 { /* missing CDF */
723 UNUR_DISTR *distr = NULL;
724 UNUR_PAR *par = NULL;
725 distr = unur_distr_cont_new();
726 unur_distr_cont_set_pdf(distr, neg_exponential_pdf);
727 par = unur_pinv_new(distr);
728
729
730 unur_reset_errno();
731 n_tests_failed += (check_expected_setfailed(TESTLOG,263,(unur_pinv_set_usecdf( par )))==UNUR_SUCCESS)?0:1;
732 n_tests_failed += (check_errorcode(TESTLOG,263,UNUR_ERR_PAR_SET)==UNUR_SUCCESS)?0:1;
733 unur_par_free(par);
734 unur_distr_free(distr);
735 }
736
737 { /* missing PDF */
738 UNUR_DISTR *distr = NULL;
739 UNUR_PAR *par = NULL;
740 distr = unur_distr_cont_new();
741 unur_distr_cont_set_cdf(distr, neg_exponential_cdf);
742 par = unur_pinv_new(distr);
743
744
745 unur_reset_errno();
746 n_tests_failed += (check_expected_setfailed(TESTLOG,274,(unur_pinv_set_usepdf( par )))==UNUR_SUCCESS)?0:1;
747 n_tests_failed += (check_errorcode(TESTLOG,274,UNUR_ERR_PAR_SET)==UNUR_SUCCESS)?0:1;
748 unur_par_free(par);
749 unur_distr_free(distr);
750 }
751
752 { /* missing PDF */
753 UNUR_DISTR *distr = NULL;
754 UNUR_PAR *par;
755 UNUR_GEN *gen;
756 distr = unur_distr_cont_new();
757 unur_distr_cont_set_cdf(distr, neg_exponential_cdf);
758
759
760 unur_reset_errno();
761 par = unur_pinv_new(distr);
762 unur_pinv_set_usecdf( par );
763 unur_pinv_set_smoothness( par, 1 );
764 gen = unur_init(par);
765 n_tests_failed += (check_errorcode(TESTLOG,289,UNUR_ERR_DISTR_REQUIRED)==UNUR_SUCCESS)?0:1;
766
767 unur_reset_errno();
768 unur_free(gen);
769 par = unur_pinv_new(distr);
770 unur_pinv_set_usecdf( par );
771 unur_pinv_set_smoothness( par, 2 );
772 gen = unur_init(par);
773 n_tests_failed += (check_errorcode(TESTLOG,296,UNUR_ERR_DISTR_REQUIRED)==UNUR_SUCCESS)?0:1;
774
775 unur_reset_errno();
776 unur_free(gen);
777 unur_distr_cont_set_pdf(distr, neg_exponential_pdf);
778 par = unur_pinv_new(distr);
779 unur_pinv_set_usecdf( par );
780 unur_pinv_set_smoothness( par, 2 );
781 gen = unur_init(par);
782 n_tests_failed += (check_errorcode(TESTLOG,304,UNUR_ERR_DISTR_REQUIRED)==UNUR_SUCCESS)?0:1;
783 unur_free(gen);
784 unur_distr_free(distr);
785 }
786
787
788 /* timing */
789 stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
790
791 /* test finished */
792 test_ok &= (n_tests_failed) ? 0 : 1;
793 (n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
794
795 } /* end of test_set() */
796
797 /*---------------------------------------------------------------------------*/
798 /* [get] */
799
test_get(void)800 void test_get (void)
801 {
802 int n_tests_failed; /* number of failed tests */
803
804 /* start test */
805 printf("[get "); fflush(stdout);
806 fprintf(TESTLOG,"\n[get]\n");
807
808 /* reset counter */
809 n_tests_failed = 0;
810
811 /* set stop watch */
812 stopwatch_lap(&watch);
813
814 { /* invalid generator object */
815 UNUR_DISTR *distr = NULL;
816 UNUR_PAR *par = NULL;
817 UNUR_GEN *gen = NULL;
818 distr = unur_distr_normal(NULL,0);
819 par = unur_srou_new(distr);
820 gen = unur_init(par);
821 abort_if_NULL(TESTLOG, 315, gen );
822
823
824 unur_reset_errno();
825 n_tests_failed += (check_expected_zero(TESTLOG,319,(unur_pinv_get_n_intervals(gen)))==UNUR_SUCCESS)?0:1;
826 n_tests_failed += (check_errorcode(TESTLOG,319,UNUR_ERR_GEN_INVALID)==UNUR_SUCCESS)?0:1;
827 unur_distr_free(distr);
828 unur_free(gen);
829 }
830
831
832 /* timing */
833 stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
834
835 /* test finished */
836 test_ok &= (n_tests_failed) ? 0 : 1;
837 (n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
838
839 } /* end of test_get() */
840
841 /*---------------------------------------------------------------------------*/
842 /* [sample] */
843
test_sample(void)844 void test_sample (void)
845 {
846 int n_tests_failed; /* number of failed tests */
847
848 /* start test */
849 printf("[sample "); fflush(stdout);
850 fprintf(TESTLOG,"\n[sample]\n");
851
852 /* reset counter */
853 n_tests_failed = 0;
854
855 /* set stop watch */
856 stopwatch_lap(&watch);
857
858 { /* invalid NULL ptr */
859 UNUR_GEN *gen = NULL;
860 gen = NULL;
861
862
863 unur_reset_errno();
864 n_tests_failed += (check_expected_INFINITY(TESTLOG,350,(unur_pinv_eval_approxinvcdf(gen,0.5)))==UNUR_SUCCESS)?0:1;
865 n_tests_failed += (check_errorcode(TESTLOG,350,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
866 unur_free(gen);
867 }
868
869 { /* invalid generator object */
870 UNUR_DISTR *distr = NULL;
871 UNUR_PAR *par = NULL;
872 UNUR_GEN *gen = NULL;
873 distr = unur_distr_normal(NULL,0);
874 par = unur_srou_new(distr);
875 gen = unur_init(par);
876 abort_if_NULL(TESTLOG, 356, gen );
877
878
879 unur_reset_errno();
880 n_tests_failed += (check_expected_INFINITY(TESTLOG,360,(unur_pinv_eval_approxinvcdf(gen,0.5)))==UNUR_SUCCESS)?0:1;
881 n_tests_failed += (check_errorcode(TESTLOG,360,UNUR_ERR_GEN_INVALID)==UNUR_SUCCESS)?0:1;
882 unur_distr_free(distr);
883 unur_free(gen);
884 }
885
886 { /* invalid domain */
887 UNUR_DISTR *distr = NULL;
888 UNUR_PAR *par = NULL;
889 UNUR_GEN *gen = NULL;
890 distr = unur_distr_normal(NULL,0);
891 par = unur_pinv_new(distr);
892 unur_set_debug(par,0);
893 gen = unur_init( par );
894 abort_if_NULL(TESTLOG, 366, gen );
895
896
897 unur_reset_errno();
898 n_tests_failed += (check_expected_INFINITY(TESTLOG,370,(unur_pinv_eval_approxinvcdf(gen,1.5)))==UNUR_SUCCESS)?0:1;
899 n_tests_failed += (check_errorcode(TESTLOG,370,UNUR_ERR_DOMAIN)==UNUR_SUCCESS)?0:1;
900
901 unur_reset_errno();
902 n_tests_failed += (check_expected_negINFINITY(TESTLOG,373,(unur_pinv_eval_approxinvcdf(gen,-0.5)))==UNUR_SUCCESS)?0:1;
903 n_tests_failed += (check_errorcode(TESTLOG,373,UNUR_ERR_DOMAIN)==UNUR_SUCCESS)?0:1;
904 unur_distr_free(distr);
905 unur_free(gen);
906 }
907
908 { /* cdf table removed */
909 UNUR_DISTR *distr = NULL;
910 UNUR_PAR *par = NULL;
911 UNUR_GEN *gen = NULL;
912 distr = unur_distr_normal(NULL,0);
913 par = unur_pinv_new(distr);
914 unur_set_debug(par,0);
915 gen = unur_init( par );
916 abort_if_NULL(TESTLOG, 380, gen );
917
918
919 unur_reset_errno();
920 n_tests_failed += (check_expected_INFINITY(TESTLOG,384,(unur_pinv_eval_approxcdf(gen,1.5)))==UNUR_SUCCESS)?0:1;
921 n_tests_failed += (check_errorcode(TESTLOG,384,UNUR_ERR_GENERIC)==UNUR_SUCCESS)?0:1;
922 unur_distr_free(distr);
923 unur_free(gen);
924 }
925
926 { /* check approximate cdf */
927 UNUR_GEN *gen = NULL;
928 int i, cdffailed=0;
929 double x,u,d;
930 gen = unur_str2gen("cont;logpdf='5-x';domain=(0,infinity)&method=pinv;keepcdf=on;debug=0");
931
932
933 unur_reset_errno();
934 for (i=1; i<1000; i++) {
935 x = 5.*i/1000.;
936 u = unur_pinv_eval_approxcdf(gen,x);
937 d = fabs(u - (1-exp(-x)));
938 if (d > 1.e-11) { cdffailed = 1; }}
939 n_tests_failed += (check_expected_zero(TESTLOG,399,(cdffailed))==UNUR_SUCCESS)?0:1;
940 n_tests_failed += (check_errorcode(TESTLOG,399,UNUR_SUCCESS)==UNUR_SUCCESS)?0:1;
941 unur_free(gen);
942 }
943
944 { /* compare clone */
945 UNUR_DISTR *distr = NULL;
946 UNUR_PAR *par = NULL;
947 UNUR_GEN *gen = NULL;
948 UNUR_GEN *clone;
949 distr = unur_distr_normal(NULL,0);
950 par = NULL;
951 gen = NULL;
952
953
954 unur_reset_errno();
955 /* original generator object */
956 par = unur_pinv_new(distr);
957 gen = unur_init(par);
958 n_tests_failed += (compare_sequence_gen_start(TESTLOG,412,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
959
960 unur_reset_errno();
961 /* clone */
962 clone = unur_gen_clone(gen);
963 unur_free(gen);
964 gen = clone;
965 n_tests_failed += (compare_sequence_gen(TESTLOG,418,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
966 unur_distr_free(distr);
967 unur_free(gen);
968 }
969
970 { /* compare stringparser */
971 UNUR_DISTR *distr = NULL;
972 UNUR_PAR *par = NULL;
973 UNUR_GEN *gen = NULL;
974 double fpar[] = {3.,4.};
975 distr = NULL;
976 par = NULL;
977 gen = NULL;
978
979
980 unur_reset_errno();
981 distr = unur_distr_gamma(fpar,2);
982 unur_distr_cont_set_domain(distr,2.,UNUR_INFINITY);
983 par = unur_pinv_new(distr);
984 set_debug_flag(par);
985 gen = unur_init(par);
986 n_tests_failed += (compare_sequence_gen_start(TESTLOG,450,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
987
988 unur_reset_errno();
989 unur_free(gen); gen = NULL;
990 unur_distr_free(distr); distr = NULL;
991 gen = unur_str2gen( "gamma(3.,4.); domain = (2,infinity) & \
992 method = pinv; debug = 0x1" );
993 n_tests_failed += (compare_sequence_gen(TESTLOG,456,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
994
995 unur_reset_errno();
996 unur_free(gen); gen = NULL;
997 distr = unur_distr_normal(NULL,0);
998 unur_distr_cont_set_domain(distr,2.,UNUR_INFINITY);
999 par = unur_pinv_new(distr);
1000 unur_pinv_set_order(par,10);
1001 unur_pinv_set_u_resolution(par,1.e-6);
1002 unur_pinv_set_boundary(par,1.,1000.);
1003 unur_pinv_set_max_intervals(par,1000);
1004 set_debug_flag(par);
1005 gen = unur_init(par);
1006 n_tests_failed += (compare_sequence_gen_start(TESTLOG,469,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
1007
1008 unur_reset_errno();
1009 unur_free(gen); gen = NULL;
1010 unur_distr_free(distr); distr = NULL;
1011 gen = unur_str2gen( "normal; domain = (2,inf) & \
1012 method = pinv; order = 10; u_resolution = 1.e-6; \
1013 boundary = (1,1000); max_intervals = 1000; debug = 0x1" );
1014 n_tests_failed += (compare_sequence_gen(TESTLOG,476,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
1015 unur_distr_free(distr);
1016 unur_free(gen);
1017 }
1018
1019
1020 /* timing */
1021 stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
1022
1023 /* test finished */
1024 test_ok &= (n_tests_failed) ? 0 : 1;
1025 (n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
1026
1027 } /* end of test_sample() */
1028
1029 /*---------------------------------------------------------------------------*/
1030 /* [validate] */
1031
1032 /*---------------------------------------------------------------------------*/
1033
1034 /* [validate] */
1035
test_validate(void)1036 void test_validate (void)
1037 {
1038 UNUR_DISTR *distr[4];
1039 UNUR_PAR *par;
1040 UNUR_GEN *gen;
1041 int n_tests_failed;
1042 int rcode;
1043 double *darray;
1044 double fpm[10];
1045
1046 rcode = 0;
1047
1048 /* start test */
1049 printf("[validate "); fflush(stdout);
1050 fprintf(TESTLOG,"\n[validate]\n");
1051
1052 /* reset counter */
1053 n_tests_failed = 0;
1054
1055 /* set stop watch */
1056 stopwatch_lap(&watch);
1057
1058
1059 /* distributions: 4 */
1060 {
1061 distr[0] = unur_distr_normal(NULL,0);
1062 }
1063
1064 {
1065 distr[1] = unur_distr_multPDF( distr[0], 100. );
1066 }
1067
1068 {
1069 distr[2] = unur_str2distr( "cont; pdf='x/(1+x*x*x*x)'; center=1" );
1070 }
1071
1072 {
1073 distr[3] = unur_str2distr( "cont; pdf='-x/(1+x*x*x*x)'; center=-1" );
1074 }
1075
1076 /* timing */
1077 stopwatch_print(TESTLOG,"\n<*>setup time = %.3f ms\n", stopwatch_lap(&watch));
1078
1079 printf("\n(chi^2) "); fflush(stdout);
1080
1081 /* chi^2 tests: 4 */
1082
1083 unur_set_default_debug(~UNUR_DEBUG_SAMPLE);
1084 fprintf( TESTLOG,"\nChi^2 Test:\n");
1085
1086 /* distribution [0] */
1087
1088 if(TRUE) {
1089 unur_reset_errno();
1090 do {
1091 UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[0]);
1092 par = unur_pinv_new(distr_localcopy);
1093 gen = unur_init(par);
1094 rcode = run_validate_chi2(TESTLOG,0,gen,distr[0],'+');
1095 n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
1096 n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
1097 unur_free(gen);
1098 unur_distr_free(distr_localcopy);
1099 } while (0);
1100 }
1101
1102 /* distribution [1] */
1103
1104 if(TRUE) {
1105 unur_reset_errno();
1106 do {
1107 UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[1]);
1108 par = unur_pinv_new(distr_localcopy);
1109 gen = unur_init(par);
1110 rcode = run_validate_chi2(TESTLOG,0,gen,distr[1],'+');
1111 n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
1112 n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
1113 unur_free(gen);
1114 unur_distr_free(distr_localcopy);
1115 } while (0);
1116 }
1117
1118 /* distribution [2] */
1119
1120 if(TRUE) {
1121 unur_reset_errno();
1122 do {
1123 UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[2]);
1124 par = unur_pinv_new(distr_localcopy);
1125 gen = unur_init(par);
1126 rcode = run_validate_chi2(TESTLOG,0,gen,distr[2],'0');
1127 n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
1128 n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
1129 unur_free(gen);
1130 unur_distr_free(distr_localcopy);
1131 } while (0);
1132 }
1133
1134 /* distribution [3] */
1135
1136 if(TRUE) {
1137 unur_reset_errno();
1138 do {
1139 UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[3]);
1140 par = unur_pinv_new(distr_localcopy);
1141 gen = unur_init(par);
1142 rcode = run_validate_chi2(TESTLOG,0,gen,distr[3],'0');
1143 n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
1144 n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
1145 unur_free(gen);
1146 unur_distr_free(distr_localcopy);
1147 } while (0);
1148 }
1149
1150 /* timing */
1151 stopwatch_print(TESTLOG,"\n<*>time = %.0f ms\n", stopwatch_lap(&watch));
1152
1153
1154 /* free distributions */
1155 unur_distr_free(distr[0]);
1156 unur_distr_free(distr[1]);
1157 unur_distr_free(distr[2]);
1158 unur_distr_free(distr[3]);
1159
1160 /* test finished */
1161 test_ok &= (n_tests_failed>CHI2_FAILURES_TOLERATED) ? 0 : 1;
1162 /* we accept CHI2_FAILURES_TOLERATED failures */
1163 (n_tests_failed>CHI2_FAILURES_TOLERATED) ? printf(" ==> failed] ") : printf(" ==> ok] ");
1164
1165 /* prevent compiler from making useless annoying warnings */
1166 distr[0] = NULL;
1167 par = NULL;
1168 gen = NULL;
1169 darray = NULL;
1170 fpm[0] = 0.;
1171
1172 } /* end of test_validate */
1173
1174 /*---------------------------------------------------------------------------*/
1175 /* [special] */
1176
test_special(void)1177 void test_special (void)
1178 {
1179 /* set boolean to FALSE */
1180 int FAILED = 0;
1181
1182
1183
1184
1185
1186 int samplesize = UERROR_SAMPLESIZE;
1187 int errorsum = 0;
1188 double fpar[4];
1189
1190 UNUR_DISTR *distr, *qdistr;
1191 UNUR_PAR *par;
1192
1193 int global_UERROR_CDF = UERROR_CDF;
1194
1195
1196 /* start test */
1197 printf("[special "); fflush(stdout);
1198 fprintf(TESTLOG,"\n[special]\n");
1199
1200 /* set stop watch */
1201 stopwatch_lap(&watch);
1202
1203
1204
1205 /* set u-error tests */
1206 set_uerror_tests();
1207
1208 /* test for maximal u-error */
1209 printf("\n[test maximal u-error]");
1210 fprintf(TESTLOG,"\n* Test maximal u-error *\n");
1211
1212 if (UERROR_STANDARDDIST) { /* --------------------------- */
1213
1214 printf("\nStandard distributions:\n");
1215 fprintf(TESTLOG,"\n--- Standard distributions --- \n\n");
1216
1217
1218 if (ALL) {
1219 printf(" normal");
1220 distr = unur_distr_normal(NULL,0);
1221 par = unur_pinv_new(distr);
1222 errorsum += pinv_error_experiment(par,samplesize);
1223 unur_distr_free(distr);
1224 fprintf(TESTLOG,"\n");
1225 }
1226
1227
1228 if (ALL) {
1229 printf(" cauchy");
1230 distr = unur_distr_cauchy(NULL,0);
1231 par = unur_pinv_new(distr);
1232 errorsum += pinv_error_experiment(par,samplesize);
1233 unur_distr_free(distr);
1234 fprintf(TESTLOG,"\n");
1235 }
1236
1237
1238 if (ALL) {
1239 printf(" exponential");
1240 distr = unur_distr_exponential(NULL,0);
1241 par = unur_pinv_new(distr);
1242 errorsum += pinv_error_experiment(par,samplesize);
1243 unur_distr_free(distr);
1244 fprintf(TESTLOG,"\n");
1245 }
1246
1247
1248 if (ALL) {
1249 printf(" gamma(0.9)");
1250 fpar[0] = 0.9;
1251 distr = unur_distr_gamma(fpar,1);
1252 unur_distr_cont_set_center(distr,1.);
1253 par = unur_pinv_new(distr);
1254 errorsum += pinv_error_experiment(par,samplesize);
1255 unur_distr_free(distr);
1256 fprintf(TESTLOG,"\n");
1257 }
1258
1259
1260 if (ALL) {
1261 printf(" gamma(1.02)");
1262 fpar[0] = 1.02;
1263 distr = unur_distr_gamma(fpar,1);
1264 unur_distr_cont_set_center(distr,1.);
1265 par = unur_pinv_new(distr);
1266 errorsum += pinv_error_experiment(par,samplesize);
1267 unur_distr_free(distr);
1268 fprintf(TESTLOG,"\n");
1269 }
1270
1271
1272 if (ALL) {
1273 printf(" gamma(1.5)");
1274 fpar[0] = 1.5;
1275 distr = unur_distr_gamma(fpar,1);
1276 unur_distr_cont_set_center(distr,1.);
1277 par = unur_pinv_new(distr);
1278 errorsum += pinv_error_experiment(par,samplesize);
1279 unur_distr_free(distr);
1280 fprintf(TESTLOG,"\n");
1281 }
1282
1283
1284 if (ALL) {
1285 printf(" gamma(2)");
1286 fpar[0] = 2.;
1287 distr = unur_distr_gamma(fpar,1);
1288 unur_distr_cont_set_center(distr,1.);
1289 par = unur_pinv_new(distr);
1290 unur_pinv_set_boundary(par,0., 1.e100);
1291 errorsum += pinv_error_experiment(par,samplesize);
1292 unur_distr_free(distr);
1293 fprintf(TESTLOG,"\n");
1294 }
1295
1296
1297 if (ALL) {
1298 printf(" gamma(5)");
1299 fpar[0] = 5.;
1300 distr = unur_distr_gamma(fpar,1);
1301 unur_distr_cont_set_center(distr,1.);
1302 par = unur_pinv_new(distr);
1303 unur_pinv_set_boundary(par,0., 1.e100);
1304 errorsum += pinv_error_experiment(par,samplesize);
1305 unur_distr_free(distr);
1306 fprintf(TESTLOG,"\n");
1307 }
1308
1309
1310 if (ALL) {
1311 printf(" beta(2,3)");
1312 fpar[0] = 2;
1313 fpar[1] = 3;
1314 distr = unur_distr_beta(fpar,2);
1315 par = unur_pinv_new(distr);
1316 errorsum += pinv_error_experiment(par,samplesize);
1317 unur_distr_free(distr);
1318 fprintf(TESTLOG,"\n");
1319 }
1320
1321
1322 if (ALL) {
1323 printf(" Gumbel");
1324 distr = unur_distr_extremeI(NULL,0);
1325 par = unur_pinv_new(distr);
1326 errorsum += pinv_error_experiment(par,samplesize);
1327 unur_distr_free(distr);
1328 fprintf(TESTLOG,"\n");
1329 }
1330
1331
1332 if (ALL) {
1333 printf(" shifted normal");
1334 fpar[0] = -1.e3;
1335 fpar[1] = 1.;
1336 distr = unur_distr_normal(fpar,2);
1337 par = unur_pinv_new(distr);
1338 errorsum += pinv_error_experiment(par,samplesize);
1339 unur_distr_free(distr);
1340 fprintf(TESTLOG,"\n");
1341
1342 printf(" shifted normal");
1343 fpar[0] = 1.e3;
1344 fpar[1] = 1.;
1345 distr = unur_distr_normal(fpar,2);
1346 par = unur_pinv_new(distr);
1347 errorsum += pinv_error_experiment(par,samplesize);
1348 unur_distr_free(distr);
1349 fprintf(TESTLOG,"\n");
1350 }
1351
1352
1353 if (0) {
1354 printf(" lognormal(2,0.5)");
1355 fpar[0] = 2.;
1356 fpar[1] = 0.5;
1357 distr = unur_distr_lognormal(fpar,2);
1358 par = unur_pinv_new(distr);
1359 errorsum += pinv_error_experiment(par,samplesize);
1360 unur_distr_free(distr);
1361 fprintf(TESTLOG,"\n");
1362
1363 printf(" lognormal(2.0.5,4.)");
1364 fpar[0] = 2.;
1365 fpar[1] = 0.5;
1366 fpar[2] = 4.;
1367 distr = unur_distr_lognormal(fpar,3);
1368 par = unur_pinv_new(distr);
1369 errorsum += pinv_error_experiment(par,samplesize);
1370 unur_distr_free(distr);
1371 fprintf(TESTLOG,"\n");
1372 }
1373
1374 } /* endif (UERROR_STANDARDDIST) */
1375 if (UERROR_QUASIPDF) { /* --------------------------- */
1376
1377 printf("\nDistributions with quasi-densities:\n");
1378 fprintf(TESTLOG,"\n--- Distributions with quasi-densities --- \n\n");
1379
1380 if (ALL) {
1381 distr = unur_distr_normal(NULL,0);
1382
1383 printf(" (normal*1e10)");
1384 qdistr = unur_distr_multPDF( distr, 1.e10 );
1385 par = unur_pinv_new(qdistr);
1386 errorsum += pinv_error_experiment(par,samplesize);
1387 unur_distr_free(qdistr);
1388 fprintf(TESTLOG,"\n");
1389
1390 printf(" (normal*1e-10)");
1391 qdistr = unur_distr_multPDF( distr, 1.e-10 );
1392 par = unur_pinv_new(qdistr);
1393 errorsum += pinv_error_experiment(par,samplesize);
1394 unur_distr_free(qdistr);
1395 fprintf(TESTLOG,"\n");
1396
1397 unur_distr_free(distr);
1398 }
1399
1400 } /* endif (UERROR_QUASIPDF) */
1401 if (UERROR_VANISHINGPDF) { /* --------------------------- */
1402
1403 printf("\nDistributions with vanishing PDF:\n");
1404 fprintf(TESTLOG,"\n--- Distributions with vanishing PDF --- \n\n");
1405
1406
1407 if (ALL) {
1408 printf(" (exponential_on_(-oo,oo))");
1409 distr = unur_distr_exponential(NULL,0);
1410 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1411 unur_distr_set_name(distr,"exponential_(-oo,oo)");
1412 par = unur_pinv_new(distr);
1413 errorsum += pinv_error_experiment(par,samplesize);
1414 unur_distr_free(distr);
1415 fprintf(TESTLOG,"\n");
1416 }
1417
1418 if (ALL) {
1419 printf(" (exponential(1,1)_on_(-oo,oo))");
1420 fpar[0] = 1.;
1421 fpar[1] = 1.;
1422 distr = unur_distr_exponential(fpar,2);
1423 unur_distr_cont_set_center(distr,2.);
1424 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1425 unur_distr_set_name(distr,"exponential(1,1)_(-oo,oo)");
1426 par = unur_pinv_new(distr);
1427 errorsum += pinv_error_experiment(par,samplesize);
1428 unur_distr_free(distr);
1429 fprintf(TESTLOG,"\n");
1430 }
1431
1432 if (ALL) {
1433 printf(" (exponential(1,1)_on_(-oo,oo))");
1434 fpar[0] = 1.;
1435 fpar[1] = 1.;
1436 distr = unur_distr_exponential(fpar,2);
1437 unur_distr_cont_set_center(distr,2.);
1438 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1439 unur_distr_cont_set_center(distr,2.);
1440 unur_distr_set_name(distr,"exponential(1,1)_(-oo,oo)");
1441 par = unur_pinv_new(distr);
1442 errorsum += pinv_error_experiment(par,samplesize);
1443 unur_distr_free(distr);
1444 fprintf(TESTLOG,"\n");
1445 }
1446
1447 if (ALL) {
1448 printf(" (exponential(1,-1)_on_(-oo,oo))");
1449 fpar[0] = 1.;
1450 fpar[1] = -1.;
1451 distr = unur_distr_exponential(fpar,2);
1452 unur_distr_cont_set_center(distr,2.);
1453 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1454 unur_distr_set_name(distr,"exponential(1,-1)_(-oo,oo)");
1455 par = unur_pinv_new(distr);
1456 errorsum += pinv_error_experiment(par,samplesize);
1457 unur_distr_free(distr);
1458 fprintf(TESTLOG,"\n");
1459 }
1460
1461 if (ALL) {
1462 printf(" (exponential(0.1,0.1)_on_(-oo,oo))");
1463 fpar[0] = 0.1;
1464 fpar[1] = 0.1;
1465 distr = unur_distr_exponential(fpar,2);
1466 unur_distr_cont_set_center(distr,2.);
1467 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1468 unur_distr_set_name(distr,"exponential(0.1,0.1)_(-oo,oo)");
1469 par = unur_pinv_new(distr);
1470 errorsum += pinv_error_experiment(par,samplesize);
1471 unur_distr_free(distr);
1472 fprintf(TESTLOG,"\n");
1473 }
1474
1475 if (ALL) {
1476 printf(" (exponential(1000,1000)_on_(-oo,oo))");
1477 fpar[0] = 1000;
1478 fpar[1] = 1000;
1479 distr = unur_distr_exponential(fpar,2);
1480 unur_distr_cont_set_center(distr,2.);
1481 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1482 unur_distr_set_name(distr,"exponential(1000,1000)_(-oo,oo)");
1483 par = unur_pinv_new(distr);
1484 errorsum += pinv_error_experiment(par,samplesize);
1485 unur_distr_free(distr);
1486 fprintf(TESTLOG,"\n");
1487 }
1488
1489
1490 if (ALL) {
1491 printf(" neg_exponential");
1492 distr = unur_distr_cont_new();
1493 unur_distr_set_name(distr,"neg_exponential");
1494 unur_distr_cont_set_cdf( distr, neg_exponential_cdf );
1495 unur_distr_cont_set_pdf( distr, neg_exponential_pdf );
1496 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1497 par = unur_pinv_new(distr);
1498 errorsum += pinv_error_experiment(par,samplesize);
1499 unur_distr_free(distr);
1500 fprintf(TESTLOG,"\n");
1501 }
1502
1503 if (ALL) {
1504 printf(" neg_exponential_1");
1505 distr = unur_distr_cont_new();
1506 unur_distr_set_name(distr,"neg_exponential_1");
1507 unur_distr_cont_set_cdf( distr, neg_exponential_1_cdf );
1508 unur_distr_cont_set_pdf( distr, neg_exponential_1_pdf );
1509 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1510 unur_distr_cont_set_center(distr,-2.);
1511 par = unur_pinv_new(distr);
1512 errorsum += pinv_error_experiment(par,samplesize);
1513 unur_distr_free(distr);
1514 fprintf(TESTLOG,"\n");
1515 }
1516
1517
1518 if (ALL) {
1519 printf(" gamma(2)");
1520 fpar[0] = 2.;
1521 distr = unur_distr_gamma(fpar,1);
1522 unur_distr_cont_set_center(distr,1.);
1523 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1524 par = unur_pinv_new(distr);
1525 unur_pinv_set_boundary(par,0., 1.e100);
1526 errorsum += pinv_error_experiment(par,samplesize);
1527 unur_distr_free(distr);
1528 fprintf(TESTLOG,"\n");
1529 }
1530
1531
1532 if (ALL) {
1533 printf(" gamma(5)");
1534 fpar[0] = 5.;
1535 distr = unur_distr_gamma(fpar,1);
1536 unur_distr_cont_set_center(distr,1.);
1537 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1538 par = unur_pinv_new(distr);
1539 unur_pinv_set_boundary(par,0., 1.e100);
1540 errorsum += pinv_error_experiment(par,samplesize);
1541 unur_distr_free(distr);
1542 fprintf(TESTLOG,"\n");
1543 }
1544
1545
1546 if (ALL) {
1547 printf(" gamma(1.02)");
1548 fpar[0] = 1.02;
1549 distr = unur_distr_gamma(fpar,1);
1550 unur_distr_cont_set_center(distr,1.);
1551 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1552 par = unur_pinv_new(distr);
1553 errorsum += pinv_error_experiment(par,samplesize);
1554 unur_distr_free(distr);
1555 fprintf(TESTLOG,"\n");
1556 }
1557
1558 } /* endif (UERROR_VANISHINGPDF) */
1559 if (UERROR_TRUNCATED) { /* --------------------------- */
1560
1561 printf("\nTruncated Distributions:\n");
1562 fprintf(TESTLOG,"\n--- Truncated Distributions --- \n\n");
1563
1564
1565 if (ALL) {
1566 printf(" truncated normal[3,inf]");
1567 distr = unur_distr_normal(NULL,0);
1568 unur_distr_cont_set_domain(distr,3.,UNUR_INFINITY);
1569 par = unur_pinv_new(distr);
1570 errorsum += pinv_error_experiment(par,samplesize);
1571 unur_distr_free(distr);
1572 fprintf(TESTLOG,"\n");
1573 }
1574
1575 if (ALL && DEVEL) {
1576 printf(" truncated normal[15,inf]");
1577 distr = unur_distr_normal(NULL,0);
1578 unur_distr_cont_set_domain(distr,15.,UNUR_INFINITY);
1579 par = unur_pinv_new(distr);
1580 /* using CDF does not work here. */
1581 /* ugly hack. */
1582 global_UERROR_CDF = UERROR_CDF;
1583 UERROR_CDF = FALSE;
1584 errorsum += pinv_error_experiment(par,samplesize);
1585 UERROR_CDF = global_UERROR_CDF;
1586 unur_distr_free(distr);
1587 fprintf(TESTLOG,"\n");
1588 }
1589
1590 } /* endif (UERROR_TRUNCATED) */
1591 if (UERROR_UNBOUNDEDPDF) { /* --------------------------- */
1592
1593 printf("\nDistributions with unbounded PDF:\n");
1594 fprintf(TESTLOG,"\n--- Distributions with unbounded PDF --- \n\n");
1595
1596
1597 if (ALL) {
1598 printf(" gamma(0.5)");
1599 fpar[0] = 0.5;
1600 distr = unur_distr_gamma(fpar,1);
1601 unur_distr_cont_set_center(distr,1.);
1602 par = unur_pinv_new(distr);
1603 errorsum += pinv_error_experiment(par,samplesize);
1604 unur_distr_free(distr);
1605 fprintf(TESTLOG,"\n");
1606 }
1607
1608 } /* endif (UERROR_UNBOUNDEDPDF) */
1609 if (UERROR_MULTIMODAL) { /* --------------------------- */
1610
1611 printf("\nMultimodal distributions:\n");
1612 fprintf(TESTLOG,"\n--- Multimodal distributions --- \n\n");
1613
1614
1615 if (ALL) {
1616 printf(" sin-2-example");
1617 distr = unur_distr_cont_new();
1618 unur_distr_set_name(distr,"sin-2-example");
1619 unur_distr_cont_set_cdf( distr, sin_2_cdf );
1620 unur_distr_cont_set_pdf( distr, sin_2_pdf );
1621 unur_distr_cont_set_domain( distr, -1., 1. );
1622 unur_distr_cont_set_center(distr,0.25);
1623 par = unur_pinv_new(distr);
1624 errorsum += pinv_error_experiment(par,samplesize);
1625 unur_distr_free(distr);
1626 fprintf(TESTLOG,"\n");
1627 }
1628
1629
1630 if (ALL) {
1631 printf(" sin-10-example");
1632 distr = unur_distr_cont_new();
1633 unur_distr_set_name(distr,"sin-10-example");
1634 unur_distr_cont_set_cdf( distr, sin_10_cdf );
1635 unur_distr_cont_set_pdf( distr, sin_10_pdf );
1636 unur_distr_cont_set_domain( distr, -5., 5. );
1637 unur_distr_cont_set_center(distr,0.25);
1638 par = unur_pinv_new(distr);
1639 errorsum += pinv_error_experiment(par,samplesize);
1640 unur_distr_free(distr);
1641 fprintf(TESTLOG,"\n");
1642 }
1643
1644 } /* endif (UERROR_MULTIMODAL) */
1645 if (UERROR_MULTIMODAL_VANISHINGPDF) { /* --------------------------- */
1646
1647 printf("\nMultimodal distributions with vanishing PDF:\n");
1648 fprintf(TESTLOG,"\n--- Multimodal distributions with vanishing PDF --- \n\n");
1649
1650
1651 if (ALL) {
1652 printf(" sin-2-example");fflush(stdout);
1653 distr = unur_distr_cont_new();
1654 unur_distr_set_name(distr,"sin-0-example");
1655 unur_distr_cont_set_cdf( distr, sin_2_cdf );
1656 unur_distr_cont_set_pdf( distr, sin_2_pdf );
1657 unur_distr_cont_set_domain( distr, -2., 2. );
1658 unur_distr_cont_set_center(distr,0.25);
1659 par = unur_pinv_new(distr);
1660 errorsum += pinv_error_experiment(par,samplesize);
1661 unur_distr_free(distr);
1662 fprintf(TESTLOG,"\n");
1663 }
1664
1665 if (ALL) {
1666 printf(" sin-2-example");fflush(stdout);
1667 distr = unur_distr_cont_new();
1668 unur_distr_set_name(distr,"sin-0-example");
1669 unur_distr_cont_set_cdf( distr, sin_2_cdf );
1670 unur_distr_cont_set_pdf( distr, sin_2_pdf );
1671 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1672 unur_distr_cont_set_center(distr,0.25);
1673 par = unur_pinv_new(distr);
1674 errorsum += pinv_error_experiment(par,samplesize);
1675 unur_distr_free(distr);
1676 fprintf(TESTLOG,"\n");
1677 }
1678
1679
1680 if (ALL) {
1681 printf(" sin-10-example");
1682 distr = unur_distr_cont_new();
1683 unur_distr_set_name(distr,"sin-10-example");
1684 unur_distr_cont_set_cdf( distr, sin_10_cdf );
1685 unur_distr_cont_set_pdf( distr, sin_10_pdf );
1686 unur_distr_cont_set_domain(distr,-UNUR_INFINITY,UNUR_INFINITY);
1687 unur_distr_cont_set_center(distr,0.25);
1688 par = unur_pinv_new(distr);
1689 errorsum += pinv_error_experiment(par,samplesize);
1690 unur_distr_free(distr);
1691 fprintf(TESTLOG,"\n");
1692 }
1693
1694 } /* endif (UERROR_MULTIMODAL_VANISHINGPDF) */
1695
1696
1697 /*---------------------------------------------------------------------------*/
1698
1699 /* test finished */
1700 FAILED = (errorsum < 2) ? 0 : 1;
1701
1702
1703
1704
1705 /* timing */
1706 stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
1707
1708 /* test finished */
1709 test_ok &= (FAILED) ? 0 : 1;
1710 (FAILED) ? printf(" ==> failed] ") : printf(" ==> ok] ");
1711
1712 } /* end of test_special() */
1713
1714
1715 /*---------------------------------------------------------------------------*/
1716 /* run generator in verifying mode */
1717
run_verify_generator(FILE * LOG,int line,UNUR_PAR * par)1718 void run_verify_generator( FILE *LOG, int line, UNUR_PAR *par )
1719 {
1720 UNUR_GEN *gen;
1721 int i;
1722
1723 /* switch to verifying mode */
1724 unur_pinv_set_verify(par,1);
1725
1726 /* initialize generator */
1727 gen = unur_init( par ); abort_if_NULL(LOG, line, gen);
1728
1729 /* run generator */
1730 for (i=0; i<VIOLATE_SAMPLE_SIZE; i++)
1731 unur_sample_cont(gen);
1732
1733 /* destroy generator */
1734 unur_free(gen);
1735
1736 } /* end of run_verify_generator() */
1737
unur_pinv_set_verify(UNUR_PAR * par ATTRIBUTE__UNUSED,int verify ATTRIBUTE__UNUSED)1738 int unur_pinv_set_verify(UNUR_PAR *par ATTRIBUTE__UNUSED, int verify ATTRIBUTE__UNUSED) {return 0;}
1739
1740 /*---------------------------------------------------------------------------*/
1741
main(void)1742 int main(void)
1743 {
1744 unsigned long seed;
1745 char *str_seed, *str_tail;
1746
1747 /* start stop watch */
1748 stopwatch_init();
1749 stopwatch_start(&watch);
1750
1751 /* open log file for unuran and set output stream for unuran messages */
1752 UNURANLOG = fopen( "t_pinv_unuran.log","w" );
1753 abort_if_NULL( stderr,-1, UNURANLOG );
1754 unur_set_stream( UNURANLOG );
1755
1756 /* open log file for testing */
1757 TESTLOG = fopen( "t_pinv_test.log","w" );
1758 abort_if_NULL( stderr,-1, TESTLOG );
1759
1760 /* seed for uniform generators */
1761
1762 /* seed set by environment */
1763 str_seed = getenv("SEED");
1764
1765 if (str_seed != NULL) {
1766 seed = strtol(str_seed, &str_tail, 10);
1767 if (seed == 0u)
1768 seed = 966759;
1769 }
1770 else {
1771 #ifdef SEED
1772 seed = SEED;
1773 #else
1774 seed = 966759;
1775 #endif
1776 }
1777
1778 /* seed build-in uniform generators */
1779 unur_urng_MRG31k3p_seed(NULL,seed);
1780 unur_urng_fish_seed(NULL,seed);
1781 unur_urng_mstd_seed(NULL,seed);
1782
1783 /* seed uniform random number generator */
1784 #ifdef UNUR_URNG_UNURAN
1785 # ifdef UNUR_URNG_DEFAULT_RNGSTREAM
1786 {
1787 unsigned long sa[6];
1788 int i;
1789 for (i=0; i<6; i++) sa[i] = seed;
1790 RngStream_SetPackageSeed(sa);
1791 }
1792 # else
1793 if (unur_urng_seed(NULL,seed) != UNUR_SUCCESS) {
1794 fprintf(stderr,"WARNING: Seed could not be set at random\n");
1795 seed = ~0u;
1796 }
1797 # endif /* UNUR_URNG_DEFAULT_RNGSTREAM */
1798 #endif /* UNUR_URNG_UNURAN */
1799
1800 /* set default debugging flag */
1801 unur_set_default_debug(UNUR_DEBUG_ALL);
1802
1803 /* detect required check mode */
1804 fullcheck = (getenv("UNURANFULLCHECK")==NULL) ? FALSE : TRUE;
1805
1806 /* write header into log file */
1807 print_test_log_header( TESTLOG, seed, fullcheck );
1808
1809 /* set timer for sending SIGALRM signal */
1810 set_alarm(TESTLOG);
1811
1812 /* start test */
1813 printf("pinv: ");
1814
1815 /* run tests */
1816 test_new();
1817 test_set();
1818 test_get();
1819 test_sample();
1820 test_validate();
1821 test_special();
1822
1823
1824 /* test finished */
1825 printf("\n"); fflush(stdout);
1826
1827 /* close log files */
1828 fprintf(TESTLOG,"\n====================================================\n\n");
1829 if (test_ok)
1830 fprintf(TESTLOG,"All tests PASSED.\n");
1831 else
1832 fprintf(TESTLOG,"Test(s) FAILED.\n");
1833
1834 /* timing */
1835 stopwatch_print(TESTLOG,"\n<*>total time = %.0f ms\n\n", stopwatch_stop(&watch));
1836
1837 fclose(UNURANLOG);
1838 fclose(TESTLOG);
1839
1840 /* free memory */
1841 compare_free_memory();
1842 unur_urng_free(unur_get_default_urng());
1843 unur_urng_free(unur_get_default_urng_aux());
1844
1845 /* exit */
1846 exit( (test_ok) ? EXIT_SUCCESS : EXIT_FAILURE );
1847
1848 } /* end of main */
1849
1850