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 STRINGPARSER
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_stringparser_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 int unur_ssr_set_pedantic( struct unur_par *par, int pedantic );
60 
61 #define COMPARE_SAMPLE_SIZE   (10000)
62 #define VIOLATE_SAMPLE_SIZE   (20)
63 
64 
65 
66 
67 /*---------------------------------------------------------------------------*/
68 
69 #ifndef CHI2_FAILURES_TOLERATED
70 #  define CHI2_FAILURES_TOLERATED DEFAULT_CHI2_FAILURES_TOLERATED
71 #endif
72 
73 /*---------------------------------------------------------------------------*/
74 /* [verbatim] */
75 
76 
77 
78 
79 /*---------------------------------------------------------------------------*/
80 /* [new] */
81 
test_new(void)82 void test_new (void)
83 {
84         int n_tests_failed;          /* number of failed tests */
85 
86 	/* start test */
87 	printf("[new "); fflush(stdout);
88 	fprintf(TESTLOG,"\n[new]\n");
89 
90 	/* reset counter */
91 	n_tests_failed = 0;
92 
93 	/* set stop watch */
94 	stopwatch_lap(&watch);
95 
96 
97 	/* timing */
98 	stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
99 
100 	/* test finished */
101 	test_ok &= (n_tests_failed) ? 0 : 1;
102 	(n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
103 
104 } /* end of test_new() */
105 
106 /*---------------------------------------------------------------------------*/
107 /* [init] */
108 
test_init(void)109 void test_init (void)
110 {
111         int n_tests_failed;          /* number of failed tests */
112 
113 	/* start test */
114 	printf("[init "); fflush(stdout);
115 	fprintf(TESTLOG,"\n[init]\n");
116 
117 	/* reset counter */
118 	n_tests_failed = 0;
119 
120 	/* set stop watch */
121 	stopwatch_lap(&watch);
122 
123 { /* invalid NULL ptr */
124 UNUR_DISTR *distr = NULL;
125 UNUR_GEN   *gen = NULL;
126    distr = NULL;
127    gen = NULL;
128 
129 
130 unur_reset_errno();
131 n_tests_failed += (check_expected_NULL(TESTLOG,46,(gen = unur_str2gen( NULL )))==UNUR_SUCCESS)?0:1;
132 n_tests_failed += (check_errorcode(TESTLOG,46,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
133 
134 unur_reset_errno();
135 n_tests_failed += (check_expected_NULL(TESTLOG,49,(distr = unur_str2distr( NULL )))==UNUR_SUCCESS)?0:1;
136 n_tests_failed += (check_errorcode(TESTLOG,49,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
137 
138 unur_reset_errno();
139 n_tests_failed += (check_expected_NULL(TESTLOG,52,(gen = unur_makegen_ssu(NULL,NULL,NULL)))==UNUR_SUCCESS)?0:1;
140 n_tests_failed += (check_errorcode(TESTLOG,52,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
141 unur_distr_free(distr);
142 unur_free(gen);
143 }
144 
145 { /* invalid distribution block */
146 UNUR_GEN   *gen = NULL;
147    gen = NULL;
148 
149 
150 unur_reset_errno();
151 n_tests_failed += (check_expected_NULL(TESTLOG,59,(gen = unur_str2gen( "xxxx" )))==UNUR_SUCCESS)?0:1;
152 n_tests_failed += (check_errorcode(TESTLOG,59,UNUR_ERR_STR_UNKNOWN)==UNUR_SUCCESS)?0:1;
153 
154 unur_reset_errno();
155 unur_free(gen); gen = NULL;
156 n_tests_failed += (check_expected_NULL(TESTLOG,63,(gen = unur_str2gen( "method = xxxx" )))==UNUR_SUCCESS)?0:1;
157 n_tests_failed += (check_errorcode(TESTLOG,63,UNUR_ERR_STR_SYNTAX)==UNUR_SUCCESS)?0:1;
158 
159 unur_reset_errno();
160 unur_free(gen); gen = NULL;
161 n_tests_failed += (check_expected_NULL(TESTLOG,67,(gen = unur_str2gen( "normal; xxxx=1" )))==UNUR_SUCCESS)?0:1;
162 n_tests_failed += (check_errorcode(TESTLOG,67,UNUR_ERR_STR_UNKNOWN)==UNUR_SUCCESS)?0:1;
163 
164 unur_reset_errno();
165 unur_free(gen); gen = NULL;
166 n_tests_failed += (check_expected_NULL(TESTLOG,71,(gen = unur_str2gen( "normal; pv=(1,2,3)" )))==UNUR_SUCCESS)?0:1;
167 n_tests_failed += (check_errorcode(TESTLOG,71,UNUR_ERR_STR_UNKNOWN)==UNUR_SUCCESS)?0:1;
168 
169 unur_reset_errno();
170 unur_free(gen); gen = NULL;
171 n_tests_failed += (check_expected_NULL(TESTLOG,75,(gen = unur_str2gen( "normal,(1,2)" )))==UNUR_SUCCESS)?0:1;
172 n_tests_failed += (check_errorcode(TESTLOG,75,UNUR_ERR_STR_UNKNOWN)==UNUR_SUCCESS)?0:1;
173 
174 unur_reset_errno();
175 unur_free(gen); gen = NULL;
176 n_tests_failed += (check_expected_NULL(TESTLOG,79,(gen = unur_str2gen( "beta" )))==UNUR_SUCCESS)?0:1;
177 n_tests_failed += (check_errorcode(TESTLOG,79,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
178 
179 unur_reset_errno();
180 unur_free(gen); gen = NULL;
181 n_tests_failed += (check_expected_NULL(TESTLOG,83,(gen = unur_str2gen( "beta()" )))==UNUR_SUCCESS)?0:1;
182 n_tests_failed += (check_errorcode(TESTLOG,83,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
183 
184 unur_reset_errno();
185 unur_free(gen); gen = NULL;
186 n_tests_failed += (check_expected_NULL(TESTLOG,87,(gen = unur_str2gen( "beta(1)" )))==UNUR_SUCCESS)?0:1;
187 n_tests_failed += (check_errorcode(TESTLOG,87,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
188 
189 unur_reset_errno();
190 unur_free(gen); gen = NULL;
191 gen = unur_str2gen( "beta(1,2,3)" );
192 n_tests_failed += (check_errorcode(TESTLOG,91,UNUR_ERR_DISTR_NPARAMS)==UNUR_SUCCESS)?0:1;
193 
194 unur_reset_errno();
195 unur_free(gen); gen = NULL;
196 gen = unur_str2gen( "beta(1,2,3,4,5)" );
197 n_tests_failed += (check_errorcode(TESTLOG,95,UNUR_ERR_DISTR_NPARAMS)==UNUR_SUCCESS)?0:1;
198 
199 unur_reset_errno();
200 unur_free(gen); gen = NULL;
201 n_tests_failed += (check_expected_NULL(TESTLOG,99,(gen = unur_str2gen( "gamma(-0.5)" )))==UNUR_SUCCESS)?0:1;
202 n_tests_failed += (check_errorcode(TESTLOG,99,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
203 
204 unur_reset_errno();
205 unur_free(gen); gen = NULL;
206 n_tests_failed += (check_expected_NULL(TESTLOG,103,(gen = unur_str2gen( "normal(); domain" )))==UNUR_SUCCESS)?0:1;
207 n_tests_failed += (check_errorcode(TESTLOG,103,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
208 unur_free(gen);
209 }
210 
211 { /* invalid other block */
212 UNUR_GEN   *gen = NULL;
213    gen = NULL;
214 
215 
216 unur_reset_errno();
217 n_tests_failed += (check_expected_NULL(TESTLOG,110,(gen = unur_str2gen( "normal() & xxxx = arou" )))==UNUR_SUCCESS)?0:1;
218 n_tests_failed += (check_errorcode(TESTLOG,110,UNUR_ERR_STR_UNKNOWN)==UNUR_SUCCESS)?0:1;
219 
220 unur_reset_errno();
221 unur_free(gen); gen = NULL;
222 n_tests_failed += (check_expected_NULL(TESTLOG,114,(gen = unur_str2gen( "normal() & distr=gamma(2)" )))==UNUR_SUCCESS)?0:1;
223 n_tests_failed += (check_errorcode(TESTLOG,114,UNUR_ERR_STR_UNKNOWN)==UNUR_SUCCESS)?0:1;
224 unur_free(gen);
225 }
226 
227 { /* invalid method block */
228 UNUR_GEN   *gen = NULL;
229    gen = NULL;
230 
231 
232 unur_reset_errno();
233 gen = unur_str2gen( "normal() & method = arou; c = 0" );
234 n_tests_failed += (check_errorcode(TESTLOG,121,UNUR_ERR_STR_UNKNOWN)==UNUR_SUCCESS)?0:1;
235 
236 unur_reset_errno();
237 unur_free(gen); gen = NULL;
238 n_tests_failed += (check_expected_NULL(TESTLOG,125,(gen = unur_str2gen( "normal() & method = xxx" )))==UNUR_SUCCESS)?0:1;
239 n_tests_failed += (check_errorcode(TESTLOG,125,UNUR_ERR_NULL)==UNUR_SUCCESS)?0:1;
240 unur_free(gen);
241 }
242 
243 { /* invalid urng block */
244 UNUR_GEN   *gen = NULL;
245     gen = NULL;
246 
247 
248 unur_reset_errno();
249 gen = unur_str2gen( "normal & urng = xxx" );
250 n_tests_failed += (check_errorcode(TESTLOG,132,UNUR_ERR_STR)==UNUR_SUCCESS)?0:1;
251 
252 unur_reset_errno();
253 unur_free(gen); gen = NULL;
254 #ifdef UNURAN_SUPPORTS_PRNG
255 gen = unur_str2gen( "normal & urng = mt19937(123); xxx = 1" );
256 n_tests_failed += (check_errorcode(TESTLOG,137,UNUR_ERR_STR_UNKNOWN)==UNUR_SUCCESS)?0:1;
257 #endif
258 unur_free(gen);
259 }
260 
261 { /* invalid data */
262 UNUR_GEN   *gen = NULL;
263    gen = NULL;
264 
265 
266 unur_reset_errno();
267 n_tests_failed += (check_expected_NULL(TESTLOG,146,(gen = unur_str2gen( "gamma(0.5) & method = tdr" )))==UNUR_SUCCESS)?0:1;
268 n_tests_failed += (check_errorcode(TESTLOG,146,UNUR_ERR_GEN_DATA)==UNUR_SUCCESS)?0:1;
269 unur_free(gen);
270 }
271 
272 { /* invalid data */
273 UNUR_DISTR *distr = NULL;
274 UNUR_PAR   *par = NULL;
275 UNUR_GEN   *gen = NULL;
276    struct unur_slist *mlist = NULL;
277    distr = NULL;
278    par = NULL;
279    gen = NULL;
280 
281 distr = unur_str2distr("normal()");
282 par = _unur_str2par(distr, "tdr", &mlist);
283 gen = unur_init(par);
284 _unur_slist_free(mlist);
285 unur_distr_free(distr);
286 unur_free(gen);
287 }
288 
289 { /* invalid distribution block */
290 UNUR_DISTR *distr = NULL;
291    distr = NULL;
292 
293 
294 unur_reset_errno();
295 n_tests_failed += (check_expected_NULL(TESTLOG,169,(distr = unur_str2distr("cont; pdf='exp'")))==UNUR_SUCCESS)?0:1;
296 n_tests_failed += (check_errorcode(TESTLOG,169,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
297 
298 unur_reset_errno();
299 n_tests_failed += (check_expected_NULL(TESTLOG,174,(distr = unur_str2distr("cont; pdf='abc(x)'")))==UNUR_SUCCESS)?0:1;
300 n_tests_failed += (check_errorcode(TESTLOG,174,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
301 
302 unur_reset_errno();
303 n_tests_failed += (check_expected_NULL(TESTLOG,179,(distr = unur_str2distr("cont; pdf='exp(x*y)'")))==UNUR_SUCCESS)?0:1;
304 n_tests_failed += (check_errorcode(TESTLOG,179,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
305 
306 unur_reset_errno();
307 n_tests_failed += (check_expected_NULL(TESTLOG,183,(distr = unur_str2distr("cont; pdf='exp(x'")))==UNUR_SUCCESS)?0:1;
308 n_tests_failed += (check_errorcode(TESTLOG,183,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
309 
310 unur_reset_errno();
311 n_tests_failed += (check_expected_NULL(TESTLOG,186,(distr = unur_str2distr("cont; pdf='exp((x)'")))==UNUR_SUCCESS)?0:1;
312 n_tests_failed += (check_errorcode(TESTLOG,186,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
313 
314 unur_reset_errno();
315 n_tests_failed += (check_expected_NULL(TESTLOG,189,(distr = unur_str2distr("cont; pdf='exp(x))'")))==UNUR_SUCCESS)?0:1;
316 n_tests_failed += (check_errorcode(TESTLOG,189,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
317 
318 unur_reset_errno();
319 n_tests_failed += (check_expected_NULL(TESTLOG,193,(distr = unur_str2distr("cont; pdf='x^'")))==UNUR_SUCCESS)?0:1;
320 n_tests_failed += (check_errorcode(TESTLOG,193,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
321 
322 unur_reset_errno();
323 n_tests_failed += (check_expected_NULL(TESTLOG,197,(distr = unur_str2distr("cont; pdf='exp(x)x'")))==UNUR_SUCCESS)?0:1;
324 n_tests_failed += (check_errorcode(TESTLOG,197,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
325 
326 unur_reset_errno();
327 n_tests_failed += (check_expected_NULL(TESTLOG,200,(distr = unur_str2distr("cont; pdf='2x'")))==UNUR_SUCCESS)?0:1;
328 n_tests_failed += (check_errorcode(TESTLOG,200,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
329 
330 unur_reset_errno();
331 n_tests_failed += (check_expected_NULL(TESTLOG,203,(distr = unur_str2distr("cont; pdf='x***2'")))==UNUR_SUCCESS)?0:1;
332 n_tests_failed += (check_errorcode(TESTLOG,203,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
333 
334 unur_reset_errno();
335 n_tests_failed += (check_expected_NULL(TESTLOG,206,(distr = unur_str2distr("cont; pdf='x*exp(x^(x*y))'")))==UNUR_SUCCESS)?0:1;
336 n_tests_failed += (check_errorcode(TESTLOG,206,UNUR_ERR_STR_INVALID)==UNUR_SUCCESS)?0:1;
337 unur_distr_free(distr);
338 }
339 
340 
341 	/* timing */
342 	stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
343 
344 	/* test finished */
345 	test_ok &= (n_tests_failed) ? 0 : 1;
346 	(n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
347 
348 } /* end of test_init() */
349 
350 /*---------------------------------------------------------------------------*/
351 /* [sample] */
352 
test_sample(void)353 void test_sample (void)
354 {
355         int n_tests_failed;          /* number of failed tests */
356 
357 	/* start test */
358 	printf("[sample "); fflush(stdout);
359 	fprintf(TESTLOG,"\n[sample]\n");
360 
361 	/* reset counter */
362 	n_tests_failed = 0;
363 
364 	/* set stop watch */
365 	stopwatch_lap(&watch);
366 
367 { /* compare function parser - cont */
368 UNUR_DISTR *distr = NULL;
369 UNUR_PAR   *par = NULL;
370 UNUR_GEN   *gen = NULL;
371    double fpm[10];
372    distr = NULL;
373    par = NULL;
374    gen = NULL;
375 
376 
377 unur_reset_errno();
378 distr = unur_distr_normal(NULL,0);
379 par = unur_srou_new(distr);
380 gen = unur_init(par);
381 n_tests_failed += (compare_sequence_gen_start(TESTLOG,232,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
382 
383 unur_reset_errno();
384 unur_free(gen); gen = NULL;
385 unur_distr_free(distr); distr = NULL;
386 gen = unur_str2gen( "cont; pdf = \"(1/sqrt(2*pi)*exp(-x^2/2))\"; mode = 0; pdfarea = 1 & \
387 	             method = srou" );
388 n_tests_failed += (compare_sequence_gen(TESTLOG,238,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
389 
390 unur_reset_errno();
391 unur_free(gen); gen = NULL;
392 unur_distr_free(distr); distr = NULL;
393 gen = unur_str2gen( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1 & \
394 	             method = srou" );
395 n_tests_failed += (compare_sequence_gen(TESTLOG,244,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
396 
397 unur_reset_errno();
398 unur_free(gen); gen = NULL;
399 unur_distr_free(distr); distr = NULL;
400 gen = unur_makegen_ssu( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1", \
401 	             "method = srou", NULL );
402 n_tests_failed += (compare_sequence_gen(TESTLOG,250,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
403 
404 unur_reset_errno();
405 unur_free(gen); gen = NULL;
406 unur_distr_free(distr); distr = NULL;
407 gen = unur_makegen_ssu( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1", \
408 	             "srou", NULL );
409 n_tests_failed += (compare_sequence_gen(TESTLOG,256,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
410 
411 unur_reset_errno();
412 unur_free(gen); gen = NULL;
413 unur_distr_free(distr); distr = NULL;
414 distr = unur_str2distr("cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1");
415 gen = unur_makegen_dsu( distr, "srou", NULL );
416 n_tests_failed += (compare_sequence_gen(TESTLOG,263,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
417 
418 unur_reset_errno();
419 unur_free(gen); gen = NULL;
420 unur_distr_free(distr); distr = NULL;
421 distr = unur_distr_normal(NULL,0);
422 par = unur_ssr_new(distr);
423 gen = unur_init(par);
424 n_tests_failed += (compare_sequence_gen_start(TESTLOG,272,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
425 
426 unur_reset_errno();
427 unur_free(gen); gen = NULL;
428 unur_distr_free(distr); distr = NULL;
429 gen = unur_str2gen( "cont; pdf = \"(1/sqrt(2*pi)*exp(-x^2/2))\"; mode = 0; pdfarea = 1 & \
430 	             method = ssr" );
431 n_tests_failed += (compare_sequence_gen(TESTLOG,279,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
432 
433 unur_reset_errno();
434 unur_free(gen); gen = NULL;
435 unur_distr_free(distr); distr = NULL;
436 distr = unur_distr_normal(NULL,0);
437 par = unur_utdr_new(distr);
438 gen = unur_init(par);
439 n_tests_failed += (compare_sequence_gen_start(TESTLOG,288,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
440 
441 unur_reset_errno();
442 unur_free(gen); gen = NULL;
443 unur_distr_free(distr); distr = NULL;
444 gen = unur_str2gen( "cont; pdf = \"(1/sqrt(2*pi)*exp(-x^2/2))\"; mode = 0; pdfarea = 1 & \
445 	             method = utdr" );
446 n_tests_failed += (compare_sequence_gen(TESTLOG,294,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
447 
448 unur_reset_errno();
449 unur_free(gen); gen = NULL;
450 unur_distr_free(distr); distr = NULL;
451 gen = unur_str2gen( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1 & \
452 	             method = utdr" );
453 n_tests_failed += (compare_sequence_gen(TESTLOG,300,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
454 
455 unur_reset_errno();
456 unur_free(gen); gen = NULL;
457 unur_distr_free(distr); distr = NULL;
458 distr = unur_distr_normal(NULL,0);
459 par = unur_tdr_new(distr);
460 unur_tdr_set_cpoints(par,8,NULL);
461 unur_tdr_set_max_sqhratio(par,0.);
462 gen = unur_init(par);
463 n_tests_failed += (compare_sequence_gen_start(TESTLOG,311,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
464 
465 unur_reset_errno();
466 unur_free(gen); gen = NULL;
467 unur_distr_free(distr); distr = NULL;
468 gen = unur_str2gen( "cont; pdf = \"(1/sqrt(2*pi)*exp(-x^2/2))\"; mode = 0; pdfarea = 1 & \
469 	             method = tdr; cpoints = 8; max_sqhratio = 0." );
470 n_tests_failed += (compare_sequence_gen(TESTLOG,317,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
471 
472 unur_reset_errno();
473 unur_free(gen); gen = NULL;
474 unur_distr_free(distr); distr = NULL;
475 gen = unur_str2gen( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1 & \
476 	             method = tdr; cpoints = 8; max_sqhratio = 0." );
477 n_tests_failed += (compare_sequence_gen(TESTLOG,323,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
478 
479 unur_reset_errno();
480 unur_free(gen); gen = NULL;
481 unur_distr_free(distr); distr = NULL;
482 gen = unur_makegen_ssu( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1", \
483 	             "method = tdr; cpoints = 8; max_sqhratio = 0.", NULL );
484 n_tests_failed += (compare_sequence_gen(TESTLOG,329,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
485 
486 unur_reset_errno();
487 unur_free(gen); gen = NULL;
488 unur_distr_free(distr); distr = NULL;
489 gen = unur_makegen_ssu( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1", \
490 	             "tdr; cpoints = 8; max_sqhratio = 0.", NULL );
491 n_tests_failed += (compare_sequence_gen(TESTLOG,335,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
492 
493 unur_reset_errno();
494 unur_free(gen); gen = NULL;
495 unur_distr_free(distr); distr = NULL;
496 distr = unur_distr_normal(NULL,0);
497 par = unur_arou_new(distr);
498 unur_arou_set_cpoints(par,8,NULL);
499 unur_arou_set_max_sqhratio(par,0.);
500 gen = unur_init(par);
501 n_tests_failed += (compare_sequence_gen_start(TESTLOG,346,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
502 
503 unur_reset_errno();
504 unur_free(gen); gen = NULL;
505 unur_distr_free(distr); distr = NULL;
506 gen = unur_str2gen( "cont; pdf = \"(1/sqrt(2*pi)*exp(-x^2/2))\"; mode = 0; pdfarea = 1 & \
507 	             method = arou; cpoints = 8; max_sqhratio = 0." );
508 n_tests_failed += (compare_sequence_gen(TESTLOG,352,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
509 
510 unur_reset_errno();
511 unur_free(gen); gen = NULL;
512 unur_distr_free(distr); distr = NULL;
513 distr = unur_distr_cont_new();
514 unur_distr_cont_set_cdfstr(distr,"1-exp(-x)");
515 par = unur_ninv_new(distr);
516 unur_ninv_set_usenewton(par);
517 gen = unur_init(par);
518 n_tests_failed += (compare_sequence_gen_start(TESTLOG,363,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
519 
520 unur_reset_errno();
521 unur_free(gen); gen = NULL;
522 unur_distr_free(distr); distr = NULL;
523 gen = unur_str2gen( "cont; cdf = \"1-exp(-x)\"; domain = (0,inf)& \
524 	             method = ninv; usenewton" );
525 n_tests_failed += (compare_sequence_gen(TESTLOG,369,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
526 
527 unur_reset_errno();
528 unur_free(gen); gen = NULL;
529 unur_distr_free(distr); distr = NULL;
530 distr = unur_distr_cont_new();
531 unur_distr_cont_set_hrstr(distr,"1/(1+x)");
532 par = unur_hrb_new(distr);
533 gen = unur_init(par);
534 n_tests_failed += (compare_sequence_gen_start(TESTLOG,379,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
535 
536 unur_reset_errno();
537 unur_free(gen); gen = NULL;
538 unur_distr_free(distr); distr = NULL;
539 gen = unur_str2gen( "cont; hr = \"1/(1+x)\"; domain = (0,inf)& \
540 	             method = hrb" );
541 n_tests_failed += (compare_sequence_gen(TESTLOG,385,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
542 
543 unur_reset_errno();
544 unur_free(gen); gen = NULL;
545 unur_distr_free(distr); distr = NULL;
546 distr = unur_distr_normal(NULL,0);
547 par = unur_auto_new(distr);
548 gen = unur_init(par);
549 n_tests_failed += (compare_sequence_gen_start(TESTLOG,394,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
550 
551 unur_reset_errno();
552 unur_free(gen); gen = NULL;
553 unur_distr_free(distr); distr = NULL;
554 gen = unur_str2gen( "normal() & method=auto" );
555 n_tests_failed += (compare_sequence_gen(TESTLOG,399,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
556 
557 unur_reset_errno();
558 unur_free(gen); gen = NULL;
559 unur_distr_free(distr); distr = NULL;
560 gen = unur_makegen_ssu( "normal()", "method=auto", NULL );
561 n_tests_failed += (compare_sequence_gen(TESTLOG,404,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
562 
563 unur_reset_errno();
564 unur_free(gen); gen = NULL;
565 unur_distr_free(distr); distr = NULL;
566 gen = unur_makegen_ssu( "normal()", "auto", NULL );
567 n_tests_failed += (compare_sequence_gen(TESTLOG,409,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
568 
569 unur_reset_errno();
570 unur_free(gen); gen = NULL;
571 unur_distr_free(distr); distr = NULL;
572 gen = unur_makegen_ssu( "normal()", "", NULL );
573 n_tests_failed += (compare_sequence_gen(TESTLOG,414,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
574 
575 unur_reset_errno();
576 unur_free(gen); gen = NULL;
577 unur_distr_free(distr); distr = NULL;
578 gen = unur_makegen_ssu( "normal()", NULL, NULL );
579 n_tests_failed += (compare_sequence_gen(TESTLOG,419,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
580 
581 unur_reset_errno();
582 unur_free(gen); gen = NULL;
583 unur_distr_free(distr); distr = NULL;
584 gen = unur_makegen_ssu( "normal", NULL, NULL );
585 n_tests_failed += (compare_sequence_gen(TESTLOG,424,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
586 
587 unur_reset_errno();
588 unur_free(gen); gen = NULL;
589 unur_distr_free(distr); distr = NULL;
590 fpm[0] = 1.;
591 fpm[1] = 2.;
592 distr = unur_distr_normal(fpm,2);
593 par = unur_auto_new(distr);
594 gen = unur_init(par);
595 n_tests_failed += (compare_sequence_gen_start(TESTLOG,435,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
596 
597 unur_reset_errno();
598 unur_free(gen); gen = NULL;
599 unur_distr_free(distr); distr = NULL;
600 gen = unur_str2gen( "normal(1.,2.) & method=auto" );
601 n_tests_failed += (compare_sequence_gen(TESTLOG,440,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
602 
603 unur_reset_errno();
604 unur_free(gen); gen = NULL;
605 unur_distr_free(distr); distr = NULL;
606 gen = unur_makegen_ssu( "normal(1,2)", "method=auto", NULL );
607 n_tests_failed += (compare_sequence_gen(TESTLOG,445,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
608 
609 unur_reset_errno();
610 unur_free(gen); gen = NULL;
611 unur_distr_free(distr); distr = NULL;
612 gen = unur_makegen_ssu( "normal(1,2.)", "auto", NULL );
613 n_tests_failed += (compare_sequence_gen(TESTLOG,450,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
614 
615 unur_reset_errno();
616 unur_free(gen); gen = NULL;
617 unur_distr_free(distr); distr = NULL;
618 gen = unur_makegen_ssu( "normal(1.,2)", "", NULL );
619 n_tests_failed += (compare_sequence_gen(TESTLOG,455,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
620 
621 unur_reset_errno();
622 unur_free(gen); gen = NULL;
623 unur_distr_free(distr); distr = NULL;
624 gen = unur_makegen_ssu( "normal(1,2)", NULL, NULL );
625 n_tests_failed += (compare_sequence_gen(TESTLOG,460,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
626 
627 unur_reset_errno();
628 unur_free(gen); gen = NULL;
629 unur_distr_free(distr); distr = NULL;
630 fpm[0] = 1.;
631 fpm[1] = 2.;
632 distr = unur_distr_normal(fpm,2);
633 gen = unur_makegen_dsu( distr, "method=auto", NULL );
634 n_tests_failed += (compare_sequence_gen(TESTLOG,468,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
635 
636 unur_reset_errno();
637 unur_free(gen); gen = NULL;
638 unur_distr_free(distr); distr = NULL;
639 fpm[0] = 1.;
640 fpm[1] = 2.;
641 distr = unur_distr_normal(fpm,2);
642 gen = unur_makegen_dsu( distr, "auto", NULL );
643 n_tests_failed += (compare_sequence_gen(TESTLOG,476,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
644 
645 unur_reset_errno();
646 unur_free(gen); gen = NULL;
647 unur_distr_free(distr); distr = NULL;
648 fpm[0] = 1.;
649 fpm[1] = 2.;
650 distr = unur_distr_normal(fpm,2);
651 gen = unur_makegen_dsu( distr, "", NULL );
652 n_tests_failed += (compare_sequence_gen(TESTLOG,484,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
653 
654 unur_reset_errno();
655 unur_free(gen); gen = NULL;
656 unur_distr_free(distr); distr = NULL;
657 fpm[0] = 1.;
658 fpm[1] = 2.;
659 distr = unur_distr_normal(fpm,2);
660 gen = unur_makegen_dsu( distr, NULL, NULL );
661 n_tests_failed += (compare_sequence_gen(TESTLOG,492,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
662 unur_distr_free(distr);
663 unur_free(gen);
664 }
665 
666 { /* compare function parser - discr */
667 UNUR_DISTR *distr = NULL;
668 UNUR_PAR   *par = NULL;
669 UNUR_GEN   *gen = NULL;
670    double fpar[] = {0.4};
671    distr = NULL;
672    par = NULL;
673    gen = NULL;
674 
675 
676 unur_reset_errno();
677 distr = unur_distr_geometric(fpar,1);
678 par = unur_dsrou_new(distr);
679 gen = unur_init(par);
680 n_tests_failed += (compare_sequence_gen_start(TESTLOG,511,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
681 
682 unur_reset_errno();
683 unur_free(gen); gen = NULL;
684 unur_distr_free(distr); distr = NULL;
685 gen = unur_str2gen( "discr; pmf = \"0.4 * (1-0.4)^k\"; domain = (0,inf); mode = 0; pmfsum = 1 & \
686 	             method = dsrou" );
687 n_tests_failed += (compare_sequence_gen(TESTLOG,517,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
688 
689 unur_reset_errno();
690 unur_free(gen); gen = NULL;
691 unur_distr_free(distr); distr = NULL;
692 distr = unur_distr_geometric(fpar,1);
693 par = unur_dau_new(distr);
694 gen = unur_init(par);
695 n_tests_failed += (compare_sequence_gen_start(TESTLOG,525,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
696 
697 unur_reset_errno();
698 unur_free(gen); gen = NULL;
699 unur_distr_free(distr); distr = NULL;
700 gen = unur_str2gen( "discr; pmf = \"0.4 * (1-0.4)^k\"; domain = (0,inf); mode = 0; pmfsum = 1 & \
701 	             method = dau" );
702 n_tests_failed += (compare_sequence_gen(TESTLOG,531,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
703 
704 unur_reset_errno();
705 unur_free(gen); gen = NULL;
706 unur_distr_free(distr); distr = NULL;
707 distr = unur_distr_geometric(fpar,1);
708 par = unur_dgt_new(distr);
709 gen = unur_init(par);
710 n_tests_failed += (compare_sequence_gen_start(TESTLOG,539,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
711 
712 unur_reset_errno();
713 unur_free(gen); gen = NULL;
714 unur_distr_free(distr); distr = NULL;
715 gen = unur_str2gen( "discr; pmf = \"0.4 * (1-0.4)^k\"; domain = (0,inf); mode = 0; pmfsum = 1 & \
716 	             method = dgt" );
717 n_tests_failed += (compare_sequence_gen(TESTLOG,545,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
718 
719 unur_reset_errno();
720 unur_free(gen); gen = NULL;
721 unur_distr_free(distr); distr = NULL;
722 distr = unur_distr_geometric(fpar,1);
723 par = unur_dari_new(distr);
724 gen = unur_init(par);
725 n_tests_failed += (compare_sequence_gen_start(TESTLOG,553,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
726 
727 unur_reset_errno();
728 unur_free(gen); gen = NULL;
729 unur_distr_free(distr); distr = NULL;
730 gen = unur_str2gen( "discr; pmf = \"0.4 * (1-0.4)^k\"; domain = (0,inf); mode = 0; pmfsum = 1 & \
731 	             method = dari" );
732 n_tests_failed += (compare_sequence_gen(TESTLOG,560,gen,COMPARE_SAMPLE_SIZE)==UNUR_SUCCESS)?0:1;
733 unur_distr_free(distr);
734 unur_free(gen);
735 }
736 
737 
738 	/* timing */
739 	stopwatch_print(TESTLOG,"\n<*>time = %.3f ms\n\n", stopwatch_lap(&watch));
740 
741 	/* test finished */
742 	test_ok &= (n_tests_failed) ? 0 : 1;
743 	(n_tests_failed) ? printf(" ==> failed] ") : printf(" ==> ok] ");
744 
745 } /* end of test_sample() */
746 
747 
748 /*---------------------------------------------------------------------------*/
749 /* run generator in verifying mode */
750 
run_verify_generator(FILE * LOG,int line,UNUR_PAR * par)751 void run_verify_generator( FILE *LOG, int line, UNUR_PAR *par )
752 {
753 	UNUR_GEN *gen;
754 	int i;
755 
756 	/* switch to verifying mode */
757 	unur_stringparser_set_verify(par,1);
758 
759 	/* initialize generator */
760 	gen = unur_init( par ); abort_if_NULL(LOG, line, gen);
761 
762 	/* run generator */
763 	for (i=0; i<VIOLATE_SAMPLE_SIZE; i++)
764 		unur_sample_cont(gen);
765 
766 	/* destroy generator */
767 	unur_free(gen);
768 
769 } /* end of run_verify_generator() */
770 
unur_stringparser_set_verify(UNUR_PAR * par ATTRIBUTE__UNUSED,int verify ATTRIBUTE__UNUSED)771 int unur_stringparser_set_verify(UNUR_PAR *par ATTRIBUTE__UNUSED, int verify ATTRIBUTE__UNUSED) {return 0;}
772 
773 /*---------------------------------------------------------------------------*/
774 
main(void)775 int main(void)
776 {
777         unsigned long seed;
778 	char *str_seed, *str_tail;
779 
780 	/* start stop watch */
781 	stopwatch_init();
782 	stopwatch_start(&watch);
783 
784         /* open log file for unuran and set output stream for unuran messages */
785         UNURANLOG = fopen( "t_stringparser_unuran.log","w" );
786         abort_if_NULL( stderr,-1, UNURANLOG );
787         unur_set_stream( UNURANLOG );
788 
789         /* open log file for testing */
790 	TESTLOG = fopen( "t_stringparser_test.log","w" );
791 	abort_if_NULL( stderr,-1, TESTLOG );
792 
793         /* seed for uniform generators */
794 
795 	/* seed set by environment */
796 	str_seed = getenv("SEED");
797 
798 	if (str_seed != NULL) {
799 	    seed = strtol(str_seed, &str_tail, 10);
800 	    if (seed == 0u)
801 		seed = 259225;
802 	}
803 	else {
804 #ifdef SEED
805 	    seed = SEED;
806 #else
807 	    seed = 259225;
808 #endif
809 	}
810 
811         /* seed build-in uniform generators */
812         unur_urng_MRG31k3p_seed(NULL,seed);
813         unur_urng_fish_seed(NULL,seed);
814 	unur_urng_mstd_seed(NULL,seed);
815 
816 	/* seed uniform random number generator */
817 #ifdef UNUR_URNG_UNURAN
818 #  ifdef UNUR_URNG_DEFAULT_RNGSTREAM
819 	{
820 	        unsigned long sa[6];
821 	        int i;
822 	        for (i=0; i<6; i++) sa[i] = seed;
823                 RngStream_SetPackageSeed(sa);
824         }
825 #  else
826 	if (unur_urng_seed(NULL,seed) != UNUR_SUCCESS) {
827 	        fprintf(stderr,"WARNING: Seed could not be set at random\n");
828                 seed = ~0u;
829 	}
830 #  endif  /* UNUR_URNG_DEFAULT_RNGSTREAM */
831 #endif  /* UNUR_URNG_UNURAN */
832 
833 	/* set default debugging flag */
834 	unur_set_default_debug(UNUR_DEBUG_ALL);
835 
836         /* detect required check mode */
837         fullcheck = (getenv("UNURANFULLCHECK")==NULL) ? FALSE : TRUE;
838 
839 	/* write header into log file */
840         print_test_log_header( TESTLOG, seed, fullcheck );
841 
842 	/* set timer for sending SIGALRM signal */
843 	set_alarm(TESTLOG);
844 
845 	/* start test */
846 	printf("stringparser: ");
847 
848 	/* run tests */
849 test_new();
850 test_init();
851 test_sample();
852 
853 
854 	/* test finished */
855 	printf("\n");  fflush(stdout);
856 
857 	/* close log files */
858 	fprintf(TESTLOG,"\n====================================================\n\n");
859 	if (test_ok)
860 		fprintf(TESTLOG,"All tests PASSED.\n");
861 	else
862 		fprintf(TESTLOG,"Test(s) FAILED.\n");
863 
864 	/* timing */
865 	stopwatch_print(TESTLOG,"\n<*>total time = %.0f ms\n\n", stopwatch_stop(&watch));
866 
867 	fclose(UNURANLOG);
868 	fclose(TESTLOG);
869 
870 	/* free memory */
871 	compare_free_memory();
872 	unur_urng_free(unur_get_default_urng());
873 	unur_urng_free(unur_get_default_urng_aux());
874 
875 	/* exit */
876 	exit( (test_ok) ? EXIT_SUCCESS : EXIT_FAILURE );
877 
878 } /* end of main */
879 
880