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 NORTA
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_norta_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 /* prototypes */
59 
60 #define COMPARE_SAMPLE_SIZE   (10000)
61 #define VIOLATE_SAMPLE_SIZE   (20)
62 
63 
64 
65 
66 /*---------------------------------------------------------------------------*/
67 
68 #ifndef CHI2_FAILURES_TOLERATED
69 #  define CHI2_FAILURES_TOLERATED DEFAULT_CHI2_FAILURES_TOLERATED
70 #endif
71 
72 /*---------------------------------------------------------------------------*/
73 /* [verbatim] */
74 
75 
76 
77 /*---------------------------------------------------------------------------*/
78 /* [new] */
79 
test_new(void)80 void test_new (void)
81 {
82         int n_tests_failed;          /* number of failed tests */
83 
84 	/* start test */
85 	printf("[new "); fflush(stdout);
86 	fprintf(TESTLOG,"\n[new]\n");
87 
88 	/* reset counter */
89 	n_tests_failed = 0;
90 
91 	/* set stop watch */
92 	stopwatch_lap(&watch);
93 
94 { /* invalid NULL ptr */
95 UNUR_DISTR *distr = NULL;
96    distr = NULL;
97 
98 
99 unur_reset_errno();
100 n_tests_failed += (check_expected_NULL(TESTLOG,26,(unur_norta_new( distr )))==UNUR_SUCCESS)?0:1;
101 n_tests_failed += (check_errorcode(TESTLOG,26,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
102 unur_distr_free(distr);
103 }
104 
105 { /* invalid distribution type */
106 UNUR_DISTR *distr = NULL;
107    distr = unur_distr_discr_new();
108 
109 
110 unur_reset_errno();
111 n_tests_failed += (check_expected_NULL(TESTLOG,33,(unur_norta_new( distr )))==UNUR_SUCCESS)?0:1;
112 n_tests_failed += (check_errorcode(TESTLOG,33,UNUR_ERR_DISTR_INVALID)==UNUR_SUCCESS)?0:1;
113 unur_distr_free(distr);
114 }
115 
116 { /* data missing in distribution object */
117 UNUR_DISTR *distr = NULL;
118    double mean[] = {1.,2.};
119    double covar[] = {2.,1., 1., 2.};
120    distr = unur_distr_cvec_new(2);
121 
122 
123 unur_reset_errno();
124 /* mean */
125 n_tests_failed += (check_expected_NULL(TESTLOG,43,(unur_norta_new( distr )))==UNUR_SUCCESS)?0:1;
126 n_tests_failed += (check_errorcode(TESTLOG,43,UNUR_ERR_DISTR_REQUIRED)==UNUR_SUCCESS)?0:1;
127 
128 unur_reset_errno();
129 /* covariance matrix */
130 unur_distr_cvec_set_mean(distr,mean);
131 unur_distr_cvec_set_covar(distr,covar);
132 n_tests_failed += (check_expected_NULL(TESTLOG,49,(unur_norta_new( distr )))==UNUR_SUCCESS)?0:1;
133 n_tests_failed += (check_errorcode(TESTLOG,49,UNUR_ERR_DISTR_REQUIRED)==UNUR_SUCCESS)?0:1;
134 unur_distr_free(distr);
135 }
136 
137 
138 	/* timing */
139 	stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
140 
141 	/* test finished */
142 	test_ok &= (n_tests_failed) ? 0 : 1;
143 	(n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
144 
145 } /* end of test_new() */
146 
147 /*---------------------------------------------------------------------------*/
148 /* [reinit] */
149 
test_reinit(void)150 void test_reinit (void)
151 {
152         int n_tests_failed;          /* number of failed tests */
153 
154 	/* start test */
155 	printf("[reinit "); fflush(stdout);
156 	fprintf(TESTLOG,"\n[reinit]\n");
157 
158 	/* reset counter */
159 	n_tests_failed = 0;
160 
161 	/* set stop watch */
162 	stopwatch_lap(&watch);
163 
164 { /* does not exist */
165 UNUR_DISTR *distr = NULL;
166 UNUR_PAR   *par = NULL;
167 UNUR_GEN   *gen = NULL;
168    double x[3];
169    const int dim = 3;
170    double rankcorr[] = { 1., 0.5, 0.1,  0.5, 1., 0.3,  0.1, 0.3, 1. };
171    distr = unur_distr_copula(dim, rankcorr);
172    par = unur_norta_new(distr);
173    gen = unur_init( par );
174 abort_if_NULL(TESTLOG, 77,    gen );
175 
176 
177 unur_reset_errno();
178 n_tests_failed += (check_expected_setfailed(TESTLOG,81,(unur_reinit( gen )))==UNUR_SUCCESS)?0:1;
179 n_tests_failed += (check_errorcode(TESTLOG,81,UNUR_ERR_NO_REINIT)==UNUR_SUCCESS)?0:1;
180 
181 unur_reset_errno();
182 unur_sample_vec( gen, x );
183 n_tests_failed += (check_expected_INFINITY(TESTLOG,85,(x[0]))==UNUR_SUCCESS)?0:1;
184 n_tests_failed += (check_errorcode(TESTLOG,85,UNUR_ERR_GEN_CONDITION)==UNUR_SUCCESS)?0:1;
185 unur_distr_free(distr);
186 unur_free(gen);
187 }
188 
189 
190 	/* timing */
191 	stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
192 
193 	/* test finished */
194 	test_ok &= (n_tests_failed) ? 0 : 1;
195 	(n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
196 
197 } /* end of test_reinit() */
198 
199 /*---------------------------------------------------------------------------*/
200 /* [sample] */
201 
test_sample(void)202 void test_sample (void)
203 {
204         int n_tests_failed;          /* number of failed tests */
205 
206 	/* start test */
207 	printf("[sample "); fflush(stdout);
208 	fprintf(TESTLOG,"\n[sample]\n");
209 
210 	/* reset counter */
211 	n_tests_failed = 0;
212 
213 	/* set stop watch */
214 	stopwatch_lap(&watch);
215 
216 { /* compare clone */
217 UNUR_DISTR *distr = NULL;
218 UNUR_PAR   *par = NULL;
219 UNUR_GEN   *gen = NULL;
220    const int dim = 3;
221    UNUR_GEN *clone;
222    distr = unur_distr_copula(dim, NULL);
223    par = unur_norta_new(distr);
224    gen = unur_init( par );
225 abort_if_NULL(TESTLOG, 96,    gen );
226 
227 
228 unur_reset_errno();
229 /* copula without correlation */;
230 n_tests_failed += (compare_sequence_gen_start(TESTLOG,100,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
231 
232 unur_reset_errno();
233 /* clone */
234 clone = unur_gen_clone(gen);
235 unur_free(gen);
236 gen = clone;
237 n_tests_failed += (compare_sequence_gen(TESTLOG,106,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
238 unur_distr_free(distr);
239 unur_free(gen);
240 }
241 
242 { /* compare clone */
243 UNUR_DISTR *distr = NULL;
244 UNUR_PAR   *par = NULL;
245 UNUR_GEN   *gen = NULL;
246    const int dim = 3;
247    double rankcorr[] = { 1., 0.5, 0.1,  0.5, 1., 0.3,  0.1, 0.3, 1. };
248    UNUR_GEN *clone;
249    distr = unur_distr_copula(dim, rankcorr);
250    par = unur_norta_new(distr);
251    gen = unur_init( par );
252 abort_if_NULL(TESTLOG, 115,    gen );
253 
254 
255 unur_reset_errno();
256 /* copula with correlation */;
257 n_tests_failed += (compare_sequence_gen_start(TESTLOG,119,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
258 
259 unur_reset_errno();
260 /* clone */
261 clone = unur_gen_clone(gen);
262 unur_free(gen);
263 gen = clone;
264 n_tests_failed += (compare_sequence_gen(TESTLOG,125,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
265 unur_distr_free(distr);
266 unur_free(gen);
267 }
268 
269 { /* compare clone */
270 UNUR_DISTR *distr = NULL;
271 UNUR_PAR   *par = NULL;
272 UNUR_GEN   *gen = NULL;
273    const int dim = 3;
274    double rankcorr[] = { 1., 0.5, 0.1,  0.5, 1., 0.3,  0.1, 0.3, 1. };
275    double gamma_params[] = {5.};
276    UNUR_GEN *clone;
277    UNUR_DISTR *marginal;
278    distr = unur_distr_cvec_new(dim);
279    unur_distr_cvec_set_rankcorr(distr,rankcorr);
280    marginal = unur_distr_gamma(gamma_params,1);
281    unur_distr_cvec_set_marginals(distr,marginal);
282    unur_distr_free(marginal);
283    par = unur_norta_new(distr);
284    gen = unur_init( par );
285 abort_if_NULL(TESTLOG, 140,    gen );
286 
287 
288 unur_reset_errno();
289 /* gamma marginals with correlation */;
290 n_tests_failed += (compare_sequence_gen_start(TESTLOG,144,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
291 
292 unur_reset_errno();
293 /* clone */
294 clone = unur_gen_clone(gen);
295 unur_free(gen);
296 gen = clone;
297 n_tests_failed += (compare_sequence_gen(TESTLOG,150,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
298 unur_distr_free(distr);
299 unur_free(gen);
300 }
301 
302 { /* compare clone */
303 UNUR_DISTR *distr = NULL;
304 UNUR_PAR   *par = NULL;
305 UNUR_GEN   *gen = NULL;
306    const int dim = 3;
307    double rankcorr[] = { 1., 0.5, 0.1,  0.5, 1., 0.3,  0.1, 0.3, 1. };
308    double gamma_params[] = {5.};
309    double beta_params[] = {3.,5.};
310    UNUR_GEN *clone;
311    distr = unur_distr_cvec_new(dim);
312    unur_distr_cvec_set_rankcorr(distr,rankcorr);
313    unur_distr_cvec_set_marginal_list(distr,
314         unur_distr_cauchy(NULL,0),
315         unur_distr_gamma(gamma_params,1),
316         unur_distr_beta(beta_params,2) );
317    par = unur_norta_new(distr);
318    gen = unur_init( par );
319 abort_if_NULL(TESTLOG, 166,    gen );
320 
321 
322 unur_reset_errno();
323 /* multivariate distribution with given marginals */;
324 n_tests_failed += (compare_sequence_gen_start(TESTLOG,170,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
325 
326 unur_reset_errno();
327 /* clone */
328 clone = unur_gen_clone(gen);
329 unur_free(gen);
330 gen = clone;
331 n_tests_failed += (compare_sequence_gen(TESTLOG,176,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
332 unur_distr_free(distr);
333 unur_free(gen);
334 }
335 
336 { /* compare clone */
337 UNUR_DISTR *distr = NULL;
338 UNUR_PAR   *par = NULL;
339 UNUR_GEN   *gen = NULL;
340    double rankcorr[] = { 1., 0.5, 0.1,  0.5, 1., 0.3,  0.1, 0.3, 1. };
341    double gamma_params[] = {5.};
342    double beta_params[] = {3.,5.};
343    UNUR_GEN *clone;
344    UNUR_DISTR *marginals[3];
345    distr = unur_distr_cvec_new(3);
346    unur_distr_cvec_set_rankcorr(distr,rankcorr);
347    marginals[0] = unur_distr_gamma(gamma_params,1);
348    marginals[1] = unur_distr_cauchy(NULL,0);
349    marginals[2] = unur_distr_beta(beta_params,2);
350    unur_distr_cvec_set_marginal_array(distr,marginals);
351    unur_distr_free(marginals[0]);
352    unur_distr_free(marginals[1]);
353    unur_distr_free(marginals[2]);
354    par = unur_norta_new(distr);
355    gen = unur_init( par );
356 abort_if_NULL(TESTLOG, 195,    gen );
357 
358 
359 unur_reset_errno();
360 /* multivariate distribution with given marginals */;
361 n_tests_failed += (compare_sequence_gen_start(TESTLOG,199,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
362 
363 unur_reset_errno();
364 /* clone */
365 clone = unur_gen_clone(gen);
366 unur_free(gen);
367 gen = clone;
368 n_tests_failed += (compare_sequence_gen(TESTLOG,205,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
369 unur_distr_free(distr);
370 unur_free(gen);
371 }
372 
373 { /* compare clone 1dim */
374 UNUR_DISTR *distr = NULL;
375 UNUR_PAR   *par = NULL;
376 UNUR_GEN   *gen = NULL;
377    const int dim = 1;
378    double beta_params[] = {3.,5.};
379    UNUR_GEN *clone;
380    distr = unur_distr_cvec_new(dim);
381    unur_distr_cvec_set_rankcorr(distr,NULL);
382    unur_distr_cvec_set_marginal_list(distr,
383 	unur_distr_beta(beta_params,2) );
384    par = unur_norta_new(distr);
385    gen = unur_init( par );
386 abort_if_NULL(TESTLOG, 217,    gen );
387 
388 
389 unur_reset_errno();
390 /* multivariate distribution with given marginals */;
391 n_tests_failed += (compare_sequence_gen_start(TESTLOG,221,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
392 
393 unur_reset_errno();
394 /* clone */
395 clone = unur_gen_clone(gen);
396 unur_free(gen);
397 gen = clone;
398 n_tests_failed += (compare_sequence_gen(TESTLOG,227,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
399 unur_distr_free(distr);
400 unur_free(gen);
401 }
402 
403 
404 	/* timing */
405 	stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
406 
407 	/* test finished */
408 	test_ok &= (n_tests_failed) ? 0 : 1;
409 	(n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
410 
411 } /* end of test_sample() */
412 
413 /*---------------------------------------------------------------------------*/
414 /* [validate] */
415 
416 /*---------------------------------------------------------------------------*/
417 
418 /* [validate] */
419 
test_validate(void)420 void test_validate (void)
421 {
422 	UNUR_DISTR *distr[11];
423 	UNUR_PAR *par;
424 	UNUR_GEN *gen;
425 	int n_tests_failed;
426 	int rcode;
427 	double *darray;
428 	double fpm[10];
429 
430 	rcode = 0;
431 
432 	/* start test */
433 	printf("[validate "); fflush(stdout);
434 	fprintf(TESTLOG,"\n[validate]\n");
435 
436 	/* reset counter */
437 	n_tests_failed = 0;
438 
439 	/* set stop watch */
440 	stopwatch_lap(&watch);
441 
442 
443 /* distributions: 11 */
444 {
445 distr[0] = unur_distr_copula(3,NULL);
446 }
447 
448 {
449 double rankcorr[] = { 1., 0.5, 0.1,  0.5, 1., 0.3,  0.1, 0.3, 1. };
450 distr[1] = unur_distr_copula(3, rankcorr);
451 }
452 
453 {
454 #define dim (3)
455 double rankcorr[] = { 1., 0.5, 0.1,  0.5, 1., 0.3,  0.1, 0.3, 1. };
456 double gamma_params[] = {5.};
457 UNUR_DISTR *marginal;
458 distr[2] = unur_distr_cvec_new(dim);
459 unur_distr_cvec_set_rankcorr(distr[2],rankcorr);
460 marginal = unur_distr_gamma(gamma_params,1);
461 unur_distr_cvec_set_marginals(distr[2],marginal);
462 unur_distr_free(marginal);
463 unur_distr_set_name(distr[2],"gamma marginals");
464 #undef dim
465 }
466 
467 {
468 #define dim (3)
469 double rankcorr[] = { 1., 0.5, 0.1,  0.5, 1., 0.3,  0.1, 0.3, 1. };
470 double gamma_params[] = {5.};
471 double beta_params[] = {3.,5.};
472 distr[3] = unur_distr_cvec_new(dim);
473 unur_distr_cvec_set_rankcorr(distr[3],rankcorr);
474 unur_distr_cvec_set_marginal_list(distr[3],
475 	unur_distr_gamma(gamma_params,1),
476 	unur_distr_cauchy(NULL,0),
477 	unur_distr_beta(beta_params,2) );
478 unur_distr_set_name(distr[3],"gamma-cauchy-beta marginals");
479 #undef dim
480 }
481 
482 {
483 #define dim (3)
484 UNUR_DISTR *corr_distr;
485 UNUR_GEN *corr_gen;
486 double corr[dim*dim];
487 corr_distr = unur_distr_correlation(dim);
488 corr_gen = unur_init(unur_mcorr_new(corr_distr));
489 do {
490    unur_sample_matr(corr_gen,corr);
491    distr[4] = unur_distr_copula(dim, corr);
492 } while (distr[4]==NULL);
493 unur_distr_free(corr_distr);
494 unur_free(corr_gen);
495 unur_distr_set_name(distr[4],"copula with random correlations");
496 #undef dim
497 }
498 
499 {
500 #define dim (10)
501 UNUR_DISTR *corr_distr;
502 UNUR_GEN *corr_gen;
503 double corr[dim*dim];
504 corr_distr = unur_distr_correlation(dim);
505 corr_gen = unur_init(unur_mcorr_new(corr_distr));
506 do {
507    unur_sample_matr(corr_gen,corr);
508    distr[5] = unur_distr_copula(dim, corr);
509 } while (distr[5]==NULL);
510 unur_distr_free(corr_distr);
511 unur_free(corr_gen);
512 unur_distr_set_name(distr[5],"copula with random correlations");
513 #undef dim
514 }
515 
516 {
517 #define dim (30)
518 UNUR_DISTR *corr_distr;
519 UNUR_GEN *corr_gen;
520 double corr[dim*dim];
521 corr_distr = unur_distr_correlation(dim);
522 corr_gen = unur_init(unur_mcorr_new(corr_distr));
523 do {
524    unur_sample_matr(corr_gen,corr);
525    distr[6] = unur_distr_copula(dim, corr);
526 } while (distr[6]==NULL);
527 unur_distr_free(corr_distr);
528 unur_free(corr_gen);
529 unur_distr_set_name(distr[6],"copula with random correlations");
530 #undef dim
531 }
532 
533 {
534 #define dim (100)
535 UNUR_DISTR *corr_distr;
536 UNUR_GEN *corr_gen;
537 double corr[dim*dim];
538 corr_distr = unur_distr_correlation(dim);
539 corr_gen = unur_init(unur_mcorr_new(corr_distr));
540 do {
541    unur_sample_matr(corr_gen,corr);
542    distr[7] = unur_distr_copula(dim, corr);
543 } while (distr[7]==NULL);
544 unur_distr_free(corr_distr);
545 unur_free(corr_gen);
546 unur_distr_set_name(distr[7],"copula with random correlations");
547 #undef dim
548 }
549 
550 {
551 #define dim (3)
552 double ll[3] = {0.,1.,0.};
553 double ru[3] = {1.,UNUR_INFINITY,UNUR_INFINITY};
554 double rankcorr[] = { 1., 0., 0.,  0., 1., 0.,  0., 0., 1. };
555 double gamma_params[] = {5.};
556 UNUR_DISTR *marginal;
557 distr[8] = unur_distr_cvec_new(dim);
558 unur_distr_cvec_set_rankcorr(distr[8],rankcorr);
559 marginal = unur_distr_gamma(gamma_params,1);
560 unur_distr_cvec_set_marginals(distr[8],marginal);
561 unur_distr_cvec_set_domain_rect(distr[8],ll,ru);
562 unur_distr_free(marginal);
563 unur_distr_set_name(distr[8],"gamma marginals with rectangular domain");
564 #undef dim
565 }
566 
567 {
568 #define dim (3)
569 double ll[3] = {0.,1.,2.};
570 double ru[3] = {1.,2., 3.};
571 double rankcorr[] = { 1., 0.5, 0.1,  0.5, 1., 0.3,  0.1, 0.3, 1. };
572 double gamma_params[] = {5.};
573 UNUR_DISTR *marginal;
574 distr[9] = unur_distr_cvec_new(dim);
575 unur_distr_cvec_set_rankcorr(distr[9],rankcorr);
576 marginal = unur_distr_gamma(gamma_params,1);
577 unur_distr_cvec_set_marginals(distr[9],marginal);
578 unur_distr_cvec_set_domain_rect(distr[9],ll,ru);
579 unur_distr_free(marginal);
580 unur_distr_set_name(distr[9],"gamma marginals with rectangular domain");
581 #undef dim
582 }
583 
584 {
585 #define dim (3)
586 double ll[3] = {0.,1.,2.};
587 double ru[3] = {1.,2., 3.};
588 double rankcorr[] = { 1., 0.5, 0.1,  0.5, 1., 0.3,  0.1, 0.3, 1. };
589 double gamma_params[] = {5.};
590 distr[10] = unur_distr_cvec_new(dim);
591 unur_distr_cvec_set_rankcorr(distr[10],rankcorr);
592 unur_distr_cvec_set_marginal_list(distr[10],
593 	unur_distr_gamma(gamma_params,1),
594 	unur_distr_gamma(gamma_params,1),
595 	unur_distr_gamma(gamma_params,1));
596 unur_distr_cvec_set_domain_rect(distr[10],ll,ru);
597 unur_distr_set_name(distr[10],"gamma marginals with rectangular domain");
598 #undef dim
599 }
600 
601 	/* timing */
602 	stopwatch_print(TESTLOG,"\n<*>setup time = %.3f ms\n", stopwatch_lap(&watch));
603 
604 	printf("\n(chi^2) "); fflush(stdout);
605 
606 /* chi^2 tests: 11 */
607 
608 	unur_set_default_debug(~UNUR_DEBUG_SAMPLE);
609 	fprintf( TESTLOG,"\nChi^2 Test:\n");
610 
611 /* distribution [0] */
612 
613 	if(TRUE) {
614 	unur_reset_errno();
615 	do {
616 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[0]);
617 par = unur_norta_new(distr_localcopy);
618 	gen = unur_init(par);
619 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[0],'+');
620 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
621 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
622 	unur_free(gen);
623 	unur_distr_free(distr_localcopy);
624 	} while (0);
625 	}
626 
627 /* distribution [1] */
628 
629 	if(TRUE) {
630 	unur_reset_errno();
631 	do {
632 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[1]);
633 par = unur_norta_new(distr_localcopy);
634 	gen = unur_init(par);
635 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[1],'+');
636 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
637 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
638 	unur_free(gen);
639 	unur_distr_free(distr_localcopy);
640 	} while (0);
641 	}
642 
643 /* distribution [2] */
644 
645 	if(TRUE) {
646 	unur_reset_errno();
647 	do {
648 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[2]);
649 par = unur_norta_new(distr_localcopy);
650 	gen = unur_init(par);
651 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[2],'+');
652 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
653 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
654 	unur_free(gen);
655 	unur_distr_free(distr_localcopy);
656 	} while (0);
657 	}
658 
659 /* distribution [3] */
660 
661 	if(TRUE) {
662 	unur_reset_errno();
663 	do {
664 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[3]);
665 par = unur_norta_new(distr_localcopy);
666 	gen = unur_init(par);
667 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[3],'+');
668 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
669 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
670 	unur_free(gen);
671 	unur_distr_free(distr_localcopy);
672 	} while (0);
673 	}
674 
675 /* distribution [4] */
676 
677 	if(TRUE) {
678 	unur_reset_errno();
679 	do {
680 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[4]);
681 par = unur_norta_new(distr_localcopy);
682 	gen = unur_init(par);
683 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[4],'+');
684 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
685 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
686 	unur_free(gen);
687 	unur_distr_free(distr_localcopy);
688 	} while (0);
689 	}
690 
691 /* distribution [5] */
692 
693 	if(TRUE) {
694 	unur_reset_errno();
695 	do {
696 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[5]);
697 par = unur_norta_new(distr_localcopy);
698 	gen = unur_init(par);
699 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[5],'+');
700 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
701 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
702 	unur_free(gen);
703 	unur_distr_free(distr_localcopy);
704 	} while (0);
705 	}
706 
707 /* distribution [6] */
708 
709 	if(TRUE) {
710 	unur_reset_errno();
711 	do {
712 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[6]);
713 par = unur_norta_new(distr_localcopy);
714 	gen = unur_init(par);
715 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[6],'+');
716 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
717 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
718 	unur_free(gen);
719 	unur_distr_free(distr_localcopy);
720 	} while (0);
721 	}
722 
723 /* distribution [7] */
724 
725 	if(TRUE) {
726 	unur_reset_errno();
727 	do {
728 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[7]);
729 par = unur_norta_new(distr_localcopy);
730 	gen = unur_init(par);
731 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[7],'+');
732 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
733 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
734 	unur_free(gen);
735 	unur_distr_free(distr_localcopy);
736 	} while (0);
737 	}
738 
739 /* distribution [8] */
740 
741 	if(TRUE) {
742 	unur_reset_errno();
743 	do {
744 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[8]);
745 par = unur_norta_new(distr_localcopy);
746 	gen = unur_init(par);
747 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[8],'+');
748 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
749 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
750 	unur_free(gen);
751 	unur_distr_free(distr_localcopy);
752 	} while (0);
753 	}
754 
755 /* distribution [9] */
756 
757 	if(TRUE) {
758 	unur_reset_errno();
759 	do {
760 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[9]);
761 par = unur_norta_new(distr_localcopy);
762 	gen = unur_init(par);
763 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[9],'+');
764 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
765 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
766 	unur_free(gen);
767 	unur_distr_free(distr_localcopy);
768 	} while (0);
769 	}
770 
771 /* distribution [10] */
772 
773 	if(TRUE) {
774 	unur_reset_errno();
775 	do {
776 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[10]);
777 par = unur_norta_new(distr_localcopy);
778 	gen = unur_init(par);
779 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[10],'+');
780 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
781 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
782 	unur_free(gen);
783 	unur_distr_free(distr_localcopy);
784 	} while (0);
785 	}
786 
787 	/* timing */
788 	stopwatch_print(TESTLOG,"\n<*>time = %.0f ms\n", stopwatch_lap(&watch));
789 
790 
791 /* free distributions */
792 	unur_distr_free(distr[0]);
793 	unur_distr_free(distr[1]);
794 	unur_distr_free(distr[2]);
795 	unur_distr_free(distr[3]);
796 	unur_distr_free(distr[4]);
797 	unur_distr_free(distr[5]);
798 	unur_distr_free(distr[6]);
799 	unur_distr_free(distr[7]);
800 	unur_distr_free(distr[8]);
801 	unur_distr_free(distr[9]);
802 	unur_distr_free(distr[10]);
803 
804 	/* test finished */
805 	test_ok &= (n_tests_failed>CHI2_FAILURES_TOLERATED) ? 0 : 1;
806 	/* we accept CHI2_FAILURES_TOLERATED failures */
807 	(n_tests_failed>CHI2_FAILURES_TOLERATED) ? printf(" ==> failed] ") : printf(" ==> ok] ");
808 
809 	/* prevent compiler from making useless annoying warnings */
810 	distr[0] = NULL;
811 	par = NULL;
812 	gen = NULL;
813 	darray = NULL;
814 	fpm[0] = 0.;
815 
816 } /* end of test_validate */
817 
818 
819 /*---------------------------------------------------------------------------*/
820 /* run generator in verifying mode */
821 
run_verify_generator(FILE * LOG,int line,UNUR_PAR * par)822 void run_verify_generator( FILE *LOG, int line, UNUR_PAR *par )
823 {
824 	UNUR_GEN *gen;
825 	int i;
826 
827 	/* switch to verifying mode */
828 	unur_norta_set_verify(par,1);
829 
830 	/* initialize generator */
831 	gen = unur_init( par ); abort_if_NULL(LOG, line, gen);
832 
833 	/* run generator */
834 	for (i=0; i<VIOLATE_SAMPLE_SIZE; i++)
835 		unur_sample_cont(gen);
836 
837 	/* destroy generator */
838 	unur_free(gen);
839 
840 } /* end of run_verify_generator() */
841 
unur_norta_set_verify(UNUR_PAR * par ATTRIBUTE__UNUSED,int verify ATTRIBUTE__UNUSED)842 int unur_norta_set_verify(UNUR_PAR *par ATTRIBUTE__UNUSED, int verify ATTRIBUTE__UNUSED) {return 0;}
843 
844 /*---------------------------------------------------------------------------*/
845 
main(void)846 int main(void)
847 {
848         unsigned long seed;
849 	char *str_seed, *str_tail;
850 
851 	/* start stop watch */
852 	stopwatch_init();
853 	stopwatch_start(&watch);
854 
855         /* open log file for unuran and set output stream for unuran messages */
856         UNURANLOG = fopen( "t_norta_unuran.log","w" );
857         abort_if_NULL( stderr,-1, UNURANLOG );
858         unur_set_stream( UNURANLOG );
859 
860         /* open log file for testing */
861 	TESTLOG = fopen( "t_norta_test.log","w" );
862 	abort_if_NULL( stderr,-1, TESTLOG );
863 
864         /* seed for uniform generators */
865 
866 	/* seed set by environment */
867 	str_seed = getenv("SEED");
868 
869 	if (str_seed != NULL) {
870 	    seed = strtol(str_seed, &str_tail, 10);
871 	    if (seed == 0u)
872 		seed = 765794;
873 	}
874 	else {
875 #ifdef SEED
876 	    seed = SEED;
877 #else
878 	    seed = 765794;
879 #endif
880 	}
881 
882         /* seed build-in uniform generators */
883         unur_urng_MRG31k3p_seed(NULL,seed);
884         unur_urng_fish_seed(NULL,seed);
885 	unur_urng_mstd_seed(NULL,seed);
886 
887 	/* seed uniform random number generator */
888 #ifdef UNUR_URNG_UNURAN
889 #  ifdef UNUR_URNG_DEFAULT_RNGSTREAM
890 	{
891 	        unsigned long sa[6];
892 	        int i;
893 	        for (i=0; i<6; i++) sa[i] = seed;
894                 RngStream_SetPackageSeed(sa);
895         }
896 #  else
897 	if (unur_urng_seed(NULL,seed) != UNUR_SUCCESS) {
898 	        fprintf(stderr,"WARNING: Seed could not be set at random\n");
899                 seed = ~0u;
900 	}
901 #  endif  /* UNUR_URNG_DEFAULT_RNGSTREAM */
902 #endif  /* UNUR_URNG_UNURAN */
903 
904 	/* set default debugging flag */
905 	unur_set_default_debug(UNUR_DEBUG_ALL);
906 
907         /* detect required check mode */
908         fullcheck = (getenv("UNURANFULLCHECK")==NULL) ? FALSE : TRUE;
909 
910 	/* write header into log file */
911         print_test_log_header( TESTLOG, seed, fullcheck );
912 
913 	/* set timer for sending SIGALRM signal */
914 	set_alarm(TESTLOG);
915 
916 	/* start test */
917 	printf("norta: ");
918 
919 	/* run tests */
920 test_new();
921 test_reinit();
922 test_sample();
923 test_validate();
924 
925 
926 	/* test finished */
927 	printf("\n");  fflush(stdout);
928 
929 	/* close log files */
930 	fprintf(TESTLOG,"\n====================================================\n\n");
931 	if (test_ok)
932 		fprintf(TESTLOG,"All tests PASSED.\n");
933 	else
934 		fprintf(TESTLOG,"Test(s) FAILED.\n");
935 
936 	/* timing */
937 	stopwatch_print(TESTLOG,"\n<*>total time = %.0f ms\n\n", stopwatch_stop(&watch));
938 
939 	fclose(UNURANLOG);
940 	fclose(TESTLOG);
941 
942 	/* free memory */
943 	compare_free_memory();
944 	unur_urng_free(unur_get_default_urng());
945 	unur_urng_free(unur_get_default_urng_aux());
946 
947 	/* exit */
948 	exit( (test_ok) ? EXIT_SUCCESS : EXIT_FAILURE );
949 
950 } /* end of main */
951 
952