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 MVSTD
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_mvstd_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  (500)
61 #define VIOLATE_SAMPLE_SIZE  (20)
62 
63 /* #define SEED   (298346) */
64 
65 /* we need marginal distributions for the chi2 tests */
66 #define unur_distr_multinormal  unur_distr_multinormal_w_marginals
67 
68 
69 
70 
71 /*---------------------------------------------------------------------------*/
72 
73 #ifndef CHI2_FAILURES_TOLERATED
74 #  define CHI2_FAILURES_TOLERATED DEFAULT_CHI2_FAILURES_TOLERATED
75 #endif
76 
77 /*---------------------------------------------------------------------------*/
78 /* [verbatim] */
79 
80 
81 
82 /*---------------------------------------------------------------------------*/
83 /* [new] */
84 
test_new(void)85 void test_new (void)
86 {
87         int n_tests_failed;          /* number of failed tests */
88 
89 	/* start test */
90 	printf("[new "); fflush(stdout);
91 	fprintf(TESTLOG,"\n[new]\n");
92 
93 	/* reset counter */
94 	n_tests_failed = 0;
95 
96 	/* set stop watch */
97 	stopwatch_lap(&watch);
98 
99 { /* invalid NULL ptr */
100 UNUR_DISTR *distr = NULL;
101    distr = NULL;
102 
103 
104 unur_reset_errno();
105 n_tests_failed += (check_expected_NULL(TESTLOG,31,(unur_mvstd_new( distr )))==UNUR_SUCCESS)?0:1;
106 n_tests_failed += (check_errorcode(TESTLOG,31,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
107 unur_distr_free(distr);
108 }
109 
110 { /* invalid distribution type */
111 UNUR_DISTR *distr = NULL;
112    distr = unur_distr_cont_new();
113 
114 
115 unur_reset_errno();
116 n_tests_failed += (check_expected_NULL(TESTLOG,37,(unur_mvstd_new( distr )))==UNUR_SUCCESS)?0:1;
117 n_tests_failed += (check_errorcode(TESTLOG,37,UNUR_ERR_DISTR_INVALID)==UNUR_SUCCESS)?0:1;
118 unur_distr_free(distr);
119 }
120 
121 { /* not a standard distribution */
122 UNUR_DISTR *distr = NULL;
123    distr = unur_distr_cvec_new(3);
124 
125 
126 unur_reset_errno();
127 n_tests_failed += (check_expected_NULL(TESTLOG,43,(unur_mvstd_new( distr )))==UNUR_SUCCESS)?0:1;
128 n_tests_failed += (check_errorcode(TESTLOG,43,UNUR_ERR_DISTR_INVALID)==UNUR_SUCCESS)?0:1;
129 unur_distr_free(distr);
130 }
131 
132 
133 	/* timing */
134 	stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
135 
136 	/* test finished */
137 	test_ok &= (n_tests_failed) ? 0 : 1;
138 	(n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
139 
140 } /* end of test_new() */
141 
142 /*---------------------------------------------------------------------------*/
143 /* [reinit] */
144 
test_reinit(void)145 void test_reinit (void)
146 {
147         int n_tests_failed;          /* number of failed tests */
148 
149 	/* start test */
150 	printf("[reinit "); fflush(stdout);
151 	fprintf(TESTLOG,"\n[reinit]\n");
152 
153 	/* reset counter */
154 	n_tests_failed = 0;
155 
156 	/* set stop watch */
157 	stopwatch_lap(&watch);
158 
159 { /* exists */
160 UNUR_DISTR *distr = NULL;
161 UNUR_PAR   *par = NULL;
162 UNUR_GEN   *gen = NULL;
163    distr = unur_distr_multinormal(3,NULL,NULL);
164    par = unur_mvstd_new(distr);
165    gen = unur_init( par );
166 abort_if_NULL(TESTLOG, 67,    gen );
167 
168 
169 unur_reset_errno();
170 n_tests_failed += (check_expected_reinit(TESTLOG,71,(unur_reinit( gen )))==UNUR_SUCCESS)?0:1;
171 unur_distr_free(distr);
172 unur_free(gen);
173 }
174 
175 
176 	/* timing */
177 	stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
178 
179 	/* test finished */
180 	test_ok &= (n_tests_failed) ? 0 : 1;
181 	(n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
182 
183 } /* end of test_reinit() */
184 
185 /*---------------------------------------------------------------------------*/
186 /* [sample] */
187 
test_sample(void)188 void test_sample (void)
189 {
190         int n_tests_failed;          /* number of failed tests */
191 
192 	/* start test */
193 	printf("[sample "); fflush(stdout);
194 	fprintf(TESTLOG,"\n[sample]\n");
195 
196 	/* reset counter */
197 	n_tests_failed = 0;
198 
199 	/* set stop watch */
200 	stopwatch_lap(&watch);
201 
202 { /* compare clone */
203 UNUR_DISTR *distr = NULL;
204 UNUR_PAR   *par = NULL;
205 UNUR_GEN   *gen = NULL;
206    const int dim = 3;
207    double mean[] = {1.,2.,3.};
208    double covar[] = { 2., 2., 1.,   2., 4., 3.,   1., 3., 3. };
209    UNUR_GEN *clone;
210    distr = unur_distr_multinormal( dim, mean, covar );
211    par = NULL;
212    gen = NULL;
213 
214 
215 unur_reset_errno();
216 /* normal distribution */
217 par = unur_mvstd_new(distr);
218 gen = unur_init( par );
219 n_tests_failed += (compare_sequence_gen_start(TESTLOG,89,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
220 
221 unur_reset_errno();
222 /* clone */
223 clone = unur_gen_clone(gen);
224 unur_free(gen);
225 gen = clone;
226 n_tests_failed += (compare_sequence_gen(TESTLOG,95,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
227 unur_distr_free(distr);
228 unur_free(gen);
229 }
230 
231 
232 	/* timing */
233 	stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
234 
235 	/* test finished */
236 	test_ok &= (n_tests_failed) ? 0 : 1;
237 	(n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
238 
239 } /* end of test_sample() */
240 
241 /*---------------------------------------------------------------------------*/
242 /* [validate] */
243 
244 /*---------------------------------------------------------------------------*/
245 
246 /* [validate] */
247 
test_validate(void)248 void test_validate (void)
249 {
250 	UNUR_DISTR *distr[19];
251 	UNUR_PAR *par;
252 	UNUR_GEN *gen;
253 	int n_tests_failed;
254 	int rcode;
255 	double *darray;
256 	double fpm[10];
257 
258 	rcode = 0;
259 
260 	/* start test */
261 	printf("[validate "); fflush(stdout);
262 	fprintf(TESTLOG,"\n[validate]\n");
263 
264 	/* reset counter */
265 	n_tests_failed = 0;
266 
267 	/* set stop watch */
268 	stopwatch_lap(&watch);
269 
270 
271 /* distributions: 19 */
272 {
273 distr[0] = unur_distr_multinormal(3,NULL,NULL);
274 }
275 
276 {
277 double mean[]  = { -1., 2., -3. };
278 double covar[] = { 1., 0.8, 0.64,   0.8, 1., 0.8,   0.64, 0.8, 1. };
279 distr[1] = unur_distr_multinormal(3,mean,covar);
280 }
281 
282 {
283 #define dim (2)
284 int i;
285 double mean[dim], covar[dim*dim];
286 UNUR_DISTR *covar_distr;
287 UNUR_GEN *covar_gen;
288 UNUR_GEN *mean_gen;
289 covar_distr = unur_distr_correlation(dim);
290 covar_gen = unur_init(unur_mcorr_new(covar_distr));
291 mean_gen = unur_str2gen("normal(5,1)");
292 for (i=0; i<dim; i++)
293    mean[i] = unur_sample_cont(mean_gen);
294 do {
295    unur_sample_matr(covar_gen,covar);
296    distr[2] = unur_distr_multinormal(dim,mean,covar);
297 } while (distr[2]==NULL);
298 unur_distr_free(covar_distr);
299 unur_free(covar_gen);
300 unur_free(mean_gen);
301 #undef dim
302 }
303 
304 {
305 #define dim (3)
306 int i;
307 double mean[dim], covar[dim*dim];
308 UNUR_DISTR *covar_distr;
309 UNUR_GEN *covar_gen;
310 UNUR_GEN *mean_gen;
311 covar_distr = unur_distr_correlation(dim);
312 covar_gen = unur_init(unur_mcorr_new(covar_distr));
313 mean_gen = unur_str2gen("normal(5,1)");
314 for (i=0; i<dim; i++)
315    mean[i] = unur_sample_cont(mean_gen);
316 do {
317    unur_sample_matr(covar_gen,covar);
318    distr[3] = unur_distr_multinormal(dim,mean,covar);
319 } while (distr[3]==NULL);
320 unur_distr_free(covar_distr);
321 unur_free(covar_gen);
322 unur_free(mean_gen);
323 #undef dim
324 }
325 
326 {
327 #define dim (4)
328 int i;
329 double mean[dim], covar[dim*dim];
330 UNUR_DISTR *covar_distr;
331 UNUR_GEN *covar_gen;
332 UNUR_GEN *mean_gen;
333 covar_distr = unur_distr_correlation(dim);
334 covar_gen = unur_init(unur_mcorr_new(covar_distr));
335 mean_gen = unur_str2gen("normal(5,1)");
336 for (i=0; i<dim; i++)
337    mean[i] = unur_sample_cont(mean_gen);
338 do {
339    unur_sample_matr(covar_gen,covar);
340    distr[4] = unur_distr_multinormal(dim,mean,covar);
341 } while (distr[4]==NULL);
342 unur_distr_free(covar_distr);
343 unur_free(covar_gen);
344 unur_free(mean_gen);
345 #undef dim
346 }
347 
348 {
349 #define dim (5)
350 int i;
351 double mean[dim], covar[dim*dim];
352 UNUR_DISTR *covar_distr;
353 UNUR_GEN *covar_gen;
354 UNUR_GEN *mean_gen;
355 covar_distr = unur_distr_correlation(dim);
356 covar_gen = unur_init(unur_mcorr_new(covar_distr));
357 mean_gen = unur_str2gen("normal(5,1)");
358 for (i=0; i<dim; i++)
359    mean[i] = unur_sample_cont(mean_gen);
360 do {
361    unur_sample_matr(covar_gen,covar);
362    distr[5] = unur_distr_multinormal(dim,mean,covar);
363 } while (distr[5]==NULL);
364 unur_distr_free(covar_distr);
365 unur_free(covar_gen);
366 unur_free(mean_gen);
367 #undef dim
368 }
369 
370 {
371 #define dim (7)
372 int i;
373 double mean[dim], covar[dim*dim];
374 UNUR_DISTR *covar_distr;
375 UNUR_GEN *covar_gen;
376 UNUR_GEN *mean_gen;
377 covar_distr = unur_distr_correlation(dim);
378 covar_gen = unur_init(unur_mcorr_new(covar_distr));
379 mean_gen = unur_str2gen("normal(5,1)");
380 for (i=0; i<dim; i++)
381    mean[i] = unur_sample_cont(mean_gen);
382 do {
383    unur_sample_matr(covar_gen,covar);
384    distr[6] = unur_distr_multinormal(dim,mean,covar);
385 } while (distr[6]==NULL);
386 unur_distr_free(covar_distr);
387 unur_free(covar_gen);
388 unur_free(mean_gen);
389 #undef dim
390 }
391 
392 {
393 #define dim (10)
394 int i;
395 double mean[dim], covar[dim*dim];
396 UNUR_DISTR *covar_distr;
397 UNUR_GEN *covar_gen;
398 UNUR_GEN *mean_gen;
399 covar_distr = unur_distr_correlation(dim);
400 covar_gen = unur_init(unur_mcorr_new(covar_distr));
401 mean_gen = unur_str2gen("normal(5,1)");
402 for (i=0; i<dim; i++)
403    mean[i] = unur_sample_cont(mean_gen);
404 do {
405    unur_sample_matr(covar_gen,covar);
406    distr[7] = unur_distr_multinormal(dim,mean,covar);
407 } while (distr[7]==NULL);
408 unur_distr_free(covar_distr);
409 unur_free(covar_gen);
410 unur_free(mean_gen);
411 #undef dim
412 }
413 
414 {
415 #define dim (15)
416 int i;
417 double mean[dim], covar[dim*dim];
418 UNUR_DISTR *covar_distr;
419 UNUR_GEN *covar_gen;
420 UNUR_GEN *mean_gen;
421 covar_distr = unur_distr_correlation(dim);
422 covar_gen = unur_init(unur_mcorr_new(covar_distr));
423 mean_gen = unur_str2gen("normal(5,1)");
424 for (i=0; i<dim; i++)
425    mean[i] = unur_sample_cont(mean_gen);
426 do {
427    unur_sample_matr(covar_gen,covar);
428    distr[8] = unur_distr_multinormal(dim,mean,covar);
429 } while (distr[8]==NULL);
430 unur_distr_free(covar_distr);
431 unur_free(covar_gen);
432 unur_free(mean_gen);
433 #undef dim
434 }
435 
436 {
437 #define dim (20)
438 int i;
439 double mean[dim], covar[dim*dim];
440 UNUR_DISTR *covar_distr;
441 UNUR_GEN *covar_gen;
442 UNUR_GEN *mean_gen;
443 covar_distr = unur_distr_correlation(dim);
444 covar_gen = unur_init(unur_mcorr_new(covar_distr));
445 mean_gen = unur_str2gen("normal(5,1)");
446 for (i=0; i<dim; i++)
447    mean[i] = unur_sample_cont(mean_gen);
448 do {
449    unur_sample_matr(covar_gen,covar);
450    distr[9] = unur_distr_multinormal(dim,mean,covar);
451 } while (distr[9]==NULL);
452 unur_distr_free(covar_distr);
453 unur_free(covar_gen);
454 unur_free(mean_gen);
455 #undef dim
456 }
457 
458 {
459 #define dim (100)
460 int i;
461 double mean[dim], covar[dim*dim];
462 UNUR_DISTR *covar_distr;
463 UNUR_GEN *covar_gen;
464 UNUR_GEN *mean_gen;
465 covar_distr = unur_distr_correlation(dim);
466 covar_gen = unur_init(unur_mcorr_new(covar_distr));
467 mean_gen = unur_str2gen("normal(5,1)");
468 for (i=0; i<dim; i++)
469    mean[i] = unur_sample_cont(mean_gen);
470 do {
471    unur_sample_matr(covar_gen,covar);
472    distr[10] = unur_distr_multinormal(dim,mean,covar);
473 } while (distr[10]==NULL);
474 unur_distr_free(covar_distr);
475 unur_free(covar_gen);
476 unur_free(mean_gen);
477 #undef dim
478 }
479 
480 {
481 #define dim (100)
482 distr[11] = unur_distr_multinormal_ar1(dim,NULL,0.5);
483 #undef dim
484 }
485 
486 {
487 #define dim (100)
488 distr[12] = unur_distr_multinormal_ar1(dim,NULL,0.9);
489 #undef dim
490 }
491 
492 {
493 #define dim (100)
494 distr[13] = unur_distr_multinormal_ar1(dim,NULL,0.99);
495 #undef dim
496 }
497 
498 {
499 #define dim (100)
500 distr[14] = unur_distr_multinormal_ar1(dim,NULL,0.999);
501 #undef dim
502 }
503 
504 {
505 distr[15] = unur_distr_multinormal(1,NULL,NULL);
506 }
507 
508 {
509 #define dim (1)
510 int i;
511 double mean[dim], covar[dim*dim];
512 UNUR_DISTR *covar_distr;
513 UNUR_GEN *covar_gen;
514 UNUR_GEN *mean_gen;
515 covar_distr = unur_distr_correlation(dim);
516 covar_gen = unur_init(unur_mcorr_new(covar_distr));
517 mean_gen = unur_str2gen("normal(5,1)");
518 for (i=0; i<dim; i++)
519    mean[i] = unur_sample_cont(mean_gen);
520 do {
521    unur_sample_matr(covar_gen,covar);
522    distr[16] = unur_distr_multinormal(dim,mean,covar);
523 } while (distr[16]==NULL);
524 unur_distr_free(covar_distr);
525 unur_free(covar_gen);
526 unur_free(mean_gen);
527 #undef dim
528 }
529 
530 {
531 double ll[3] = {0.,0.,0.};
532 double ru[3] = {UNUR_INFINITY,UNUR_INFINITY,UNUR_INFINITY};
533 distr[17] = unur_distr_multinormal(3,NULL,NULL);
534 unur_distr_cvec_set_domain_rect(distr[17],ll,ru);
535 }
536 
537 {
538 distr[18] = unur_distr_multicauchy(3,NULL,NULL);
539 }
540 
541 	/* timing */
542 	stopwatch_print(TESTLOG,"\n<*>setup time = %.3f ms\n", stopwatch_lap(&watch));
543 
544 	printf("\n(chi^2) "); fflush(stdout);
545 
546 /* chi^2 tests: 38 */
547 
548 	unur_set_default_debug(~UNUR_DEBUG_SAMPLE);
549 	fprintf( TESTLOG,"\nChi^2 Test:\n");
550 
551 /* distribution [0] */
552 
553 	if(TRUE) {
554 	unur_reset_errno();
555 	do {
556 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[0]);
557 par = unur_mvstd_new(distr_localcopy);
558 	gen = unur_init(par);
559 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[0],'+');
560 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
561 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
562 	unur_free(gen);
563 	unur_distr_free(distr_localcopy);
564 	} while (0);
565 	}
566 
567 	if(TRUE) {
568 	unur_reset_errno();
569 	do {
570 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[0]);
571 { UNUR_DISTR *dg =NULL;
572 double mean[]  = { -1., 2., -3. };
573 double covar[] = { 1., 0.8, 0.64,   0.8, 1., 0.8,   0.64, 0.8, 1. };
574 par = unur_mvstd_new(distr_localcopy);
575 	gen = unur_init(par);
576 	if (gen) {
577 dg = unur_get_distr(gen);
578 unur_distr_cvec_set_mean(dg,mean);
579 unur_distr_cvec_set_covar(dg,covar);
580 unur_reinit(gen); }
581 	}
582 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[0],'+');
583 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
584 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
585 	unur_free(gen);
586 	unur_distr_free(distr_localcopy);
587 	} while (0);
588 	}
589 
590 /* distribution [1] */
591 
592 	if(TRUE) {
593 	unur_reset_errno();
594 	do {
595 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[1]);
596 par = unur_mvstd_new(distr_localcopy);
597 	gen = unur_init(par);
598 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[1],'+');
599 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
600 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
601 	unur_free(gen);
602 	unur_distr_free(distr_localcopy);
603 	} while (0);
604 	}
605 
606 	if(TRUE) {
607 	unur_reset_errno();
608 	do {
609 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[1]);
610 { UNUR_DISTR *dg =NULL;
611 double mean[]  = { -1., 2., -3. };
612 double covar[] = { 1., 0.8, 0.64,   0.8, 1., 0.8,   0.64, 0.8, 1. };
613 par = unur_mvstd_new(distr_localcopy);
614 	gen = unur_init(par);
615 	if (gen) {
616 dg = unur_get_distr(gen);
617 unur_distr_cvec_set_mean(dg,mean);
618 unur_distr_cvec_set_covar(dg,covar);
619 unur_reinit(gen); }
620 	}
621 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[1],'+');
622 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
623 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
624 	unur_free(gen);
625 	unur_distr_free(distr_localcopy);
626 	} while (0);
627 	}
628 
629 /* distribution [2] */
630 
631 	if(TRUE) {
632 	unur_reset_errno();
633 	do {
634 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[2]);
635 par = unur_mvstd_new(distr_localcopy);
636 	gen = unur_init(par);
637 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[2],'+');
638 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
639 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
640 	unur_free(gen);
641 	unur_distr_free(distr_localcopy);
642 	} while (0);
643 	}
644 
645 	if(TRUE) {
646 	printf("."); fflush(stdout);
647 	}
648 
649 /* distribution [3] */
650 
651 	if(TRUE) {
652 	unur_reset_errno();
653 	do {
654 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[3]);
655 par = unur_mvstd_new(distr_localcopy);
656 	gen = unur_init(par);
657 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[3],'+');
658 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
659 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
660 	unur_free(gen);
661 	unur_distr_free(distr_localcopy);
662 	} while (0);
663 	}
664 
665 	if(TRUE) {
666 	unur_reset_errno();
667 	do {
668 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[3]);
669 { UNUR_DISTR *dg =NULL;
670 double mean[]  = { -1., 2., -3. };
671 double covar[] = { 1., 0.8, 0.64,   0.8, 1., 0.8,   0.64, 0.8, 1. };
672 par = unur_mvstd_new(distr_localcopy);
673 	gen = unur_init(par);
674 	if (gen) {
675 dg = unur_get_distr(gen);
676 unur_distr_cvec_set_mean(dg,mean);
677 unur_distr_cvec_set_covar(dg,covar);
678 unur_reinit(gen); }
679 	}
680 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[3],'+');
681 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
682 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
683 	unur_free(gen);
684 	unur_distr_free(distr_localcopy);
685 	} while (0);
686 	}
687 
688 /* distribution [4] */
689 
690 	if(TRUE) {
691 	unur_reset_errno();
692 	do {
693 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[4]);
694 par = unur_mvstd_new(distr_localcopy);
695 	gen = unur_init(par);
696 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[4],'+');
697 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
698 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
699 	unur_free(gen);
700 	unur_distr_free(distr_localcopy);
701 	} while (0);
702 	}
703 
704 	if(TRUE) {
705 	printf("."); fflush(stdout);
706 	}
707 
708 /* distribution [5] */
709 
710 	if(TRUE) {
711 	unur_reset_errno();
712 	do {
713 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[5]);
714 par = unur_mvstd_new(distr_localcopy);
715 	gen = unur_init(par);
716 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[5],'+');
717 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
718 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
719 	unur_free(gen);
720 	unur_distr_free(distr_localcopy);
721 	} while (0);
722 	}
723 
724 	if(TRUE) {
725 	printf("."); fflush(stdout);
726 	}
727 
728 /* distribution [6] */
729 
730 	if(TRUE) {
731 	unur_reset_errno();
732 	do {
733 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[6]);
734 par = unur_mvstd_new(distr_localcopy);
735 	gen = unur_init(par);
736 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[6],'+');
737 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
738 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
739 	unur_free(gen);
740 	unur_distr_free(distr_localcopy);
741 	} while (0);
742 	}
743 
744 	if(TRUE) {
745 	printf("."); fflush(stdout);
746 	}
747 
748 /* distribution [7] */
749 
750 	if(TRUE) {
751 	unur_reset_errno();
752 	do {
753 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[7]);
754 par = unur_mvstd_new(distr_localcopy);
755 	gen = unur_init(par);
756 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[7],'+');
757 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
758 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
759 	unur_free(gen);
760 	unur_distr_free(distr_localcopy);
761 	} while (0);
762 	}
763 
764 	if(TRUE) {
765 	printf("."); fflush(stdout);
766 	}
767 
768 /* distribution [8] */
769 
770 	if(TRUE) {
771 	unur_reset_errno();
772 	do {
773 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[8]);
774 par = unur_mvstd_new(distr_localcopy);
775 	gen = unur_init(par);
776 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[8],'+');
777 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
778 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
779 	unur_free(gen);
780 	unur_distr_free(distr_localcopy);
781 	} while (0);
782 	}
783 
784 	if(TRUE) {
785 	printf("."); fflush(stdout);
786 	}
787 
788 /* distribution [9] */
789 
790 	if(TRUE) {
791 	unur_reset_errno();
792 	do {
793 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[9]);
794 par = unur_mvstd_new(distr_localcopy);
795 	gen = unur_init(par);
796 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[9],'+');
797 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
798 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
799 	unur_free(gen);
800 	unur_distr_free(distr_localcopy);
801 	} while (0);
802 	}
803 
804 	if(TRUE) {
805 	printf("."); fflush(stdout);
806 	}
807 
808 /* distribution [10] */
809 
810 	if(TRUE) {
811 	unur_reset_errno();
812 	do {
813 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[10]);
814 par = unur_mvstd_new(distr_localcopy);
815 	gen = unur_init(par);
816 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[10],'+');
817 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
818 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
819 	unur_free(gen);
820 	unur_distr_free(distr_localcopy);
821 	} while (0);
822 	}
823 
824 	if(TRUE) {
825 	printf("."); fflush(stdout);
826 	}
827 
828 /* distribution [11] */
829 
830 	if(fullcheck) {
831 	unur_reset_errno();
832 	do {
833 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[11]);
834 par = unur_mvstd_new(distr_localcopy);
835 	gen = unur_init(par);
836 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[11],'+');
837 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
838 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
839 	unur_free(gen);
840 	unur_distr_free(distr_localcopy);
841 	} while (0);
842 	}
843 
844 	if(fullcheck) {
845 	printf("."); fflush(stdout);
846 	}
847 
848 /* distribution [12] */
849 
850 	if(TRUE) {
851 	unur_reset_errno();
852 	do {
853 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[12]);
854 par = unur_mvstd_new(distr_localcopy);
855 	gen = unur_init(par);
856 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[12],'+');
857 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
858 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
859 	unur_free(gen);
860 	unur_distr_free(distr_localcopy);
861 	} while (0);
862 	}
863 
864 	if(TRUE) {
865 	printf("."); fflush(stdout);
866 	}
867 
868 /* distribution [13] */
869 
870 	if(fullcheck) {
871 	unur_reset_errno();
872 	do {
873 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[13]);
874 par = unur_mvstd_new(distr_localcopy);
875 	gen = unur_init(par);
876 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[13],'+');
877 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
878 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
879 	unur_free(gen);
880 	unur_distr_free(distr_localcopy);
881 	} while (0);
882 	}
883 
884 	if(fullcheck) {
885 	printf("."); fflush(stdout);
886 	}
887 
888 /* distribution [14] */
889 
890 	if(fullcheck) {
891 	unur_reset_errno();
892 	do {
893 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[14]);
894 par = unur_mvstd_new(distr_localcopy);
895 	gen = unur_init(par);
896 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[14],'+');
897 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
898 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
899 	unur_free(gen);
900 	unur_distr_free(distr_localcopy);
901 	} while (0);
902 	}
903 
904 	if(fullcheck) {
905 	printf("."); fflush(stdout);
906 	}
907 
908 /* distribution [15] */
909 
910 	if(TRUE) {
911 	unur_reset_errno();
912 	do {
913 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[15]);
914 par = unur_mvstd_new(distr_localcopy);
915 	gen = unur_init(par);
916 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[15],'+');
917 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
918 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
919 	unur_free(gen);
920 	unur_distr_free(distr_localcopy);
921 	} while (0);
922 	}
923 
924 	if(TRUE) {
925 	printf("."); fflush(stdout);
926 	}
927 
928 /* distribution [16] */
929 
930 	if(fullcheck) {
931 	unur_reset_errno();
932 	do {
933 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[16]);
934 par = unur_mvstd_new(distr_localcopy);
935 	gen = unur_init(par);
936 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[16],'+');
937 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
938 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
939 	unur_free(gen);
940 	unur_distr_free(distr_localcopy);
941 	} while (0);
942 	}
943 
944 	if(fullcheck) {
945 	printf("."); fflush(stdout);
946 	}
947 
948 /* distribution [17] */
949 
950 	if(TRUE) {
951 	unur_reset_errno();
952 	do {
953 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[17]);
954 par = unur_mvstd_new(distr_localcopy);
955 	gen = unur_init(par);
956 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[17],'0');
957 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
958 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
959 	unur_free(gen);
960 	unur_distr_free(distr_localcopy);
961 	} while (0);
962 	}
963 
964 	if(TRUE) {
965 	printf("."); fflush(stdout);
966 	}
967 
968 /* distribution [18] */
969 
970 	if(TRUE) {
971 	unur_reset_errno();
972 	do {
973 	UNUR_DISTR *distr_localcopy = unur_distr_clone(distr[18]);
974 par = unur_mvstd_new(distr_localcopy);
975 	gen = unur_init(par);
976 	rcode = run_validate_chi2(TESTLOG,0,gen,distr[18],'0');
977 	n_tests_failed += (rcode==UNUR_SUCCESS)?0:1;
978 	n_tests_failed += (rcode==UNUR_FAILURE)?1000:0;
979 	unur_free(gen);
980 	unur_distr_free(distr_localcopy);
981 	} while (0);
982 	}
983 
984 	if(TRUE) {
985 	printf("."); fflush(stdout);
986 	}
987 
988 	/* timing */
989 	stopwatch_print(TESTLOG,"\n<*>time = %.0f ms\n", stopwatch_lap(&watch));
990 
991 
992 /* free distributions */
993 	unur_distr_free(distr[0]);
994 	unur_distr_free(distr[1]);
995 	unur_distr_free(distr[2]);
996 	unur_distr_free(distr[3]);
997 	unur_distr_free(distr[4]);
998 	unur_distr_free(distr[5]);
999 	unur_distr_free(distr[6]);
1000 	unur_distr_free(distr[7]);
1001 	unur_distr_free(distr[8]);
1002 	unur_distr_free(distr[9]);
1003 	unur_distr_free(distr[10]);
1004 	unur_distr_free(distr[11]);
1005 	unur_distr_free(distr[12]);
1006 	unur_distr_free(distr[13]);
1007 	unur_distr_free(distr[14]);
1008 	unur_distr_free(distr[15]);
1009 	unur_distr_free(distr[16]);
1010 	unur_distr_free(distr[17]);
1011 	unur_distr_free(distr[18]);
1012 
1013 	/* test finished */
1014 	test_ok &= (n_tests_failed>CHI2_FAILURES_TOLERATED) ? 0 : 1;
1015 	/* we accept CHI2_FAILURES_TOLERATED failures */
1016 	(n_tests_failed>CHI2_FAILURES_TOLERATED) ? printf(" ==> failed] ") : printf(" ==> ok] ");
1017 
1018 	/* prevent compiler from making useless annoying warnings */
1019 	distr[0] = NULL;
1020 	par = NULL;
1021 	gen = NULL;
1022 	darray = NULL;
1023 	fpm[0] = 0.;
1024 
1025 } /* end of test_validate */
1026 
1027 
1028 /*---------------------------------------------------------------------------*/
1029 /* run generator in verifying mode */
1030 
run_verify_generator(FILE * LOG,int line,UNUR_PAR * par)1031 void run_verify_generator( FILE *LOG, int line, UNUR_PAR *par )
1032 {
1033 	UNUR_GEN *gen;
1034 	int i;
1035 
1036 	/* switch to verifying mode */
1037 	unur_mvstd_set_verify(par,1);
1038 
1039 	/* initialize generator */
1040 	gen = unur_init( par ); abort_if_NULL(LOG, line, gen);
1041 
1042 	/* run generator */
1043 	for (i=0; i<VIOLATE_SAMPLE_SIZE; i++)
1044 		unur_sample_cont(gen);
1045 
1046 	/* destroy generator */
1047 	unur_free(gen);
1048 
1049 } /* end of run_verify_generator() */
1050 
unur_mvstd_set_verify(UNUR_PAR * par ATTRIBUTE__UNUSED,int verify ATTRIBUTE__UNUSED)1051 int unur_mvstd_set_verify(UNUR_PAR *par ATTRIBUTE__UNUSED, int verify ATTRIBUTE__UNUSED) {return 0;}
1052 
1053 /*---------------------------------------------------------------------------*/
1054 
main(void)1055 int main(void)
1056 {
1057         unsigned long seed;
1058 	char *str_seed, *str_tail;
1059 
1060 	/* start stop watch */
1061 	stopwatch_init();
1062 	stopwatch_start(&watch);
1063 
1064         /* open log file for unuran and set output stream for unuran messages */
1065         UNURANLOG = fopen( "t_mvstd_unuran.log","w" );
1066         abort_if_NULL( stderr,-1, UNURANLOG );
1067         unur_set_stream( UNURANLOG );
1068 
1069         /* open log file for testing */
1070 	TESTLOG = fopen( "t_mvstd_test.log","w" );
1071 	abort_if_NULL( stderr,-1, TESTLOG );
1072 
1073         /* seed for uniform generators */
1074 
1075 	/* seed set by environment */
1076 	str_seed = getenv("SEED");
1077 
1078 	if (str_seed != NULL) {
1079 	    seed = strtol(str_seed, &str_tail, 10);
1080 	    if (seed == 0u)
1081 		seed = 299563;
1082 	}
1083 	else {
1084 #ifdef SEED
1085 	    seed = SEED;
1086 #else
1087 	    seed = 299563;
1088 #endif
1089 	}
1090 
1091         /* seed build-in uniform generators */
1092         unur_urng_MRG31k3p_seed(NULL,seed);
1093         unur_urng_fish_seed(NULL,seed);
1094 	unur_urng_mstd_seed(NULL,seed);
1095 
1096 	/* seed uniform random number generator */
1097 #ifdef UNUR_URNG_UNURAN
1098 #  ifdef UNUR_URNG_DEFAULT_RNGSTREAM
1099 	{
1100 	        unsigned long sa[6];
1101 	        int i;
1102 	        for (i=0; i<6; i++) sa[i] = seed;
1103                 RngStream_SetPackageSeed(sa);
1104         }
1105 #  else
1106 	if (unur_urng_seed(NULL,seed) != UNUR_SUCCESS) {
1107 	        fprintf(stderr,"WARNING: Seed could not be set at random\n");
1108                 seed = ~0u;
1109 	}
1110 #  endif  /* UNUR_URNG_DEFAULT_RNGSTREAM */
1111 #endif  /* UNUR_URNG_UNURAN */
1112 
1113 	/* set default debugging flag */
1114 	unur_set_default_debug(UNUR_DEBUG_ALL);
1115 
1116         /* detect required check mode */
1117         fullcheck = (getenv("UNURANFULLCHECK")==NULL) ? FALSE : TRUE;
1118 
1119 	/* write header into log file */
1120         print_test_log_header( TESTLOG, seed, fullcheck );
1121 
1122 	/* set timer for sending SIGALRM signal */
1123 	set_alarm(TESTLOG);
1124 
1125 	/* start test */
1126 	printf("mvstd: ");
1127 
1128 	/* run tests */
1129 test_new();
1130 test_reinit();
1131 test_sample();
1132 test_validate();
1133 
1134 
1135 	/* test finished */
1136 	printf("\n");  fflush(stdout);
1137 
1138 	/* close log files */
1139 	fprintf(TESTLOG,"\n====================================================\n\n");
1140 	if (test_ok)
1141 		fprintf(TESTLOG,"All tests PASSED.\n");
1142 	else
1143 		fprintf(TESTLOG,"Test(s) FAILED.\n");
1144 
1145 	/* timing */
1146 	stopwatch_print(TESTLOG,"\n<*>total time = %.0f ms\n\n", stopwatch_stop(&watch));
1147 
1148 	fclose(UNURANLOG);
1149 	fclose(TESTLOG);
1150 
1151 	/* free memory */
1152 	compare_free_memory();
1153 	unur_urng_free(unur_get_default_urng());
1154 	unur_urng_free(unur_get_default_urng_aux());
1155 
1156 	/* exit */
1157 	exit( (test_ok) ? EXIT_SUCCESS : EXIT_FAILURE );
1158 
1159 } /* end of main */
1160 
1161