0c9a7195c536f2c733eb127b13f177daae695af6
[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$EXEEXT
12 : ${PERL:=perl}
13
14 # ensure that top_srcdir is absolute
15 top_srcdir=`cd $top_srcdir; pwd`
16
17 STAT_CONFIG_PATH=$top_srcdir/config
18 export STAT_CONFIG_PATH
19
20 fail()
21 {
22     echo $activity
23     echo FAILED
24     exit 1;
25 }
26
27
28 no_result()
29 {
30     echo $activity
31     echo NO RESULT;
32     exit 2;
33 }
34
35 pass()
36 {
37     exit 0;
38 }
39
40 cd $TEMPDIR
41
42 activity="write PRNG fragment"
43 cat > my-rand.pl <<'EOF'
44 # This random number generator and the test for it below are drawn
45 # from Park and Miller, "Random Number Generators: Good Ones are Hard
46 # to Come By", Communications of the ACM 31:10 (October 1988).  It is
47 # documented to function properly on systems with a 46-bit or longer
48 # real significand, which includes systems that have 64-bit IEEE reals
49 # (with 53-bit significand).  The test should catch any systems for
50 # which this is not true, in any case.
51
52 our ($seed) = 1;
53 sub my_rand {
54   my ($modulo) = @_;
55   my ($a) = 16807;
56   my ($m) = 2147483647;
57   my ($tmp) = $a * $seed;
58   $seed = $tmp - $m * int ($tmp / $m);
59   return $seed % $modulo;
60 }
61 EOF
62 if [ $? -ne 0 ] ; then no_result ; fi
63
64 activity="write PRNG test program"
65 cat > test-my-rand.pl <<'EOF'
66 #! /usr/bin/perl
67 use strict;
68 use warnings;
69 do 'my-rand.pl';
70 my_rand (1) foreach 1...10000;
71 our $seed;
72 die $seed if $seed != 1043618065;
73 EOF
74 if [ $? -ne 0 ] ; then no_result ; fi
75
76 activity="test PRNG"
77 $PERL test-my-rand.pl
78 if [ $? -ne 0 ] ; then no_result ; fi
79
80 activity="write program to generate PSPP syntax and data"
81 cat > time-in.pl <<'EOF'
82 #! /usr/bin/perl
83
84 use strict;
85 use warnings;
86
87 do 'my-rand.pl';
88
89 my @formats = (["time", "+H:M", "+H:M:S"],
90                ["dtime", "+D H:M", "+D H:M:S"]);
91
92 my @times = (#  D  HH  MM     SS
93              [  0,  0,  0,  0.00],
94              [  1,  4, 50, 38.68],
95              [  5, 12, 31, 35.82],
96              [  0, 12, 47, 53.41],
97              [  3,  1, 26,  0.69],
98              [  1, 20, 58, 11.19],
99              [ 12,  7, 36,  5.98],
100              [ 52, 15, 43, 49.27],
101              [  7,  4, 25,  9.24],
102              [  0,  6, 49, 27.89],
103              [ 20,  2, 57, 52.56],
104              [555, 16, 45, 44.12],
105              [120, 21, 30, 57.27],
106              [  0,  4, 25,  9.98],
107              [  3,  6, 49, 27.24],
108              [  5,  2, 57, 52.13],
109              [  0, 16, 45, 44.35],
110              [  1, 21, 30, 57.32],
111              [ 10, 22, 30,  4.27],
112              [ 22,  1, 56, 51.18]);
113
114 open (SYNTAX, '>', 'time-in.pspp') or die "time-in.pspp: create: $!\n";
115 for my $format (@formats) {
116     my ($name) = @$format;
117     print SYNTAX "DATA LIST file='$name.data'/$name 1-40 ($name).\n";
118     print SYNTAX "PRINT OUTFILE='$name.out'/$name (F16.2).\n";
119     print SYNTAX "EXECUTE.\n";
120 }
121 close (SYNTAX);
122
123 for my $format (@formats) {
124     my ($fmt_name, @templates) = @$format;
125     my ($fn) = "$fmt_name.data";
126     open (DATA, '>', $fn) or die "$fn: create: $!\n";
127     select DATA;
128     for my $template (@templates) {
129         for my $time (@times) {
130             print_time_with_template ($time, $template) for 1...10;
131         }
132     }
133     close (DATA);
134 }
135
136 sub print_time_with_template {
137     my ($time, $template) = @_;
138     my ($day, $hour, $minute, $second) = @$time;
139     for my $c (split ('', $template)) {
140         if ($c eq '+') {
141             print +pick ('', '-', '+');
142         } elsif ($c eq 'D') {
143             printf (+pick ('%d', '%02d'), $day);
144             $day = 0;
145         } elsif ($c eq 'H') {
146             printf (+pick ('%d', '%02d'), $hour + 24 * $day);
147         } elsif ($c eq 'M') {
148             printf (+pick ('%d', '%02d'), $minute);
149         } elsif ($c eq 'S') {
150             printf (+pick ('%.0f', '%02.0f', '%.1f', '%.2f'), $second);
151         } elsif ($c eq ':') {
152             print +pick (' ', ':');
153         } elsif ($c eq ' ') {
154             print ' ';
155         } else {
156             die;
157         }
158     }
159     print "\n";
160 }
161
162 sub pick {
163    return $_[int (my_rand ($#_ + 1))];
164 }
165 EOF
166 if [ $? -ne 0 ] ; then no_result ; fi
167
168 activity="generate PSPP syntax and data"
169 $PERL time-in.pl
170 if [ $? -ne 0 ] ; then no_result ; fi
171
172 activity="run program"
173 $SUPERVISOR $PSPP -o pspp.csv time-in.pspp
174 if [ $? -ne 0 ] ; then no_result ; fi
175
176 activity="compare time.out output"
177 diff -u time.out - <<EOF
178               .00
179               .00
180               .00
181               .00
182               .00
183               .00
184               .00
185               .00
186               .00
187               .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         103800.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        -477060.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         -46020.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        -264360.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        -161880.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        1064160.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        4549380.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         620700.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          24540.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        1738620.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       48012300.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      -10445400.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          15900.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         283740.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        -442620.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         -60300.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         163800.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         945000.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       -1907760.00
378               .00
379               .00
380               .00
381               .00
382               .00
383               .00
384               .00
385               .00
386               .00
387               .00
388         103839.00
389         103838.68
390        -103838.70
391        -103838.68
392         103838.70
393         103838.68
394        -103839.00
395         103838.68
396         103838.70
397        -103839.00
398         477095.82
399         477096.00
400         477096.00
401         477095.82
402         477095.82
403         477095.82
404         477095.80
405        -477095.80
406         477095.82
407        -477095.82
408         -46073.00
409         -46073.40
410          46073.00
411          46073.40
412          46073.40
413          46073.00
414         -46073.00
415          46073.00
416          46073.00
417          46073.00
418         264360.69
419        -264360.70
420         264361.00
421         264360.70
422         264360.69
423         264360.70
424         264361.00
425         264360.70
426        -264361.00
427         264361.00
428         161891.00
429        -161891.20
430        -161891.00
431         161891.00
432        -161891.00
433         161891.20
434        -161891.20
435        -161891.20
436         161891.20
437        -161891.19
438       -1064166.00
439        1064165.98
440       -1064166.00
441       -1064166.00
442       -1064165.98
443        1064166.00
444        1064166.00
445       -1064166.00
446       -1064165.98
447        1064166.00
448        4549429.00
449        4549429.27
450        4549429.27
451       -4549429.30
452        4549429.00
453       -4549429.00
454        4549429.00
455        4549429.27
456        4549429.00
457        4549429.30
458         620709.00
459        -620709.24
460         620709.24
461         620709.24
462         620709.24
463         620709.20
464        -620709.24
465         620709.20
466         620709.24
467         620709.24
468          24567.90
469          24567.89
470          24567.90
471          24568.00
472          24567.90
473          24568.00
474          24568.00
475         -24567.90
476          24567.90
477          24568.00
478        1738672.56
479        1738673.00
480       -1738672.60
481       -1738672.56
482        1738673.00
483        1738673.00
484        1738673.00
485        1738672.60
486       -1738672.56
487        1738672.60
488      -48012344.10
489       48012344.12
490      -48012344.10
491      -48012344.00
492      -48012344.00
493       48012344.00
494      -48012344.00
495      -48012344.00
496      -48012344.00
497       48012344.00
498       10445457.27
499       10445457.00
500       10445457.30
501       10445457.00
502       10445457.27
503       10445457.00
504       10445457.27
505       10445457.00
506       10445457.00
507      -10445457.30
508         -15909.98
509          15910.00
510         -15910.00
511          15910.00
512         -15909.98
513          15910.00
514         -15909.98
515          15909.98
516          15910.00
517          15909.98
518        -283767.00
519         283767.20
520         283767.20
521         283767.00
522        -283767.00
523         283767.00
524         283767.24
525         283767.00
526         283767.24
527         283767.00
528        -442672.00
529         442672.13
530         442672.00
531         442672.13
532         442672.00
533         442672.00
534         442672.00
535         442672.00
536        -442672.00
537         442672.13
538         -60344.40
539         -60344.00
540          60344.00
541          60344.35
542          60344.00
543          60344.40
544          60344.40
545         -60344.00
546          60344.00
547          60344.40
548         163857.00
549         163857.00
550         163857.00
551         163857.00
552         163857.30
553        -163857.30
554         163857.30
555        -163857.00
556        -163857.00
557         163857.30
558         945004.30
559         945004.00
560         945004.27
561         945004.30
562         945004.30
563         945004.00
564         945004.30
565         945004.00
566         945004.00
567         945004.00
568        1907811.00
569        1907811.00
570       -1907811.00
571        1907811.18
572        1907811.20
573        1907811.00
574       -1907811.00
575        1907811.18
576       -1907811.00
577       -1907811.00
578 EOF
579 if [ $? -ne 0 ] ; then fail ; fi
580
581 activity="compare dtime.out output"
582 diff -u dtime.out - <<EOF
583               .00
584               .00
585               .00
586               .00
587               .00
588               .00
589               .00
590               .00
591               .00
592               .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        -103800.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         477060.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          46020.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        -264360.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        -161880.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        1064160.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        4549380.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         620700.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         -24540.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        1738620.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      -48012300.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       10445400.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          15900.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        -283740.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         442620.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          60300.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        -163800.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        -945000.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       -1907760.00
783               .00
784               .00
785               .00
786               .00
787               .00
788               .00
789               .00
790               .00
791               .00
792               .00
793         103838.70
794         103838.70
795         103839.00
796         103838.68
797         103838.70
798         103839.00
799         103838.70
800        -103839.00
801         103839.00
802         103839.00
803         477095.80
804         477095.80
805        -477095.80
806         477095.82
807         477095.82
808         477095.82
809        -477095.82
810         477095.82
811         477096.00
812        -477096.00
813         -46073.00
814          46073.00
815         -46073.00
816          46073.41
817          46073.00
818          46073.40
819          46073.00
820          46073.41
821          46073.41
822         -46073.00
823         264360.70
824         264360.70
825         264360.69
826         264361.00
827        -264360.70
828         264360.69
829        -264360.70
830         264360.69
831        -264361.00
832         264360.69
833         161891.00
834        -161891.20
835        -161891.19
836         161891.19
837         161891.00
838         161891.20
839         161891.20
840         161891.00
841         161891.00
842         161891.20
843       -1064165.98
844        1064166.00
845        1064166.00
846        1064166.00
847        1064165.98
848        1064166.00
849        1064166.00
850       -1064165.98
851        1064165.98
852       -1064166.00
853        4549429.27
854        4549429.27
855        4549429.27
856        4549429.27
857        4549429.00
858        4549429.27
859       -4549429.27
860        4549429.00
861        4549429.27
862        4549429.27
863        -620709.00
864         620709.20
865         620709.00
866        -620709.20
867        -620709.24
868        -620709.00
869         620709.00
870         620709.24
871        -620709.24
872         620709.00
873         -24567.89
874          24567.90
875          24568.00
876          24567.89
877          24568.00
878          24568.00
879          24567.90
880         -24568.00
881         -24567.89
882         -24568.00
883        1738672.56
884       -1738672.56
885        1738672.56
886       -1738672.60
887       -1738673.00
888        1738672.56
889        1738673.00
890       -1738672.60
891        1738672.60
892        1738672.56
893       48012344.00
894      -48012344.12
895      -48012344.00
896       48012344.12
897      -48012344.12
898      -48012344.00
899       48012344.12
900      -48012344.00
901      -48012344.00
902      -48012344.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.00
912      -10445457.30
913         -15909.98
914          15910.00
915         -15909.98
916          15910.00
917          15910.00
918         -15910.00
919         -15910.00
920         -15910.00
921         -15910.00
922          15909.98
923        -283767.24
924         283767.20
925         283767.24
926         283767.24
927         283767.00
928         283767.20
929         283767.20
930         283767.24
931        -283767.00
932         283767.24
933         442672.13
934        -442672.13
935         442672.00
936         442672.13
937         442672.10
938         442672.00
939         442672.00
940        -442672.10
941         442672.00
942        -442672.10
943         -60344.35
944          60344.00
945          60344.00
946         -60344.00
947          60344.00
948          60344.35
949          60344.00
950          60344.35
951          60344.00
952          60344.00
953        -163857.00
954        -163857.00
955         163857.32
956         163857.00
957        -163857.30
958        -163857.00
959         163857.30
960         163857.00
961         163857.00
962        -163857.00
963        -945004.00
964        -945004.30
965         945004.27
966         945004.27
967        -945004.27
968        -945004.27
969        -945004.00
970        -945004.27
971        -945004.00
972         945004.30
973        1907811.00
974        1907811.00
975        1907811.00
976        1907811.00
977        1907811.20
978        1907811.18
979        1907811.18
980        1907811.18
981        1907811.18
982        1907811.00
983 EOF
984 if [ $? -ne 0 ] ; then fail ; fi
985
986 pass