1# $Id: t_stringparser.conf 5330 2011-04-19 10:50:18Z leydold $
2#############################################################################
3
4[main]
5
6[main - data:]
7
8# method (for information only: the program scans the file name)
9method: STRINGPARSER
10
11[main - header:]
12
13/* prototypes */
14int unur_ssr_set_pedantic( struct unur_par *par, int pedantic );
15
16\#define COMPARE_SAMPLE_SIZE   (10000)
17\#define VIOLATE_SAMPLE_SIZE   (20)
18
19#############################################################################
20
21[new]
22
23#############################################################################
24
25# [set]
26
27#############################################################################
28
29# [get]
30
31#############################################################################
32
33# [chg]
34
35#############################################################################
36
37[init]
38
39# unur_str2gen ...
40
41[init - invalid NULL ptr:
42   distr = NULL;
43   gen = NULL; ]
44
45gen = unur_str2gen( NULL );
46	--> expected_NULL --> UNUR_ERR_NULL
47
48distr = unur_str2distr( NULL );
49	--> expected_NULL --> UNUR_ERR_NULL
50
51gen = unur_makegen_ssu(NULL,NULL,NULL);
52	--> expected_NULL --> UNUR_ERR_NULL
53
54
55[init - invalid distribution block:
56   gen = NULL; ]
57
58gen = unur_str2gen( "xxxx" );
59	--> expected_NULL --> UNUR_ERR_STR_UNKNOWN
60
61unur_free(gen); gen = NULL;
62gen = unur_str2gen( "method = xxxx" );
63	--> expected_NULL --> UNUR_ERR_STR_SYNTAX
64
65unur_free(gen); gen = NULL;
66gen = unur_str2gen( "normal; xxxx=1" );
67	--> expected_NULL --> UNUR_ERR_STR_UNKNOWN
68
69unur_free(gen); gen = NULL;
70gen = unur_str2gen( "normal; pv=(1,2,3)" );
71	--> expected_NULL --> UNUR_ERR_STR_UNKNOWN
72
73unur_free(gen); gen = NULL;
74gen = unur_str2gen( "normal,(1,2)" );
75	--> expected_NULL --> UNUR_ERR_STR_UNKNOWN
76
77unur_free(gen); gen = NULL;
78gen = unur_str2gen( "beta" );
79	--> expected_NULL --> UNUR_ERR_STR_INVALID
80
81unur_free(gen); gen = NULL;
82gen = unur_str2gen( "beta()" );
83	--> expected_NULL --> UNUR_ERR_STR_INVALID
84
85unur_free(gen); gen = NULL;
86gen = unur_str2gen( "beta(1)" );
87	--> expected_NULL --> UNUR_ERR_STR_INVALID
88
89unur_free(gen); gen = NULL;
90gen = unur_str2gen( "beta(1,2,3)" );
91	--> none --> UNUR_ERR_DISTR_NPARAMS
92
93unur_free(gen); gen = NULL;
94gen = unur_str2gen( "beta(1,2,3,4,5)" );
95	--> none --> UNUR_ERR_DISTR_NPARAMS
96
97unur_free(gen); gen = NULL;
98gen = unur_str2gen( "gamma(-0.5)" );
99	--> expected_NULL --> UNUR_ERR_STR_INVALID
100
101unur_free(gen); gen = NULL;
102gen = unur_str2gen( "normal(); domain" );
103	--> expected_NULL --> UNUR_ERR_STR_INVALID
104
105
106[init - invalid other block:
107   gen = NULL; ]
108
109gen = unur_str2gen( "normal() & xxxx = arou" );
110	--> expected_NULL --> UNUR_ERR_STR_UNKNOWN
111
112unur_free(gen); gen = NULL;
113gen = unur_str2gen( "normal() & distr=gamma(2)" );
114	--> expected_NULL --> UNUR_ERR_STR_UNKNOWN
115
116
117[init - invalid method block:
118   gen = NULL; ]
119
120gen = unur_str2gen( "normal() & method = arou; c = 0" );
121	--> none --> UNUR_ERR_STR_UNKNOWN
122
123unur_free(gen); gen = NULL;
124gen = unur_str2gen( "normal() & method = xxx" );
125	--> expected_NULL --> UNUR_ERR_NULL
126
127
128[init - invalid urng block:
129    gen = NULL; ]
130
131gen = unur_str2gen( "normal & urng = xxx" );
132	--> none --> UNUR_ERR_STR
133
134unur_free(gen); gen = NULL;
135\#ifdef UNURAN_SUPPORTS_PRNG
136gen = unur_str2gen( "normal & urng = mt19937(123); xxx = 1" );
137	--> none --> UNUR_ERR_STR_UNKNOWN
138
139\#endif
140
141
142[init - invalid data:
143   gen = NULL; ]
144
145gen = unur_str2gen( "gamma(0.5) & method = tdr" );
146	--> expected_NULL --> UNUR_ERR_GEN_DATA
147
148
149# unur_str2par ...
150
151[init - invalid data:
152   struct unur_slist *mlist = NULL;
153   distr = NULL;
154   par = NULL;
155   gen = NULL; ]
156
157distr = unur_str2distr("normal()");
158par = _unur_str2par(distr, "tdr", &mlist);
159gen = unur_init(par);
160_unur_slist_free(mlist);
161
162## Function parser
163
164[init - invalid distribution block:
165   distr = NULL; ]
166
167## missing parenthesis for function
168distr = unur_str2distr("cont; pdf='exp'");
169	--> expected_NULL --> UNUR_ERR_STR_INVALID
170
171
172## unknown function name
173distr = unur_str2distr("cont; pdf='abc(x)'");
174	--> expected_NULL --> UNUR_ERR_STR_INVALID
175
176## the first symbol ('x') is interpreted as variable,
177## the second one causes an error.
178distr = unur_str2distr("cont; pdf='exp(x*y)'");
179	--> expected_NULL --> UNUR_ERR_STR_INVALID
180
181## invalid number of parentheses
182distr = unur_str2distr("cont; pdf='exp(x'");
183	--> expected_NULL --> UNUR_ERR_STR_INVALID
184
185distr = unur_str2distr("cont; pdf='exp((x)'");
186	--> expected_NULL --> UNUR_ERR_STR_INVALID
187
188distr = unur_str2distr("cont; pdf='exp(x))'");
189	--> expected_NULL --> UNUR_ERR_STR_INVALID
190
191## variable name expected
192distr = unur_str2distr("cont; pdf='x^'");
193	--> expected_NULL --> UNUR_ERR_STR_INVALID
194
195##
196distr = unur_str2distr("cont; pdf='exp(x)x'");
197	--> expected_NULL --> UNUR_ERR_STR_INVALID
198
199distr = unur_str2distr("cont; pdf='2x'");
200	--> expected_NULL --> UNUR_ERR_STR_INVALID
201
202distr = unur_str2distr("cont; pdf='x***2'");
203	--> expected_NULL --> UNUR_ERR_STR_INVALID
204
205distr = unur_str2distr("cont; pdf='x*exp(x^(x*y))'");
206	--> expected_NULL --> UNUR_ERR_STR_INVALID
207
208
209
210# unur_makegen_ssu ...
211
212
213#############################################################################
214
215# [reinit]
216
217#############################################################################
218
219[sample]
220
221#----------------------------------------------------------------------------
222
223[sample - compare function parser - cont:
224   double fpm[10];
225   distr = NULL;
226   par = NULL;
227   gen = NULL; ]
228
229distr = unur_distr_normal(NULL,0);
230par = unur_srou_new(distr);
231gen = unur_init(par);
232	-->compare_sequence_gen_start
233
234unur_free(gen); gen = NULL;
235unur_distr_free(distr); distr = NULL;
236gen = unur_str2gen( "cont; pdf = \"(1/sqrt(2*pi)*exp(-x^2/2))\"; mode = 0; pdfarea = 1 & \
237	             method = srou" );
238	-->compare_sequence_gen
239
240unur_free(gen); gen = NULL;
241unur_distr_free(distr); distr = NULL;
242gen = unur_str2gen( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1 & \
243	             method = srou" );
244	-->compare_sequence_gen
245
246unur_free(gen); gen = NULL;
247unur_distr_free(distr); distr = NULL;
248gen = unur_makegen_ssu( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1", \
249	             "method = srou", NULL );
250	-->compare_sequence_gen
251
252unur_free(gen); gen = NULL;
253unur_distr_free(distr); distr = NULL;
254gen = unur_makegen_ssu( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1", \
255	             "srou", NULL );
256	-->compare_sequence_gen
257
258
259unur_free(gen); gen = NULL;
260unur_distr_free(distr); distr = NULL;
261distr = unur_str2distr("cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1");
262gen = unur_makegen_dsu( distr, "srou", NULL );
263	-->compare_sequence_gen
264
265# ...........................................................................
266
267unur_free(gen); gen = NULL;
268unur_distr_free(distr); distr = NULL;
269distr = unur_distr_normal(NULL,0);
270par = unur_ssr_new(distr);
271gen = unur_init(par);
272	-->compare_sequence_gen_start
273
274#if(fullcheck) {
275unur_free(gen); gen = NULL;
276unur_distr_free(distr); distr = NULL;
277gen = unur_str2gen( "cont; pdf = \"(1/sqrt(2*pi)*exp(-x^2/2))\"; mode = 0; pdfarea = 1 & \
278	             method = ssr" );
279	-->compare_sequence_gen
280
281# ...........................................................................
282
283unur_free(gen); gen = NULL;
284unur_distr_free(distr); distr = NULL;
285distr = unur_distr_normal(NULL,0);
286par = unur_utdr_new(distr);
287gen = unur_init(par);
288	-->compare_sequence_gen_start
289
290unur_free(gen); gen = NULL;
291unur_distr_free(distr); distr = NULL;
292gen = unur_str2gen( "cont; pdf = \"(1/sqrt(2*pi)*exp(-x^2/2))\"; mode = 0; pdfarea = 1 & \
293	             method = utdr" );
294	-->compare_sequence_gen
295
296unur_free(gen); gen = NULL;
297unur_distr_free(distr); distr = NULL;
298gen = unur_str2gen( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1 & \
299	             method = utdr" );
300	-->compare_sequence_gen
301
302# ...........................................................................
303
304unur_free(gen); gen = NULL;
305unur_distr_free(distr); distr = NULL;
306distr = unur_distr_normal(NULL,0);
307par = unur_tdr_new(distr);
308unur_tdr_set_cpoints(par,8,NULL);
309unur_tdr_set_max_sqhratio(par,0.);
310gen = unur_init(par);
311	-->compare_sequence_gen_start
312
313unur_free(gen); gen = NULL;
314unur_distr_free(distr); distr = NULL;
315gen = unur_str2gen( "cont; pdf = \"(1/sqrt(2*pi)*exp(-x^2/2))\"; mode = 0; pdfarea = 1 & \
316	             method = tdr; cpoints = 8; max_sqhratio = 0." );
317	-->compare_sequence_gen
318
319unur_free(gen); gen = NULL;
320unur_distr_free(distr); distr = NULL;
321gen = unur_str2gen( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1 & \
322	             method = tdr; cpoints = 8; max_sqhratio = 0." );
323	-->compare_sequence_gen
324
325unur_free(gen); gen = NULL;
326unur_distr_free(distr); distr = NULL;
327gen = unur_makegen_ssu( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1", \
328	             "method = tdr; cpoints = 8; max_sqhratio = 0.", NULL );
329	-->compare_sequence_gen
330
331unur_free(gen); gen = NULL;
332unur_distr_free(distr); distr = NULL;
333gen = unur_makegen_ssu( "cont; logpdf = \"-x^2/2-0.5*log(2*pi)\"; mode = 0; pdfarea = 1", \
334	             "tdr; cpoints = 8; max_sqhratio = 0.", NULL );
335	-->compare_sequence_gen
336
337# ...........................................................................
338
339unur_free(gen); gen = NULL;
340unur_distr_free(distr); distr = NULL;
341distr = unur_distr_normal(NULL,0);
342par = unur_arou_new(distr);
343unur_arou_set_cpoints(par,8,NULL);
344unur_arou_set_max_sqhratio(par,0.);
345gen = unur_init(par);
346	-->compare_sequence_gen_start
347
348unur_free(gen); gen = NULL;
349unur_distr_free(distr); distr = NULL;
350gen = unur_str2gen( "cont; pdf = \"(1/sqrt(2*pi)*exp(-x^2/2))\"; mode = 0; pdfarea = 1 & \
351	             method = arou; cpoints = 8; max_sqhratio = 0." );
352	-->compare_sequence_gen
353
354# ...........................................................................
355
356unur_free(gen); gen = NULL;
357unur_distr_free(distr); distr = NULL;
358distr = unur_distr_cont_new();
359unur_distr_cont_set_cdfstr(distr,"1-exp(-x)");
360par = unur_ninv_new(distr);
361unur_ninv_set_usenewton(par);
362gen = unur_init(par);
363	-->compare_sequence_gen_start
364
365unur_free(gen); gen = NULL;
366unur_distr_free(distr); distr = NULL;
367gen = unur_str2gen( "cont; cdf = \"1-exp(-x)\"; domain = (0,inf)& \
368	             method = ninv; usenewton" );
369	-->compare_sequence_gen
370
371# ...........................................................................
372
373unur_free(gen); gen = NULL;
374unur_distr_free(distr); distr = NULL;
375distr = unur_distr_cont_new();
376unur_distr_cont_set_hrstr(distr,"1/(1+x)");
377par = unur_hrb_new(distr);
378gen = unur_init(par);
379	-->compare_sequence_gen_start
380
381unur_free(gen); gen = NULL;
382unur_distr_free(distr); distr = NULL;
383gen = unur_str2gen( "cont; hr = \"1/(1+x)\"; domain = (0,inf)& \
384	             method = hrb" );
385	-->compare_sequence_gen
386
387# ...........................................................................
388
389unur_free(gen); gen = NULL;
390unur_distr_free(distr); distr = NULL;
391distr = unur_distr_normal(NULL,0);
392par = unur_auto_new(distr);
393gen = unur_init(par);
394	-->compare_sequence_gen_start
395
396unur_free(gen); gen = NULL;
397unur_distr_free(distr); distr = NULL;
398gen = unur_str2gen( "normal() & method=auto" );
399	-->compare_sequence_gen
400
401unur_free(gen); gen = NULL;
402unur_distr_free(distr); distr = NULL;
403gen = unur_makegen_ssu( "normal()", "method=auto", NULL );
404	-->compare_sequence_gen
405
406unur_free(gen); gen = NULL;
407unur_distr_free(distr); distr = NULL;
408gen = unur_makegen_ssu( "normal()", "auto", NULL );
409	-->compare_sequence_gen
410
411unur_free(gen); gen = NULL;
412unur_distr_free(distr); distr = NULL;
413gen = unur_makegen_ssu( "normal()", "", NULL );
414	-->compare_sequence_gen
415
416unur_free(gen); gen = NULL;
417unur_distr_free(distr); distr = NULL;
418gen = unur_makegen_ssu( "normal()", NULL, NULL );
419	-->compare_sequence_gen
420
421unur_free(gen); gen = NULL;
422unur_distr_free(distr); distr = NULL;
423gen = unur_makegen_ssu( "normal", NULL, NULL );
424	-->compare_sequence_gen
425
426# ...........................................................................
427
428unur_free(gen); gen = NULL;
429unur_distr_free(distr); distr = NULL;
430fpm[0] = 1.;
431fpm[1] = 2.;
432distr = unur_distr_normal(fpm,2);
433par = unur_auto_new(distr);
434gen = unur_init(par);
435	-->compare_sequence_gen_start
436
437unur_free(gen); gen = NULL;
438unur_distr_free(distr); distr = NULL;
439gen = unur_str2gen( "normal(1.,2.) & method=auto" );
440	-->compare_sequence_gen
441
442unur_free(gen); gen = NULL;
443unur_distr_free(distr); distr = NULL;
444gen = unur_makegen_ssu( "normal(1,2)", "method=auto", NULL );
445	-->compare_sequence_gen
446
447unur_free(gen); gen = NULL;
448unur_distr_free(distr); distr = NULL;
449gen = unur_makegen_ssu( "normal(1,2.)", "auto", NULL );
450	-->compare_sequence_gen
451
452unur_free(gen); gen = NULL;
453unur_distr_free(distr); distr = NULL;
454gen = unur_makegen_ssu( "normal(1.,2)", "", NULL );
455	-->compare_sequence_gen
456
457unur_free(gen); gen = NULL;
458unur_distr_free(distr); distr = NULL;
459gen = unur_makegen_ssu( "normal(1,2)", NULL, NULL );
460	-->compare_sequence_gen
461
462unur_free(gen); gen = NULL;
463unur_distr_free(distr); distr = NULL;
464fpm[0] = 1.;
465fpm[1] = 2.;
466distr = unur_distr_normal(fpm,2);
467gen = unur_makegen_dsu( distr, "method=auto", NULL );
468	-->compare_sequence_gen
469
470unur_free(gen); gen = NULL;
471unur_distr_free(distr); distr = NULL;
472fpm[0] = 1.;
473fpm[1] = 2.;
474distr = unur_distr_normal(fpm,2);
475gen = unur_makegen_dsu( distr, "auto", NULL );
476	-->compare_sequence_gen
477
478unur_free(gen); gen = NULL;
479unur_distr_free(distr); distr = NULL;
480fpm[0] = 1.;
481fpm[1] = 2.;
482distr = unur_distr_normal(fpm,2);
483gen = unur_makegen_dsu( distr, "", NULL );
484	-->compare_sequence_gen
485
486unur_free(gen); gen = NULL;
487unur_distr_free(distr); distr = NULL;
488fpm[0] = 1.;
489fpm[1] = 2.;
490distr = unur_distr_normal(fpm,2);
491gen = unur_makegen_dsu( distr, NULL, NULL );
492	-->compare_sequence_gen
493
494# ...........................................................................
495
496## Not tested:
497##
498## unur_distr_cont_set_pdfparams();
499
500#---------------------------------------------------------------------
501
502[sample - compare function parser - discr:
503   double fpar[] = {0.4};
504   distr = NULL;
505   par = NULL;
506   gen = NULL; ]
507
508distr = unur_distr_geometric(fpar,1);
509par = unur_dsrou_new(distr);
510gen = unur_init(par);
511	-->compare_sequence_gen_start
512
513unur_free(gen); gen = NULL;
514unur_distr_free(distr); distr = NULL;
515gen = unur_str2gen( "discr; pmf = \"0.4 * (1-0.4)^k\"; domain = (0,inf); mode = 0; pmfsum = 1 & \
516	             method = dsrou" );
517	-->compare_sequence_gen
518
519
520unur_free(gen); gen = NULL;
521unur_distr_free(distr); distr = NULL;
522distr = unur_distr_geometric(fpar,1);
523par = unur_dau_new(distr);
524gen = unur_init(par);
525	-->compare_sequence_gen_start
526
527unur_free(gen); gen = NULL;
528unur_distr_free(distr); distr = NULL;
529gen = unur_str2gen( "discr; pmf = \"0.4 * (1-0.4)^k\"; domain = (0,inf); mode = 0; pmfsum = 1 & \
530	             method = dau" );
531	-->compare_sequence_gen
532
533
534unur_free(gen); gen = NULL;
535unur_distr_free(distr); distr = NULL;
536distr = unur_distr_geometric(fpar,1);
537par = unur_dgt_new(distr);
538gen = unur_init(par);
539	-->compare_sequence_gen_start
540
541unur_free(gen); gen = NULL;
542unur_distr_free(distr); distr = NULL;
543gen = unur_str2gen( "discr; pmf = \"0.4 * (1-0.4)^k\"; domain = (0,inf); mode = 0; pmfsum = 1 & \
544	             method = dgt" );
545	-->compare_sequence_gen
546
547
548unur_free(gen); gen = NULL;
549unur_distr_free(distr); distr = NULL;
550distr = unur_distr_geometric(fpar,1);
551par = unur_dari_new(distr);
552gen = unur_init(par);
553	-->compare_sequence_gen_start
554
555
556unur_free(gen); gen = NULL;
557unur_distr_free(distr); distr = NULL;
558gen = unur_str2gen( "discr; pmf = \"0.4 * (1-0.4)^k\"; domain = (0,inf); mode = 0; pmfsum = 1 & \
559	             method = dari" );
560	-->compare_sequence_gen
561
562## Not tested:
563##
564## unur_distr_discr_set_mode();
565## unur_distr_discr_set_pmfparams();
566
567#############################################################################
568
569# [validate]
570
571#############################################################################
572#############################################################################
573
574[verbatim]
575
576#############################################################################
577
578