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
50 activity="write perl program for generating data"
51 cat > gen-data.pl <<'EOF'
55 # Generate shuffled data.
57 for my $i (0...$ARGV[0] - 1) {
58 push (@data, $i) foreach 1...$ARGV[1];
60 fisher_yates_shuffle (\@data);
62 # Output shuffled data.
63 my (@shuffled) = map ([$data[$_], $_], 0...$#data);
64 open (SHUFFLED, ">sort.in");
65 print SHUFFLED "$data[$_] $_\n" foreach 0...$#data;
68 my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled;
69 open (SORTED, ">sort.exp");
70 print SORTED "$_->[0] $_->[1]\n" foreach @sorted;
73 sub fisher_yates_shuffle {
74 my $deck = shift; # $deck is a reference to an array
77 my $j = int rand ($i+1);
78 @$deck[$i,$j] = @$deck[$j,$i];
83 for count_repeat_buffers in \
84 "100 5 2" "100 5 3" "100 5 4" "100 5 5" "100 5 10" "100 5 50" "100 5 100" "100 5" \
85 "100 10 2" "100 10 3" "100 10 5" "100 10" \
86 "1000 5 5" "1000 5 50" "1000 5" \
87 "100 100 3" "100 100 5" "100 100" \
90 set $count_repeat_buffers
97 activity="generate data for $count_repeat_buffers run"
98 $PERL gen-data.pl $count $repeat > sort.data
99 if [ $? -ne 0 ] ; then no_result ; fi
101 activity="generate test program for $count_repeat_buffers run"
103 echo "data list list file='sort.in'/x y (f8)."
104 if test "$buffers" != ""; then
105 echo "sort by x/buffers=$buffers."
109 echo "print outfile='sort.out'/x y."
111 } > sort.pspp || no_result
113 activity="run program"
114 $SUPERVISOR $here/../src/pspp --testing-mode -o raw-ascii sort.pspp
115 if [ $? -ne 0 ] ; then no_result ; fi
117 diff -B -w sort.exp sort.out
118 if [ $? -ne 0 ] ; then fail ; fi