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$EXEEXT
14 # ensure that top_srcdir is absolute
15 top_srcdir=`cd $top_srcdir; pwd`
17 STAT_CONFIG_PATH=$top_srcdir/config
18 export STAT_CONFIG_PATH
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.
57 my ($tmp) = $a * $seed;
58 $seed = $tmp - $m * int ($tmp / $m);
59 return $seed % $modulo;
62 if [ $? -ne 0 ] ; then no_result ; fi
64 activity="write PRNG test program"
65 cat > test-my-rand.pl <<'EOF'
70 my_rand (1) foreach 1...10000;
72 die $seed if $seed != 1043618065;
74 if [ $? -ne 0 ] ; then no_result ; fi
78 if [ $? -ne 0 ] ; then no_result ; fi
80 activity="write program to generate PSPP syntax and data"
81 cat > date-in.pl <<'EOF'
89 my @formats = (['date', 'd-m-y'],
97 ['datetime', 'd-m-y +H:M', 'd-m-y +H:M:S']);
99 my @dates = (#yyyy mm dd jjj HH MM SS
100 [1648, 6, 10, 162, 0, 0, 0],
101 [1680, 6, 30, 182, 4, 50, 38],
102 [1716, 7, 24, 206, 12, 31, 35],
103 [1768, 6, 19, 171, 12, 47, 53],
104 [1819, 8, 2, 214, 1, 26, 0],
105 [1839, 3, 27, 86, 20, 58, 11],
106 [1903, 4, 19, 109, 7, 36, 5],
107 [1929, 8, 25, 237, 15, 43, 49],
108 [1941, 9, 29, 272, 4, 25, 9],
109 [1943, 4, 19, 109, 6, 49, 27],
110 [1943, 10, 7, 280, 2, 57, 52],
111 [1992, 3, 17, 77, 16, 45, 44],
112 [1996, 2, 25, 56, 21, 30, 57],
113 [1941, 9, 29, 272, 4, 25, 9],
114 [1943, 4, 19, 109, 6, 49, 27],
115 [1943, 10, 7, 280, 2, 57, 52],
116 [1992, 3, 17, 77, 16, 45, 44],
117 [1996, 2, 25, 56, 21, 30, 57],
118 [2038, 11, 10, 314, 22, 30, 4],
119 [2094, 7, 18, 199, 1, 56, 51]);
121 open (SYNTAX, '>', 'date-in.pspp') or die "date-in.pspp: create: $!\n";
122 print SYNTAX "SET EPOCH 1930.\n";
123 for my $format (@formats) {
124 my ($name) = @$format;
125 print SYNTAX "DATA LIST file='$name.data'/$name 1-40 ($name).\n";
126 print SYNTAX "PRINT OUTFILE='$name.out'/$name (F16.2).\n";
127 print SYNTAX "EXECUTE.\n";
131 for my $format (@formats) {
132 my ($fmt_name, @templates) = @$format;
133 my ($fn) = "$fmt_name.data";
134 open (DATA, '>', $fn) or die "$fn: create: $!\n";
136 for my $template (@templates) {
137 for my $date (@dates) {
138 print_date_with_template ($date, $template) for 1...10;
144 sub print_date_with_template {
145 my ($date, $template) = @_;
146 my ($year, $month, $day, $julian, $hour, $minute, $second) = @$date;
147 my ($quarter) = int (($month - 1) / 3) + 1;
148 my ($week) = int (($julian - 1) / 7) + 1;
149 my (@year_types) = ('full');
150 push (@year_types, '2digit') if $year >= 1930 && $year < 2030;
151 for my $c (split ('', $template)) {
153 printf (+pick ('%d', '%02d'), $day);
154 } elsif ($c eq 'm') {
155 my ($type) = pick ('arabic', 'roman', 'abbrev', 'full');
156 if ($type eq 'arabic') {
157 printf (+pick ('%d', '%02d'), $month);
158 } elsif ($type eq 'roman') {
159 my ($mmm) = ('i', 'ii', 'iii',
162 'x', 'xi', 'xii')[$month - 1];
163 print_rand_case ($mmm);
164 } elsif ($type eq 'abbrev') {
165 my ($mmm) = qw (jan feb mar apr may jun
166 jul aug sep oct nov dec)[$month - 1];
167 print_rand_case ($mmm);
168 } elsif ($type eq 'full') {
169 my ($mmm) = qw (january february march
171 july august september
172 october november december)[$month - 1];
173 print_rand_case ($mmm);
177 } elsif ($c eq 'y') {
178 my ($type) = pick (@year_types);
179 if ($type eq '2digit') {
180 printf (+pick ('%d', '%02d'), $year % 100);
181 } elsif ($type eq 'full') {
186 } elsif ($c eq 'j') {
187 my ($type) = pick (@year_types);
188 if ($type eq '2digit') {
189 printf ("%02d%03d", $year % 100, $julian);
190 } elsif ($type eq 'full') {
191 printf ("%04d%03d", $year, $julian);
195 } elsif ($c eq 'q') {
197 } elsif ($c eq 'w') {
199 } elsif ($c eq 'H') {
200 printf (+pick ('%d', '%02d'), $hour);
201 } elsif ($c eq 'M') {
202 printf (+pick ('%d', '%02d'), $minute);
203 } elsif ($c eq 'S') {
204 printf (+pick ('%d', '%02d'), $second);
205 } elsif ($c eq '-') {
206 print +pick (' ', '-', '.', ',', '/');
207 } elsif ($c eq ':') {
208 print +pick (' ', ':');
209 } elsif ($c eq ' ') {
211 } elsif ($c eq 'Q') {
212 maybe_print_space ();
213 print_rand_case ('q');
214 maybe_print_space ();
215 } elsif ($c eq 'W') {
216 maybe_print_space ();
217 print_rand_case ('wk');
218 maybe_print_space ();
219 } elsif ($c eq '+') {
220 print +pick ('', '-', '+');
228 sub print_rand_case {
230 my ($case) = pick (qw (uc lc tc));
233 } elsif ($case eq 'lc') {
235 } elsif ($case eq 'tc') {
242 sub maybe_print_space {
243 print +pick ('', ' ');
247 return $_[int (my_rand ($#_ + 1))];
250 if [ $? -ne 0 ] ; then no_result ; fi
252 activity="generate PSPP syntax and data"
254 if [ $? -ne 0 ] ; then no_result ; fi
256 activity="run program"
257 $SUPERVISOR $PSPP -o pspp.csv date-in.pspp
258 if [ $? -ne 0 ] ; then no_result ; fi
260 activity="compare adate.out output"
261 diff -u adate.out - <<EOF
463 if [ $? -ne 0 ] ; then fail ; fi
465 activity="compare date.out output"
466 diff -u date.out - <<EOF
668 if [ $? -ne 0 ] ; then fail ; fi
670 activity="compare datetime.out output"
671 diff -u datetime.out - <<EOF
1073 if [ $? -ne 0 ] ; then fail ; fi
1075 activity="compare edate.out output"
1076 diff -u edate.out - <<EOF
1278 if [ $? -ne 0 ] ; then fail ; fi
1280 activity="compare jdate.out output"
1281 diff -u jdate.out - <<EOF
1483 if [ $? -ne 0 ] ; then fail ; fi
1485 activity="compare moyr.out output"
1486 diff -u moyr.out - <<EOF
1688 if [ $? -ne 0 ] ; then fail ; fi
1690 activity="compare qyr.out output"
1691 diff -u qyr.out - <<EOF
1893 if [ $? -ne 0 ] ; then fail ; fi
1895 activity="compare sdate.out output"
1896 diff -u sdate.out - <<EOF
2098 if [ $? -ne 0 ] ; then fail ; fi
2100 activity="compare wkyr.out output"
2101 diff -u wkyr.out - <<EOF
2303 if [ $? -ne 0 ] ; then fail ; fi