3 # This program tests the sort command
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
9 # ensure that top_builddir are absolute
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
12 top_builddir=`cd $top_builddir; pwd`
13 PSPP=$top_builddir/src/ui/terminal/pspp
15 # ensure that top_srcdir is absolute
16 top_srcdir=`cd $top_srcdir; pwd`
18 STAT_CONFIG_PATH=$top_srcdir/config
19 export STAT_CONFIG_PATH
24 if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then
25 echo "NOT cleaning $TEMPDIR"
60 activity="write perl program for generating data"
61 cat > gen-data.pl <<'EOF'
65 # Generate shuffled data.
67 for my $i (0...$ARGV[0] - 1) {
68 push (@data, $i) foreach 1...$ARGV[1];
70 fisher_yates_shuffle (\@data);
72 # Output shuffled data.
73 my (@shuffled) = map ([$data[$_], $_], 0...$#data);
74 open (SHUFFLED, ">sort.in");
75 print SHUFFLED "$data[$_] $_\n" foreach 0...$#data;
78 my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled;
79 open (SORTED, ">sort.exp");
80 print SORTED "$_->[0] $_->[1]\n" foreach @sorted;
83 sub fisher_yates_shuffle {
84 my $deck = shift; # $deck is a reference to an array
87 my $j = int rand ($i+1);
88 @$deck[$i,$j] = @$deck[$j,$i];
93 for count_repeat_buffers in \
94 "100 5 2" "100 5 3" "100 5 4" "100 5 5" "100 5 10" "100 5 50" "100 5 100" "100 5" \
95 "100 10 2" "100 10 3" "100 10 5" "100 10" \
96 "1000 5 5" "1000 5 50" "1000 5" \
97 "100 100 3" "100 100 5" "100 100" \
100 set $count_repeat_buffers
107 activity="generate data for $count_repeat_buffers run"
108 $PERL gen-data.pl $count $repeat > sort.data
109 if [ $? -ne 0 ] ; then no_result ; fi
111 activity="generate test program for $count_repeat_buffers run"
113 echo "data list list file='sort.in'/x y (f8)."
114 if test "$buffers" != ""; then
115 echo "sort by x/buffers=$buffers."
119 echo "print outfile='sort.out'/x y."
121 } > sort.pspp || no_result
123 activity="run program"
124 $SUPERVISOR $PSPP --testing-mode sort.pspp
125 if [ $? -ne 0 ] ; then no_result ; fi
127 perl -pi -e 's/^\s*$//g' sort.exp sort.out
128 diff -w sort.exp sort.out
129 if [ $? -ne 0 ] ; then fail ; fi