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