3 # This program tests the sort command
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
10 # ensure that top_srcdir is absolute
11 cd $top_srcdir; top_srcdir=`pwd`
13 STAT_CONFIG_PATH=$top_srcdir/config
14 export STAT_CONFIG_PATH
51 activity="write perl program for generating data"
52 cat > gen-data.pl <<'EOF'
56 # Generate shuffled data.
58 for my $i (0...$ARGV[0] - 1) {
59 push (@data, $i) foreach 1...$ARGV[1];
61 fisher_yates_shuffle (\@data);
63 # Output shuffled data.
64 my (@shuffled) = map ([$data[$_], $_], 0...$#data);
65 open (SHUFFLED, ">sort.in");
66 print SHUFFLED "$data[$_] $_\n" foreach 0...$#data;
69 my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled;
70 open (SORTED, ">sort.exp");
71 print SORTED "$_->[0] $_->[1]\n" foreach @sorted;
74 sub fisher_yates_shuffle {
75 my $deck = shift; # $deck is a reference to an array
78 my $j = int rand ($i+1);
79 @$deck[$i,$j] = @$deck[$j,$i];
84 for count_repeat_buffers in \
85 "100 5 2" "100 5 3" "100 5 4" "100 5 5" "100 5 10" "100 5 50" "100 5 100" "100 5" \
86 "100 10 2" "100 10 3" "100 10 5" "100 10" \
87 "1000 5 5" "1000 5 50" "1000 5" \
88 "100 100 3" "100 100 5" "100 100" \
91 set $count_repeat_buffers
98 activity="generate data for $count_repeat_buffers run"
99 $PERL gen-data.pl $count $repeat > sort.data
100 if [ $? -ne 0 ] ; then no_result ; fi
102 activity="generate test program for $count_repeat_buffers run"
104 echo "data list list file='sort.in'/x y (f8)."
105 if test "$buffers" != ""; then
106 echo "sort by x/buffers=$buffers."
110 echo "print outfile='sort.out'/x y."
112 } > sort.pspp || no_result
114 activity="run program"
115 $SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii sort.pspp
116 if [ $? -ne 0 ] ; then no_result ; fi
118 perl -pi -e 's/^\s*$//g' sort.exp sort.out
119 diff -w sort.exp sort.out
120 if [ $? -ne 0 ] ; then fail ; fi