Checkin of new directory structure.
[pspp-builds.git] / tests / command / sort.sh
1 #!/bin/sh
2
3 # This program tests the sort command
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_builddir  are absolute
9 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
10 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
11 top_builddir=`cd $top_builddir; pwd`
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
20 cleanup()
21 {
22      cd /
23      rm -rf $TEMPDIR
24 }
25
26
27 fail()
28 {
29     echo $activity
30     echo FAILED
31     cleanup;
32     exit 1;
33 }
34
35
36 no_result()
37 {
38     echo $activity
39     echo NO RESULT;
40     cleanup;
41     exit 2;
42 }
43
44 pass()
45 {
46     cleanup;
47     exit 0;
48 }
49
50 mkdir -p $TEMPDIR
51
52 cd $TEMPDIR
53
54 activity="write perl program for generating data"
55 cat > gen-data.pl <<'EOF'
56 use strict;
57 use warnings;
58
59 # Generate shuffled data.
60 my (@data);
61 for my $i (0...$ARGV[0] - 1) {
62     push (@data, $i) foreach 1...$ARGV[1];
63 }
64 fisher_yates_shuffle (\@data);
65
66 # Output shuffled data.
67 my (@shuffled) = map ([$data[$_], $_], 0...$#data);
68 open (SHUFFLED, ">sort.in");
69 print SHUFFLED "$data[$_] $_\n" foreach 0...$#data;
70
71 # Output sorted data.
72 my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled;
73 open (SORTED, ">sort.exp");
74 print SORTED "$_->[0] $_->[1]\n" foreach @sorted;
75
76 # From perlfaq4.
77 sub fisher_yates_shuffle {
78     my $deck = shift;  # $deck is a reference to an array
79     my $i = @$deck;
80     while ($i--) {
81         my $j = int rand ($i+1);
82         @$deck[$i,$j] = @$deck[$j,$i];
83     }
84 }
85 EOF
86
87 for count_repeat_buffers in \
88     "100 5 2" "100 5 3" "100 5 4" "100 5 5" "100 5 10" "100 5 50" "100 5 100" "100 5" \
89     "100 10 2" "100 10 3" "100 10 5" "100 10" \
90     "1000 5 5" "1000 5 50" "1000 5" \
91     "100 100 3" "100 100 5" "100 100" \
92     "10000 5 500" \
93     "50000 1"; do
94   set $count_repeat_buffers
95   count=$1
96   repeat=$2
97   buffers=$3
98
99   printf .
100
101   activity="generate data for $count_repeat_buffers run"
102   $PERL gen-data.pl $count $repeat > sort.data
103   if [ $? -ne 0 ] ; then no_result ; fi
104   
105   activity="generate test program for $count_repeat_buffers run"
106   {
107       echo "data list list file='sort.in'/x y (f8)."
108       if test "$buffers" != ""; then
109           echo "sort by x/buffers=$buffers."
110       else
111           echo "sort by x."
112       fi
113       echo "print outfile='sort.out'/x y."
114       echo "execute."
115   } > sort.pspp || no_result
116   
117   activity="run program"
118   $SUPERVISOR $top_builddir/src/pspp --testing-mode -o raw-ascii sort.pspp
119   if [ $? -ne 0 ] ; then no_result ; fi
120   
121   perl -pi -e 's/^\s*$//g' sort.exp sort.out
122   diff -w sort.exp sort.out
123   if [ $? -ne 0 ] ; then fail ; fi
124 done
125 echo
126 pass;