data-in: Convert test for numeric input formats to Autotest framework.
[pspp-builds.git] / tests / data / data-in.at
1 AT_BANNER([data input (data-in)])
2
3 m4_divert_push([PREPARE_TESTS])
4 data_in_prng () {
5   cat > my-rand.pl <<'EOF'
6 # This random number generator and the test for it below are drawn
7 # from Park and Miller, "Random Number Generators: Good Ones are Hard
8 # to Come By", Communications of the ACM 31:10 (October 1988).  It is
9 # documented to function properly on systems with a 46-bit or longer
10 # real significand, which includes systems that have 64-bit IEEE reals
11 # (with 53-bit significand).  The test should catch any systems for
12 # which this is not true, in any case.
13
14 our ($seed) = 1;
15 sub my_rand {
16   my ($modulo) = @_;
17   my ($a) = 16807;
18   my ($m) = 2147483647;
19   my ($tmp) = $a * $seed;
20   $seed = $tmp - $m * int ($tmp / $m);
21   return $seed % $modulo;
22 }
23 EOF
24   cat > test-my-rand.pl <<'EOF'
25 #! /usr/bin/perl
26 use strict;
27 use warnings;
28 do 'my-rand.pl';
29 my_rand (1) foreach 1...10000;
30 our $seed;
31 die $seed if $seed != 1043618065;
32 EOF
33 }
34 m4_divert_pop([PREPARE_TESTS])
35
36 AT_SETUP([numeric input formats])
37 AT_KEYWORDS([data-in])
38 data_in_prng
39 AT_CHECK([$PERL test-my-rand.pl])
40 AT_DATA([num-in.pl],
41 [[#! /usr/bin/perl
42
43 use POSIX;
44 use strict;
45 use warnings;
46
47 do 'my-rand.pl';
48
49 for my $number (0, 1, .5, .015625, 123) {
50     my ($base_exp) = floor ($number ? log10 ($number) : 0);
51     for my $offset (-3...3) {
52         my ($exponent) = $base_exp + $offset;
53         my ($fraction) = $number / 10**$offset;
54
55         permute_zeros ($fraction, $exponent);
56     }
57 }
58
59 sub permute_zeros {
60     my ($fraction, $exponent) = @_;
61
62     my ($frac_rep) = sprintf ("%f", $fraction);
63     my ($leading_zeros) = length (($frac_rep =~ /^(0*)/)[0]);
64     my ($trailing_zeros) = length (($frac_rep =~ /(\.?0*)$/)[0]);
65     for my $i (0...$leading_zeros) {
66         for my $j (0...$trailing_zeros) {
67             my ($trimmed) = substr ($frac_rep, $i,
68                                     length ($frac_rep) - $i - $j);
69             next if $trimmed eq '.' || $trimmed eq '';
70
71             permute_commas ($trimmed, $exponent);
72         }
73     }
74 }
75
76 sub permute_commas {
77     my ($frac_rep, $exponent) = @_;
78     permute_dot_comma ($frac_rep, $exponent);
79     my ($pos) = int (my_rand (length ($frac_rep) + 1));
80     $frac_rep = substr ($frac_rep, 0, $pos) . "," . substr ($frac_rep, $pos);
81     permute_dot_comma ($frac_rep, $exponent);
82 }
83
84 sub permute_dot_comma {
85     my ($frac_rep, $exponent) = @_;
86     permute_exponent_syntax ($frac_rep, $exponent);
87     if ($frac_rep =~ /[,.]/) {
88         $frac_rep =~ tr/.,/,./;
89         permute_exponent_syntax ($frac_rep, $exponent);
90     }
91 }
92
93 sub permute_exponent_syntax {
94     my ($frac_rep, $exponent) = @_;
95     my (@exp_reps);
96     if ($exponent == 0) {
97         @exp_reps = pick ('', 'e0', 'e-0', 'e+0', '-0', '+0');
98     } elsif ($exponent > 0) {
99         @exp_reps = pick ("e$exponent", "e+$exponent", "+$exponent");
100     } else {
101         my ($abs_exp) = -$exponent;
102         @exp_reps = pick ("e-$abs_exp", , "e-$abs_exp", "-$abs_exp");
103     }
104     permute_sign_and_affix ($frac_rep, $_) foreach @exp_reps;
105 }
106
107 sub permute_sign_and_affix {
108     my ($frac_rep, $exp_rep) = @_;
109     for my $prefix (pick ('', '$'),
110                     pick ('-', '-$', '$-', '$-$'),
111                     pick ('+', '+$', '$+', '$+$')) {
112         for my $suffix ('', '%') {
113             permute_spaces ("$prefix$frac_rep$exp_rep$suffix");
114         }
115     }
116 }
117
118 sub permute_spaces {
119     my ($s) = @_;
120     $s =~ s/([-+\$e%])/ $1 /g;
121     my (@fields) = split (' ', $s);
122     print join ('', @fields), "\n";
123
124     if ($#fields > 0) {
125         my ($pos) = int (my_rand ($#fields)) + 1;
126         print join ('', @fields[0...$pos - 1]);
127         print " ";
128         print join ('', @fields[$pos...$#fields]);
129         print "\n";
130     }
131 }
132
133 sub pick {
134     return $_[int (my_rand ($#_ + 1))];
135 }
136 ]])
137 AT_CHECK([$PERL num-in.pl > num-in.data])
138 AT_DATA([num-in.sps], [dnl
139 SET ERRORS=NONE.
140 SET MXERRS=10000000.
141 SET MXWARNS=10000000.
142 DATA LIST FILE='num-in.data' NOTABLE/
143         f 1-40 (f)
144         comma 1-40 (comma)
145         dot 1-40 (dot)
146         dollar 1-40 (dollar)
147         pct 1-40 (pct)
148         e 1-40 (e).
149 PRINT OUTFILE='num-in.out'/all (6f10.4).
150 EXECUTE.
151 ])
152 AT_CHECK([pspp -O format=csv num-in.sps])
153 AT_CHECK([gzip -cd < $top_srcdir/tests/data/num-in.expected.gz > expout])
154 AT_CHECK([cat num-in.out], [0], [expout])
155 AT_CLEANUP
156
157 dnl Some very old version of PSPP crashed reading big numbers,
158 dnl so this checks for regressions.
159 AT_SETUP([reading big numbers])
160 AT_KEYWORDS([data-in])
161 AT_DATA([bignum.txt], [dnl
162 0
163 0.1
164 0.5
165 0.8
166 0.9
167 0.999
168 1
169 2
170 3
171 4
172 5
173 12
174 123
175 1234
176 12345
177 123456
178 1234567
179 12345678
180 123456789
181 1234567890
182 19999999999
183 199999999999
184 1234567890123
185 19999999999999
186 199999999999999
187 1234567890123456
188 19999999999999999
189 123456789012345678
190 1999999999999999999
191 12345678901234567890
192 199999999999999999999
193 1234567890123456789012
194 19999999999999999999999
195 123456789012345678901234
196 1999999999999999999999999
197 12345678901234567890123456
198 199999999999999999999999999
199 1234567890123456789012345678
200 19999999999999999999999999999
201 123456789012345678901234567890
202 1999999999999999999999999999999
203 12345678901234567890123456789012
204 199999999999999999999999999999999
205 1234567890123456789012345678901234
206 19999999999999999999999999999999999
207 123456789012345678901234567890123456
208 1999999999999999999999999999999999999
209 12345678901234567890123456789012345678
210 199999999999999999999999999999999999999
211 1234567890123456789012345678901234567890
212 1999999999999999999999999999999999999999
213 1e40
214 1.1e40
215 1.5e40
216 1e41
217 1e50
218 1e100
219 1e150
220 1e200
221 1e250
222 1e300
223 1.79641e308
224 wizzah
225 ])
226 AT_DATA([bignum.sps], [dnl
227 title 'Test use of big numbers'.
228
229 *** Do the portable output.
230 data list file='bignum.txt'/BIGNUM 1-40.
231 list.
232
233 *** Do the nonportable output for fun. 
234 descriptives BIGNUM.
235 ])
236 AT_CHECK([pspp -o pspp.csv bignum.sps], [0], [ignore])
237 AT_CLEANUP
238
239 AT_SETUP([binary and hexadecimal input (IB, PIB, and PIBHEX formats)])
240 AT_CHECK([$PERL -e 'print pack "n", $_ foreach 0...65535' > binhex-in.data])
241 AT_CHECK([wc -c < binhex-in.data], [0], [131072
242 ])
243 AT_DATA([binhex-in.sps], [dnl
244 SET RIB=MSBFIRST.
245 SET ERRORS=NONE.
246 SET MXWARNS=10000000.
247 SET MXERRS=10000000.
248 FILE HANDLE data/NAME='binhex-in.data'/MODE=IMAGE/LRECL=2.
249 DATA LIST FILE=data NOTABLE/ib 1-2 (IB) pib 1-2 (PIB) pibhex 1-2 (PIBHEX).
250 COMPUTE x=$CASENUM - 1.
251 PRINT OUTFILE='binhex-in.out'/x (PIBHEX4) ' ' ib pib pibhex.
252 EXECUTE.
253 ])
254 AT_CHECK([gzip -cd < $top_srcdir/tests/data/binhex-in.expected.cmp.gz | \
255             $PERL -pe "printf ' %04X ', $.-1" > expout])
256 AT_CHECK([pspp -O format=csv binhex-in.sps], [0])
257 AT_CHECK([cat binhex-in.out], [0], [expout])
258 AT_CLEANUP
259
260 AT_SETUP([BCD input (P and PK formats)])
261 AT_CHECK([$PERL -e 'print pack "n", $_ foreach 0...65535' > bcd-in.data])
262 AT_CHECK([wc -c < bcd-in.data], [0], [131072
263 ])
264 AT_DATA([bcd-in.sps], [dnl
265 SET ERRORS=NONE.
266 SET MXWARNS=10000000.
267 SET MXERRS=10000000.
268 FILE HANDLE data/NAME='bcd-in.data'/MODE=IMAGE/LRECL=2.
269 DATA LIST FILE=data NOTABLE/p 1-2 (P) pk 1-2 (PK).
270 COMPUTE x=$CASENUM - 1.
271 PRINT OUTFILE='bcd-in.out'/x (PIBHEX4) ' ' P PK.
272 EXECUTE.
273 ])
274 AT_CHECK([gzip -cd < $top_srcdir/tests/data/bcd-in.expected.cmp.gz | \
275             $PERL -pe "printf ' %04X ', $.-1" > expout])
276 AT_CHECK([pspp -O format=csv bcd-in.sps])
277 AT_CHECK([cat bcd-in.out], [0], [expout])
278 AT_CLEANUP
279
280 AT_SETUP([legacy input (N and Z formats)])
281 AT_CHECK([$PERL -e 'print pack "n", $_ foreach 0...65535' > legacy-in.data])
282 AT_CHECK([wc -c < legacy-in.data], [0], [131072
283 ])
284 AT_DATA([legacy-in.sps], [dnl
285 SET ERRORS=NONE.
286 SET MXWARNS=10000000.
287 SET MXERRS=10000000.
288 FILE HANDLE data/NAME='legacy-in.data'/MODE=IMAGE/LRECL=2.
289 DATA LIST NOTABLE FILE=data/n 1-2 (N) z 1-2 (z).
290 COMPUTE x=$CASENUM - 1.
291 PRINT OUTFILE='legacy-in.out'/x (PIBHEX4) ' ' N Z.
292 EXECUTE.
293 ])
294 AT_CHECK([gzip -cd < $top_srcdir/tests/data/legacy-in.expected.cmp.gz | \
295             $PERL -pe "printf ' %04X ', $.-1" > expout])
296 AT_CHECK([pspp -O format=csv legacy-in.sps])
297 AT_CHECK([cat legacy-in.out], [0], [expout])
298 AT_CLEANUP
299
300 AT_SETUP([WKDAY input format])
301 AT_DATA([wkday.sps], [dnl
302 DATA LIST NOTABLE /wkday2 1-2 (wkday)
303                    wkday3 1-3 (wkday)
304                    wkday4 1-4 (wkday)
305                    wkday5 1-5 (wkday)
306                    wkday6 1-6 (wkday)
307                    wkday7 1-7 (wkday)
308                    wkday8 1-8 (wkday)
309                    wkday9 1-9 (wkday)
310                    wkday10 1-10 (wkday).
311 BEGIN DATA.
312
313 .
314 monady
315 tuseday
316 WEDENSDAY
317 Thurdsay
318 fRidya
319 SAturady
320 sudnay
321 sturday
322 END DATA.
323 FORMATS ALL (WKDAY2).
324 PRINT OUTFILE='wkday.out'/ALL.
325 EXECUTE.
326 ])
327 AT_CHECK([pspp -O format=csv wkday.sps], [0], [dnl
328 wkday.sps:20.1-2: warning: Data for variable wkday2 is not valid as format WKDAY: Unrecognized weekday name.  At least the first two letters of an English weekday name must be specified.
329
330 wkday.sps:20.1-3: warning: Data for variable wkday3 is not valid as format WKDAY: Unrecognized weekday name.  At least the first two letters of an English weekday name must be specified.
331
332 wkday.sps:20.1-4: warning: Data for variable wkday4 is not valid as format WKDAY: Unrecognized weekday name.  At least the first two letters of an English weekday name must be specified.
333
334 wkday.sps:20.1-5: warning: Data for variable wkday5 is not valid as format WKDAY: Unrecognized weekday name.  At least the first two letters of an English weekday name must be specified.
335
336 wkday.sps:20.1-6: warning: Data for variable wkday6 is not valid as format WKDAY: Unrecognized weekday name.  At least the first two letters of an English weekday name must be specified.
337
338 wkday.sps:20.1-7: warning: Data for variable wkday7 is not valid as format WKDAY: Unrecognized weekday name.  At least the first two letters of an English weekday name must be specified.
339
340 wkday.sps:20.1-8: warning: Data for variable wkday8 is not valid as format WKDAY: Unrecognized weekday name.  At least the first two letters of an English weekday name must be specified.
341
342 wkday.sps:20.1-9: warning: Data for variable wkday9 is not valid as format WKDAY: Unrecognized weekday name.  At least the first two letters of an English weekday name must be specified.
343
344 wkday.sps:20.1-10: warning: Data for variable wkday10 is not valid as format WKDAY: Unrecognized weekday name.  At least the first two letters of an English weekday name must be specified.
345 ])
346 AT_CHECK([cat wkday.out], [0], [dnl
347   .  .  .  .  .  .  .  .  . @&t@
348   .  .  .  .  .  .  .  .  . @&t@
349  MO MO MO MO MO MO MO MO MO @&t@
350  TU TU TU TU TU TU TU TU TU @&t@
351  WE WE WE WE WE WE WE WE WE @&t@
352  TH TH TH TH TH TH TH TH TH @&t@
353  FR FR FR FR FR FR FR FR FR @&t@
354  SA SA SA SA SA SA SA SA SA @&t@
355  SU SU SU SU SU SU SU SU SU @&t@
356   .  .  .  .  .  .  .  .  . @&t@
357 ])
358 AT_CLEANUP
359
360 AT_SETUP([MONTH input format])
361 AT_DATA([month.sps], [dnl
362 DATA LIST NOTABLE /month3 1-3 (MONTH)
363                    month4 1-4 (MONTH)
364                    month5 1-5 (MONTH)
365                    month6 1-6 (MONTH)
366                    month7 1-7 (MONTH)
367                    month8 1-8 (MONTH)
368                    month9 1-9 (MONTH)
369                    month10 1-10 (MONTH).
370 BEGIN DATA.
371
372 .
373 i
374 ii
375 iii
376 iiii
377 iv
378 v
379 vi
380 vii
381 viii
382 ix
383 viiii
384 x
385 xi
386 xii
387 0
388 1
389 2
390 3
391 4
392 5
393 6
394 7
395 8
396 9
397 10
398 11
399 12
400 13
401 january
402 JANAURY
403 February
404 fEbraury
405 MArch
406 marhc
407 apRIL
408 may
409 june
410 july
411 august
412 september
413 october
414 november
415 decmeber
416 december
417 END DATA.
418 FORMATS ALL (MONTH3).
419 PRINT OUTFILE='month.out'/ALL.
420 EXECUTE.
421 ])
422 AT_CHECK([pspp -O format=csv month.sps], [0], [dnl
423 month.sps:15.1-4: warning: Data for variable month4 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
424
425 month.sps:15.1-5: warning: Data for variable month5 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
426
427 month.sps:15.1-6: warning: Data for variable month6 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
428
429 month.sps:15.1-7: warning: Data for variable month7 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
430
431 month.sps:15.1-8: warning: Data for variable month8 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
432
433 month.sps:15.1-9: warning: Data for variable month9 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
434
435 month.sps:15.1-10: warning: Data for variable month10 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
436
437 month.sps:26.1-3: warning: Data for variable month3 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
438
439 month.sps:26.1-4: warning: Data for variable month4 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
440
441 month.sps:26.1-5: warning: Data for variable month5 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
442
443 month.sps:26.1-6: warning: Data for variable month6 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
444
445 month.sps:26.1-7: warning: Data for variable month7 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
446
447 month.sps:26.1-8: warning: Data for variable month8 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
448
449 month.sps:26.1-9: warning: Data for variable month9 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
450
451 month.sps:26.1-10: warning: Data for variable month10 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
452
453 month.sps:39.1-3: warning: Data for variable month3 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
454
455 month.sps:39.1-4: warning: Data for variable month4 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
456
457 month.sps:39.1-5: warning: Data for variable month5 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
458
459 month.sps:39.1-6: warning: Data for variable month6 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
460
461 month.sps:39.1-7: warning: Data for variable month7 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
462
463 month.sps:39.1-8: warning: Data for variable month8 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
464
465 month.sps:39.1-9: warning: Data for variable month9 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
466
467 month.sps:39.1-10: warning: Data for variable month10 is not valid as format MONTH: Unrecognized month format.  Months may be specified as Arabic or Roman numerals or as at least 3 letters of their English names.
468 ])
469 AT_CHECK([cat month.out], [0], [dnl
470    .   .   .   .   .   .   .   . @&t@
471    .   .   .   .   .   .   .   . @&t@
472  JAN JAN JAN JAN JAN JAN JAN JAN @&t@
473  FEB FEB FEB FEB FEB FEB FEB FEB @&t@
474  MAR MAR MAR MAR MAR MAR MAR MAR @&t@
475  MAR   .   .   .   .   .   .   . @&t@
476  APR APR APR APR APR APR APR APR @&t@
477  MAY MAY MAY MAY MAY MAY MAY MAY @&t@
478  JUN JUN JUN JUN JUN JUN JUN JUN @&t@
479  JUL JUL JUL JUL JUL JUL JUL JUL @&t@
480  JUL AUG AUG AUG AUG AUG AUG AUG @&t@
481  SEP SEP SEP SEP SEP SEP SEP SEP @&t@
482  JUL AUG AUG AUG AUG AUG AUG AUG @&t@
483  OCT OCT OCT OCT OCT OCT OCT OCT @&t@
484  NOV NOV NOV NOV NOV NOV NOV NOV @&t@
485  DEC DEC DEC DEC DEC DEC DEC DEC @&t@
486    .   .   .   .   .   .   .   . @&t@
487  JAN JAN JAN JAN JAN JAN JAN JAN @&t@
488  FEB FEB FEB FEB FEB FEB FEB FEB @&t@
489  MAR MAR MAR MAR MAR MAR MAR MAR @&t@
490  APR APR APR APR APR APR APR APR @&t@
491  MAY MAY MAY MAY MAY MAY MAY MAY @&t@
492  JUN JUN JUN JUN JUN JUN JUN JUN @&t@
493  JUL JUL JUL JUL JUL JUL JUL JUL @&t@
494  AUG AUG AUG AUG AUG AUG AUG AUG @&t@
495  SEP SEP SEP SEP SEP SEP SEP SEP @&t@
496  OCT OCT OCT OCT OCT OCT OCT OCT @&t@
497  NOV NOV NOV NOV NOV NOV NOV NOV @&t@
498  DEC DEC DEC DEC DEC DEC DEC DEC @&t@
499    .   .   .   .   .   .   .   . @&t@
500  JAN JAN JAN JAN JAN JAN JAN JAN @&t@
501  JAN JAN JAN JAN JAN JAN JAN JAN @&t@
502  FEB FEB FEB FEB FEB FEB FEB FEB @&t@
503  FEB FEB FEB FEB FEB FEB FEB FEB @&t@
504  MAR MAR MAR MAR MAR MAR MAR MAR @&t@
505  MAR MAR MAR MAR MAR MAR MAR MAR @&t@
506  APR APR APR APR APR APR APR APR @&t@
507  MAY MAY MAY MAY MAY MAY MAY MAY @&t@
508  JUN JUN JUN JUN JUN JUN JUN JUN @&t@
509  JUL JUL JUL JUL JUL JUL JUL JUL @&t@
510  AUG AUG AUG AUG AUG AUG AUG AUG @&t@
511  SEP SEP SEP SEP SEP SEP SEP SEP @&t@
512  OCT OCT OCT OCT OCT OCT OCT OCT @&t@
513  NOV NOV NOV NOV NOV NOV NOV NOV @&t@
514  DEC DEC DEC DEC DEC DEC DEC DEC @&t@
515  DEC DEC DEC DEC DEC DEC DEC DEC @&t@
516 ])
517 AT_CLEANUP