3 TEMPDIR=/tmp/pspp-tst-$$
5 trap 'cd /; rm -rf $TEMPDIR' 0
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
13 # ensure that top_srcdir is absolute
14 top_srcdir=`cd $top_srcdir; pwd`
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
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.
56 my ($tmp) = $a * $seed;
57 $seed = $tmp - $m * int ($tmp / $m);
58 return $seed % $modulo;
61 if [ $? -ne 0 ] ; then no_result ; fi
63 activity="write PRNG test program"
64 cat > test-my-rand.pl <<'EOF'
69 my_rand (1) foreach 1...10000;
71 die $seed if $seed != 1043618065;
73 if [ $? -ne 0 ] ; then no_result ; fi
77 if [ $? -ne 0 ] ; then no_result ; fi
79 activity="write program to generate PSPP syntax and data"
80 cat > date-in.pl <<'EOF'
88 my @formats = (['date', 'd-m-y'],
96 ['datetime', 'd-m-y +H:M', 'd-m-y +H:M:S']);
98 my @dates = (#yyyy mm dd jjj HH MM SS
99 [1648, 6, 10, 162, 0, 0, 0],
100 [1680, 6, 30, 182, 4, 50, 38],
101 [1716, 7, 24, 206, 12, 31, 35],
102 [1768, 6, 19, 171, 12, 47, 53],
103 [1819, 8, 2, 214, 1, 26, 0],
104 [1839, 3, 27, 86, 20, 58, 11],
105 [1903, 4, 19, 109, 7, 36, 5],
106 [1929, 8, 25, 237, 15, 43, 49],
107 [1941, 9, 29, 272, 4, 25, 9],
108 [1943, 4, 19, 109, 6, 49, 27],
109 [1943, 10, 7, 280, 2, 57, 52],
110 [1992, 3, 17, 77, 16, 45, 44],
111 [1996, 2, 25, 56, 21, 30, 57],
112 [1941, 9, 29, 272, 4, 25, 9],
113 [1943, 4, 19, 109, 6, 49, 27],
114 [1943, 10, 7, 280, 2, 57, 52],
115 [1992, 3, 17, 77, 16, 45, 44],
116 [1996, 2, 25, 56, 21, 30, 57],
117 [2038, 11, 10, 314, 22, 30, 4],
118 [2094, 7, 18, 199, 1, 56, 51]);
120 open (SYNTAX, '>', 'date-in.pspp') or die "date-in.pspp: create: $!\n";
121 print SYNTAX "SET EPOCH 1930.\n";
122 for my $format (@formats) {
123 my ($name) = @$format;
124 print SYNTAX "DATA LIST file='$name.data'/$name 1-40 ($name).\n";
125 print SYNTAX "PRINT OUTFILE='$name.out'/$name (F16.2).\n";
126 print SYNTAX "EXECUTE.\n";
130 for my $format (@formats) {
131 my ($fmt_name, @templates) = @$format;
132 my ($fn) = "$fmt_name.data";
133 open (DATA, '>', $fn) or die "$fn: create: $!\n";
135 for my $template (@templates) {
136 for my $date (@dates) {
137 print_date_with_template ($date, $template) for 1...10;
143 sub print_date_with_template {
144 my ($date, $template) = @_;
145 my ($year, $month, $day, $julian, $hour, $minute, $second) = @$date;
146 my ($quarter) = int (($month - 1) / 3) + 1;
147 my ($week) = int (($julian - 1) / 7) + 1;
148 my (@year_types) = ('full');
149 push (@year_types, '2digit') if $year >= 1930 && $year < 2030;
150 for my $c (split ('', $template)) {
152 printf (+pick ('%d', '%02d'), $day);
153 } elsif ($c eq 'm') {
154 my ($type) = pick ('arabic', 'roman', 'abbrev', 'full');
155 if ($type eq 'arabic') {
156 printf (+pick ('%d', '%02d'), $month);
157 } elsif ($type eq 'roman') {
158 my ($mmm) = ('i', 'ii', 'iii',
161 'x', 'xi', 'xii')[$month - 1];
162 print_rand_case ($mmm);
163 } elsif ($type eq 'abbrev') {
164 my ($mmm) = qw (jan feb mar apr may jun
165 jul aug sep oct nov dec)[$month - 1];
166 print_rand_case ($mmm);
167 } elsif ($type eq 'full') {
168 my ($mmm) = qw (january february march
170 july august september
171 october november december)[$month - 1];
172 print_rand_case ($mmm);
176 } elsif ($c eq 'y') {
177 my ($type) = pick (@year_types);
178 if ($type eq '2digit') {
179 printf (+pick ('%d', '%02d'), $year % 100);
180 } elsif ($type eq 'full') {
185 } elsif ($c eq 'j') {
186 my ($type) = pick (@year_types);
187 if ($type eq '2digit') {
188 printf ("%02d%03d", $year % 100, $julian);
189 } elsif ($type eq 'full') {
190 printf ("%04d%03d", $year, $julian);
194 } elsif ($c eq 'q') {
196 } elsif ($c eq 'w') {
198 } elsif ($c eq 'H') {
199 printf (+pick ('%d', '%02d'), $hour);
200 } elsif ($c eq 'M') {
201 printf (+pick ('%d', '%02d'), $minute);
202 } elsif ($c eq 'S') {
203 printf (+pick ('%d', '%02d'), $second);
204 } elsif ($c eq '-') {
205 print +pick (' ', '-', '.', ',', '/');
206 } elsif ($c eq ':') {
207 print +pick (' ', ':');
208 } elsif ($c eq ' ') {
210 } elsif ($c eq 'Q') {
211 maybe_print_space ();
212 print_rand_case ('q');
213 maybe_print_space ();
214 } elsif ($c eq 'W') {
215 maybe_print_space ();
216 print_rand_case ('wk');
217 maybe_print_space ();
218 } elsif ($c eq '+') {
219 print +pick ('', '-', '+');
227 sub print_rand_case {
229 my ($case) = pick (qw (uc lc tc));
232 } elsif ($case eq 'lc') {
234 } elsif ($case eq 'tc') {
241 sub maybe_print_space {
242 print +pick ('', ' ');
246 return $_[int (my_rand ($#_ + 1))];
249 if [ $? -ne 0 ] ; then no_result ; fi
251 activity="generate PSPP syntax and data"
253 if [ $? -ne 0 ] ; then no_result ; fi
255 activity="run program"
256 $SUPERVISOR $PSPP --testing-mode date-in.pspp
257 if [ $? -ne 0 ] ; then no_result ; fi
259 activity="compare adate.out output"
260 diff -u adate.out - <<EOF
462 if [ $? -ne 0 ] ; then fail ; fi
464 activity="compare date.out output"
465 diff -u date.out - <<EOF
667 if [ $? -ne 0 ] ; then fail ; fi
669 activity="compare datetime.out output"
670 diff -u datetime.out - <<EOF
1072 if [ $? -ne 0 ] ; then fail ; fi
1074 activity="compare edate.out output"
1075 diff -u edate.out - <<EOF
1277 if [ $? -ne 0 ] ; then fail ; fi
1279 activity="compare jdate.out output"
1280 diff -u jdate.out - <<EOF
1482 if [ $? -ne 0 ] ; then fail ; fi
1484 activity="compare moyr.out output"
1485 diff -u moyr.out - <<EOF
1687 if [ $? -ne 0 ] ; then fail ; fi
1689 activity="compare qyr.out output"
1690 diff -u qyr.out - <<EOF
1892 if [ $? -ne 0 ] ; then fail ; fi
1894 activity="compare sdate.out output"
1895 diff -u sdate.out - <<EOF
2097 if [ $? -ne 0 ] ; then fail ; fi
2099 activity="compare wkyr.out output"
2100 diff -u wkyr.out - <<EOF
2302 if [ $? -ne 0 ] ; then fail ; fi