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
56 activity="write perl program for generating data"
57 cat > gen-data.pl <<'EOF'
61 # Generate shuffled data.
63 for my $i (0...$ARGV[0] - 1) {
64 push (@data, $i) foreach 1...$ARGV[1];
66 fisher_yates_shuffle (\@data);
68 # Output shuffled data.
69 my (@shuffled) = map ([$data[$_], $_], 0...$#data);
70 open (SHUFFLED, ">sort.in");
71 print SHUFFLED "$data[$_] $_\n" foreach 0...$#data;
74 my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled;
75 open (SORTED, ">sort.exp");
76 print SORTED "$_->[0] $_->[1]\n" foreach @sorted;
79 sub fisher_yates_shuffle {
80 my $deck = shift; # $deck is a reference to an array
83 my $j = int rand ($i+1);
84 @$deck[$i,$j] = @$deck[$j,$i];
89 for count_repeat_buffers in \
90 "100 5 2" "100 5 3" "100 5 4" "100 5 5" "100 5 10" "100 5 50" "100 5 100" "100 5" \
91 "100 10 2" "100 10 3" "100 10 5" "100 10" \
92 "1000 5 5" "1000 5 50" "1000 5" \
93 "100 100 3" "100 100 5" "100 100" \
96 set $count_repeat_buffers
103 activity="generate data for $count_repeat_buffers run"
104 $PERL gen-data.pl $count $repeat > sort.data
105 if [ $? -ne 0 ] ; then no_result ; fi
107 activity="generate test program for $count_repeat_buffers run"
109 echo "data list list file='sort.in'/x y (f8)."
110 if test "$buffers" != ""; then
111 echo "sort by x/buffers=$buffers."
115 echo "print outfile='sort.out'/x y."
117 } > sort.pspp || no_result
119 activity="run program"
120 $SUPERVISOR $PSPP --testing-mode sort.pspp
121 if [ $? -ne 0 ] ; then no_result ; fi
123 perl -pi -e 's/^\s*$//g' sort.exp sort.out
124 diff -w sort.exp sort.out
125 if [ $? -ne 0 ] ; then fail ; fi