3 # This program tests the sort command
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
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
14 # ensure that top_srcdir is absolute
15 top_srcdir=`cd $top_srcdir; pwd`
17 STAT_CONFIG_PATH=$top_srcdir/config
18 export STAT_CONFIG_PATH
55 activity="write perl program for generating data"
56 cat > gen-data.pl <<'EOF'
60 # Generate shuffled data.
62 for my $i (0...$ARGV[0] - 1) {
63 push (@data, $i) foreach 1...$ARGV[1];
65 fisher_yates_shuffle (\@data);
67 # Output shuffled data.
68 my (@shuffled) = map ([$data[$_], $_], 0...$#data);
69 open (SHUFFLED, ">sort.in");
70 print SHUFFLED "$data[$_] $_\n" foreach 0...$#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;
78 sub fisher_yates_shuffle {
79 my $deck = shift; # $deck is a reference to an array
82 my $j = int rand ($i+1);
83 @$deck[$i,$j] = @$deck[$j,$i];
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" \
95 set $count_repeat_buffers
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
106 activity="generate test program for $count_repeat_buffers run"
108 echo "data list list file='sort.in'/x y (f8)."
109 if test "$buffers" != ""; then
110 echo "sort by x/buffers=$buffers."
114 echo "print outfile='sort.out'/x y."
116 } > sort.pspp || no_result
118 activity="run program"
119 $SUPERVISOR $PSPP --testing-mode -o raw-ascii sort.pspp
120 if [ $? -ne 0 ] ; then no_result ; fi
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