Fix bug #18982. Thanks to John Darrington for investigation,
[pspp-builds.git] / tests / formats / time-in.sh
1 #! /bin/sh
2
3 TEMPDIR=/tmp/pspp-tst-$$
4 mkdir -p $TEMPDIR
5 trap 'cd /; rm -rf $TEMPDIR' 0
6
7 # ensure that top_builddir  are absolute
8 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 top_builddir=`cd $top_builddir; pwd`
11 PSPP=$top_builddir/src/ui/terminal/pspp
12
13 # ensure that top_srcdir is absolute
14 top_srcdir=`cd $top_srcdir; pwd`
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19 fail()
20 {
21     echo $activity
22     echo FAILED
23     exit 1;
24 }
25
26
27 no_result()
28 {
29     echo $activity
30     echo NO RESULT;
31     exit 2;
32 }
33
34 pass()
35 {
36     exit 0;
37 }
38
39 cd $TEMPDIR
40
41 activity="write PRNG fragment"
42 cat > my-rand.pl <<'EOF'
43 # This random number generator and the test for it below are drawn
44 # from Park and Miller, "Random Number Generators: Good Ones are Hard
45 # to Come By", Communications of the ACM 31:10 (October 1988).  It is
46 # documented to function properly on systems with a 46-bit or longer
47 # real significand, which includes systems that have 64-bit IEEE reals
48 # (with 53-bit significand).  The test should catch any systems for
49 # which this is not true, in any case.
50
51 our ($seed) = 1;
52 sub my_rand {
53   my ($modulo) = @_;
54   my ($a) = 16807;
55   my ($m) = 2147483647;
56   my ($tmp) = $a * $seed;
57   $seed = $tmp - $m * int ($tmp / $m);
58   return $seed % $modulo;
59 }
60 EOF
61 if [ $? -ne 0 ] ; then no_result ; fi
62
63 activity="write PRNG test program"
64 cat > test-my-rand.pl <<'EOF'
65 #! /usr/bin/perl
66 use strict;
67 use warnings;
68 do 'my-rand.pl';
69 my_rand (1) foreach 1...10000;
70 our $seed;
71 die $seed if $seed != 1043618065;
72 EOF
73 if [ $? -ne 0 ] ; then no_result ; fi
74
75 activity="test PRNG"
76 $PERL test-my-rand.pl
77 if [ $? -ne 0 ] ; then no_result ; fi
78
79 activity="write program to generate PSPP syntax and data"
80 cat > time-in.pl <<'EOF'
81 #! /usr/bin/perl
82
83 use strict;
84 use warnings;
85
86 do 'my-rand.pl';
87
88 my @formats = (["time", "+H:M", "+H:M:S"],
89                ["dtime", "+D H:M", "+D H:M:S"]);
90
91 my @times = (#  D  HH  MM     SS
92              [  0,  0,  0,  0.00],
93              [  1,  4, 50, 38.68],
94              [  5, 12, 31, 35.82],
95              [  0, 12, 47, 53.41],
96              [  3,  1, 26,  0.69],
97              [  1, 20, 58, 11.19],
98              [ 12,  7, 36,  5.98],
99              [ 52, 15, 43, 49.27],
100              [  7,  4, 25,  9.24],
101              [  0,  6, 49, 27.89],
102              [ 20,  2, 57, 52.56],
103              [555, 16, 45, 44.12],
104              [120, 21, 30, 57.27],
105              [  0,  4, 25,  9.98],
106              [  3,  6, 49, 27.24],
107              [  5,  2, 57, 52.13],
108              [  0, 16, 45, 44.35],
109              [  1, 21, 30, 57.32],
110              [ 10, 22, 30,  4.27],
111              [ 22,  1, 56, 51.18]);
112
113 open (SYNTAX, '>', 'time-in.pspp') or die "time-in.pspp: create: $!\n";
114 for my $format (@formats) {
115     my ($name) = @$format;
116     print SYNTAX "DATA LIST file='$name.data'/$name 1-40 ($name).\n";
117     print SYNTAX "PRINT OUTFILE='$name.out'/$name (F16.2).\n";
118     print SYNTAX "EXECUTE.\n";
119 }
120 close (SYNTAX);
121
122 for my $format (@formats) {
123     my ($fmt_name, @templates) = @$format;
124     my ($fn) = "$fmt_name.data";
125     open (DATA, '>', $fn) or die "$fn: create: $!\n";
126     select DATA;
127     for my $template (@templates) {
128         for my $time (@times) {
129             print_time_with_template ($time, $template) for 1...10;
130         }
131     }
132     close (DATA);
133 }
134
135 sub print_time_with_template {
136     my ($time, $template) = @_;
137     my ($day, $hour, $minute, $second) = @$time;
138     for my $c (split ('', $template)) {
139         if ($c eq '+') {
140             print +pick ('', '-', '+');
141         } elsif ($c eq 'D') {
142             printf (+pick ('%d', '%02d'), $day);
143             $day = 0;
144         } elsif ($c eq 'H') {
145             printf (+pick ('%d', '%02d'), $hour + 24 * $day);
146         } elsif ($c eq 'M') {
147             printf (+pick ('%d', '%02d'), $minute);
148         } elsif ($c eq 'S') {
149             printf (+pick ('%.0f', '%02.0f', '%.1f', '%.2f'), $second);
150         } elsif ($c eq ':') {
151             print +pick (' ', ':');
152         } elsif ($c eq ' ') {
153             print ' ';
154         } else {
155             die;
156         }
157     }
158     print "\n";
159 }
160
161 sub pick {
162    return $_[int (my_rand ($#_ + 1))];
163 }
164 EOF
165 if [ $? -ne 0 ] ; then no_result ; fi
166
167 activity="generate PSPP syntax and data"
168 $PERL time-in.pl
169 if [ $? -ne 0 ] ; then no_result ; fi
170
171 activity="run program"
172 $SUPERVISOR $PSPP --testing-mode time-in.pspp
173 if [ $? -ne 0 ] ; then no_result ; fi
174
175 activity="compare time.out output"
176 diff -u time.out - <<EOF
177               .00
178               .00
179               .00
180               .00
181               .00
182               .00
183               .00
184               .00
185               .00
186               .00
187        -103800.00
188         103800.00
189         103800.00
190        -103800.00
191         103800.00
192        -103800.00
193         103800.00
194         103800.00
195        -103800.00
196         103800.00
197         477060.00
198         477060.00
199         477060.00
200         477060.00
201        -477060.00
202         477060.00
203         477060.00
204         477060.00
205         477060.00
206        -477060.00
207          46020.00
208         -46020.00
209         -46020.00
210         -46020.00
211          46020.00
212          46020.00
213         -46020.00
214          46020.00
215          46020.00
216         -46020.00
217         264360.00
218         264360.00
219        -264360.00
220        -264360.00
221         264360.00
222        -264360.00
223         264360.00
224        -264360.00
225        -264360.00
226        -264360.00
227         161880.00
228         161880.00
229         161880.00
230         161880.00
231         161880.00
232        -161880.00
233         161880.00
234         161880.00
235         161880.00
236        -161880.00
237        1064160.00
238        1064160.00
239        1064160.00
240        1064160.00
241        1064160.00
242        1064160.00
243       -1064160.00
244        1064160.00
245        1064160.00
246        1064160.00
247       -4549380.00
248        4549380.00
249        4549380.00
250        4549380.00
251        4549380.00
252        4549380.00
253        4549380.00
254       -4549380.00
255        4549380.00
256        4549380.00
257         620700.00
258        -620700.00
259         620700.00
260         620700.00
261        -620700.00
262         620700.00
263        -620700.00
264        -620700.00
265         620700.00
266         620700.00
267          24540.00
268         -24540.00
269          24540.00
270          24540.00
271          24540.00
272          24540.00
273          24540.00
274          24540.00
275          24540.00
276          24540.00
277       -1738620.00
278        1738620.00
279        1738620.00
280        1738620.00
281        1738620.00
282        1738620.00
283        1738620.00
284        1738620.00
285        1738620.00
286        1738620.00
287       48012300.00
288      -48012300.00
289      -48012300.00
290       48012300.00
291       48012300.00
292       48012300.00
293       48012300.00
294       48012300.00
295       48012300.00
296       48012300.00
297       10445400.00
298      -10445400.00
299      -10445400.00
300       10445400.00
301       10445400.00
302       10445400.00
303      -10445400.00
304       10445400.00
305       10445400.00
306      -10445400.00
307          15900.00
308          15900.00
309         -15900.00
310          15900.00
311         -15900.00
312         -15900.00
313          15900.00
314          15900.00
315          15900.00
316          15900.00
317         283740.00
318        -283740.00
319         283740.00
320         283740.00
321         283740.00
322        -283740.00
323         283740.00
324         283740.00
325        -283740.00
326         283740.00
327         442620.00
328         442620.00
329         442620.00
330         442620.00
331         442620.00
332         442620.00
333         442620.00
334         442620.00
335         442620.00
336        -442620.00
337          60300.00
338          60300.00
339          60300.00
340          60300.00
341          60300.00
342         -60300.00
343         -60300.00
344          60300.00
345         -60300.00
346         -60300.00
347         163800.00
348        -163800.00
349        -163800.00
350        -163800.00
351         163800.00
352         163800.00
353         163800.00
354         163800.00
355        -163800.00
356         163800.00
357         945000.00
358        -945000.00
359        -945000.00
360        -945000.00
361         945000.00
362         945000.00
363         945000.00
364        -945000.00
365         945000.00
366         945000.00
367       -1907760.00
368        1907760.00
369       -1907760.00
370        1907760.00
371       -1907760.00
372        1907760.00
373        1907760.00
374        1907760.00
375        1907760.00
376       -1907760.00
377               .00
378               .00
379               .00
380               .00
381               .00
382               .00
383               .00
384               .00
385               .00
386               .00
387         103839.00
388         103838.68
389        -103838.70
390        -103838.68
391         103838.70
392         103838.68
393        -103839.00
394         103838.68
395         103838.70
396        -103839.00
397         477095.82
398         477096.00
399         477096.00
400         477095.82
401         477095.82
402         477095.82
403         477095.80
404        -477095.80
405         477095.82
406        -477095.82
407         -46073.00
408         -46073.40
409          46073.00
410          46073.40
411          46073.40
412          46073.00
413         -46073.00
414          46073.00
415          46073.00
416          46073.00
417         264360.69
418        -264360.70
419         264361.00
420         264360.70
421         264360.69
422         264360.70
423         264361.00
424         264360.70
425        -264361.00
426         264361.00
427         161891.00
428        -161891.20
429        -161891.00
430         161891.00
431        -161891.00
432         161891.20
433        -161891.20
434        -161891.20
435         161891.20
436        -161891.19
437       -1064166.00
438        1064165.98
439       -1064166.00
440       -1064166.00
441       -1064165.98
442        1064166.00
443        1064166.00
444       -1064166.00
445       -1064165.98
446        1064166.00
447        4549429.00
448        4549429.27
449        4549429.27
450       -4549429.30
451        4549429.00
452       -4549429.00
453        4549429.00
454        4549429.27
455        4549429.00
456        4549429.30
457         620709.00
458        -620709.24
459         620709.24
460         620709.24
461         620709.24
462         620709.20
463        -620709.24
464         620709.20
465         620709.24
466         620709.24
467          24567.90
468          24567.89
469          24567.90
470          24568.00
471          24567.90
472          24568.00
473          24568.00
474         -24567.90
475          24567.90
476          24568.00
477        1738672.56
478        1738673.00
479       -1738672.60
480       -1738672.56
481        1738673.00
482        1738673.00
483        1738673.00
484        1738672.60
485       -1738672.56
486        1738672.60
487      -48012344.10
488       48012344.12
489      -48012344.10
490      -48012344.00
491      -48012344.00
492       48012344.00
493      -48012344.00
494      -48012344.00
495      -48012344.00
496       48012344.00
497       10445457.27
498       10445457.00
499       10445457.30
500       10445457.00
501       10445457.27
502       10445457.00
503       10445457.27
504       10445457.00
505       10445457.00
506      -10445457.30
507         -15909.98
508          15910.00
509         -15910.00
510          15910.00
511         -15909.98
512          15910.00
513         -15909.98
514          15909.98
515          15910.00
516          15909.98
517        -283767.00
518         283767.20
519         283767.20
520         283767.00
521        -283767.00
522         283767.00
523         283767.24
524         283767.00
525         283767.24
526         283767.00
527        -442672.00
528         442672.13
529         442672.00
530         442672.13
531         442672.00
532         442672.00
533         442672.00
534         442672.00
535        -442672.00
536         442672.13
537         -60344.40
538         -60344.00
539          60344.00
540          60344.35
541          60344.00
542          60344.40
543          60344.40
544         -60344.00
545          60344.00
546          60344.40
547         163857.00
548         163857.00
549         163857.00
550         163857.00
551         163857.30
552        -163857.30
553         163857.30
554        -163857.00
555        -163857.00
556         163857.30
557         945004.30
558         945004.00
559         945004.27
560         945004.30
561         945004.30
562         945004.00
563         945004.30
564         945004.00
565         945004.00
566         945004.00
567        1907811.00
568        1907811.00
569       -1907811.00
570        1907811.18
571        1907811.20
572        1907811.00
573       -1907811.00
574        1907811.18
575       -1907811.00
576       -1907811.00
577 EOF
578 if [ $? -ne 0 ] ; then fail ; fi
579
580 activity="compare dtime.out output"
581 diff -u dtime.out - <<EOF
582               .00
583               .00
584               .00
585               .00
586               .00
587               .00
588               .00
589               .00
590               .00
591               .00
592         103800.00
593         103800.00
594        -103800.00
595         103800.00
596         103800.00
597        -103800.00
598         103800.00
599        -103800.00
600         103800.00
601        -103800.00
602         477060.00
603         477060.00
604         477060.00
605         477060.00
606         477060.00
607         477060.00
608        -477060.00
609        -477060.00
610        -477060.00
611         477060.00
612          46020.00
613          46020.00
614          46020.00
615          46020.00
616         -46020.00
617         -46020.00
618         -46020.00
619          46020.00
620          46020.00
621          46020.00
622         264360.00
623         264360.00
624        -264360.00
625         264360.00
626         264360.00
627         264360.00
628         264360.00
629        -264360.00
630        -264360.00
631        -264360.00
632        -161880.00
633        -161880.00
634         161880.00
635         161880.00
636         161880.00
637        -161880.00
638         161880.00
639        -161880.00
640         161880.00
641        -161880.00
642        1064160.00
643        1064160.00
644        1064160.00
645        1064160.00
646        1064160.00
647        1064160.00
648       -1064160.00
649        1064160.00
650        1064160.00
651        1064160.00
652       -4549380.00
653        4549380.00
654       -4549380.00
655       -4549380.00
656       -4549380.00
657        4549380.00
658        4549380.00
659        4549380.00
660        4549380.00
661        4549380.00
662        -620700.00
663         620700.00
664         620700.00
665        -620700.00
666         620700.00
667         620700.00
668         620700.00
669        -620700.00
670         620700.00
671         620700.00
672         -24540.00
673          24540.00
674          24540.00
675          24540.00
676         -24540.00
677          24540.00
678          24540.00
679         -24540.00
680          24540.00
681         -24540.00
682        1738620.00
683        1738620.00
684        1738620.00
685       -1738620.00
686       -1738620.00
687       -1738620.00
688        1738620.00
689        1738620.00
690        1738620.00
691        1738620.00
692       48012300.00
693       48012300.00
694       48012300.00
695       48012300.00
696       48012300.00
697      -48012300.00
698      -48012300.00
699       48012300.00
700      -48012300.00
701      -48012300.00
702      -10445400.00
703       10445400.00
704      -10445400.00
705       10445400.00
706       10445400.00
707       10445400.00
708       10445400.00
709       10445400.00
710       10445400.00
711       10445400.00
712          15900.00
713          15900.00
714          15900.00
715          15900.00
716          15900.00
717         -15900.00
718          15900.00
719          15900.00
720          15900.00
721          15900.00
722        -283740.00
723         283740.00
724        -283740.00
725        -283740.00
726         283740.00
727         283740.00
728         283740.00
729         283740.00
730         283740.00
731        -283740.00
732         442620.00
733        -442620.00
734        -442620.00
735         442620.00
736         442620.00
737        -442620.00
738        -442620.00
739        -442620.00
740         442620.00
741         442620.00
742          60300.00
743         -60300.00
744          60300.00
745          60300.00
746          60300.00
747          60300.00
748          60300.00
749          60300.00
750          60300.00
751          60300.00
752         163800.00
753         163800.00
754        -163800.00
755         163800.00
756        -163800.00
757        -163800.00
758        -163800.00
759         163800.00
760         163800.00
761        -163800.00
762         945000.00
763         945000.00
764         945000.00
765         945000.00
766        -945000.00
767         945000.00
768         945000.00
769         945000.00
770         945000.00
771        -945000.00
772       -1907760.00
773        1907760.00
774        1907760.00
775        1907760.00
776       -1907760.00
777       -1907760.00
778       -1907760.00
779        1907760.00
780       -1907760.00
781       -1907760.00
782               .00
783               .00
784               .00
785               .00
786               .00
787               .00
788               .00
789               .00
790               .00
791               .00
792         103838.70
793         103838.70
794         103839.00
795         103838.68
796         103838.70
797         103839.00
798         103838.70
799        -103839.00
800         103839.00
801         103839.00
802         477095.80
803         477095.80
804        -477095.80
805         477095.82
806         477095.82
807         477095.82
808        -477095.82
809         477095.82
810         477096.00
811        -477096.00
812         -46073.00
813          46073.00
814         -46073.00
815          46073.41
816          46073.00
817          46073.40
818          46073.00
819          46073.41
820          46073.41
821         -46073.00
822         264360.70
823         264360.70
824         264360.69
825         264361.00
826        -264360.70
827         264360.69
828        -264360.70
829         264360.69
830        -264361.00
831         264360.69
832         161891.00
833        -161891.20
834        -161891.19
835         161891.19
836         161891.00
837         161891.20
838         161891.20
839         161891.00
840         161891.00
841         161891.20
842       -1064165.98
843        1064166.00
844        1064166.00
845        1064166.00
846        1064165.98
847        1064166.00
848        1064166.00
849       -1064165.98
850        1064165.98
851       -1064166.00
852        4549429.27
853        4549429.27
854        4549429.27
855        4549429.27
856        4549429.00
857        4549429.27
858       -4549429.27
859        4549429.00
860        4549429.27
861        4549429.27
862        -620709.00
863         620709.20
864         620709.00
865        -620709.20
866        -620709.24
867        -620709.00
868         620709.00
869         620709.24
870        -620709.24
871         620709.00
872         -24567.89
873          24567.90
874          24568.00
875          24567.89
876          24568.00
877          24568.00
878          24567.90
879         -24568.00
880         -24567.89
881         -24568.00
882        1738672.56
883       -1738672.56
884        1738672.56
885       -1738672.60
886       -1738673.00
887        1738672.56
888        1738673.00
889       -1738672.60
890        1738672.60
891        1738672.56
892       48012344.00
893      -48012344.12
894      -48012344.00
895       48012344.12
896      -48012344.12
897      -48012344.00
898       48012344.12
899      -48012344.00
900      -48012344.00
901      -48012344.00
902      -10445457.00
903       10445457.00
904       10445457.00
905       10445457.00
906      -10445457.00
907      -10445457.00
908       10445457.00
909       10445457.00
910       10445457.00
911      -10445457.30
912         -15909.98
913          15910.00
914         -15909.98
915          15910.00
916          15910.00
917         -15910.00
918         -15910.00
919         -15910.00
920         -15910.00
921          15909.98
922        -283767.24
923         283767.20
924         283767.24
925         283767.24
926         283767.00
927         283767.20
928         283767.20
929         283767.24
930        -283767.00
931         283767.24
932         442672.13
933        -442672.13
934         442672.00
935         442672.13
936         442672.10
937         442672.00
938         442672.00
939        -442672.10
940         442672.00
941        -442672.10
942         -60344.35
943          60344.00
944          60344.00
945         -60344.00
946          60344.00
947          60344.35
948          60344.00
949          60344.35
950          60344.00
951          60344.00
952        -163857.00
953        -163857.00
954         163857.32
955         163857.00
956        -163857.30
957        -163857.00
958         163857.30
959         163857.00
960         163857.00
961        -163857.00
962        -945004.00
963        -945004.30
964         945004.27
965         945004.27
966        -945004.27
967        -945004.27
968        -945004.00
969        -945004.27
970        -945004.00
971         945004.30
972        1907811.00
973        1907811.00
974        1907811.00
975        1907811.00
976        1907811.20
977        1907811.18
978        1907811.18
979        1907811.18
980        1907811.18
981        1907811.00
982 EOF
983 if [ $? -ne 0 ] ; then fail ; fi
984
985 pass