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`
13 # ensure that top_srcdir is absolute
14 top_srcdir=`cd $top_srcdir; pwd`
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
54 activity="write perl program for generating data"
55 cat > gen-data.pl <<'EOF'
59 # Generate shuffled data.
61 for my $i (0...$ARGV[0] - 1) {
62 push (@data, $i) foreach 1...$ARGV[1];
64 fisher_yates_shuffle (\@data);
66 # Output shuffled data.
67 my (@shuffled) = map ([$data[$_], $_], 0...$#data);
68 open (SHUFFLED, ">sort.in");
69 print SHUFFLED "$data[$_] $_\n" foreach 0...$#data;
72 my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled;
73 open (SORTED, ">sort.exp");
74 print SORTED "$_->[0] $_->[1]\n" foreach @sorted;
77 sub fisher_yates_shuffle {
78 my $deck = shift; # $deck is a reference to an array
81 my $j = int rand ($i+1);
82 @$deck[$i,$j] = @$deck[$j,$i];
87 for count_repeat_buffers in \
88 "100 5 2" "100 5 3" "100 5 4" "100 5 5" "100 5 10" "100 5 50" "100 5 100" "100 5" \
89 "100 10 2" "100 10 3" "100 10 5" "100 10" \
90 "1000 5 5" "1000 5 50" "1000 5" \
91 "100 100 3" "100 100 5" "100 100" \
94 set $count_repeat_buffers
101 activity="generate data for $count_repeat_buffers run"
102 $PERL gen-data.pl $count $repeat > sort.data
103 if [ $? -ne 0 ] ; then no_result ; fi
105 activity="generate test program for $count_repeat_buffers run"
107 echo "data list list file='sort.in'/x y (f8)."
108 if test "$buffers" != ""; then
109 echo "sort by x/buffers=$buffers."
113 echo "print outfile='sort.out'/x y."
115 } > sort.pspp || no_result
117 activity="run program"
118 $SUPERVISOR $top_builddir/src/pspp --testing-mode -o raw-ascii sort.pspp
119 if [ $? -ne 0 ] ; then no_result ; fi
121 perl -pi -e 's/^\s*$//g' sort.exp sort.out
122 diff -w sort.exp sort.out
123 if [ $? -ne 0 ] ; then fail ; fi