From 1cc9ec74f2a7507d3230e366e027f03846095f59 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 4 Oct 2010 17:23:28 -0700 Subject: [PATCH] SORT CASES: Convert tests to Autotest framework. --- tests/automake.mk | 2 +- tests/command/sort.sh | 132 ----------------------------- tests/language/stats/sort-cases.at | 82 ++++++++++++++++++ 3 files changed, 83 insertions(+), 133 deletions(-) delete mode 100755 tests/command/sort.sh create mode 100644 tests/language/stats/sort-cases.at diff --git a/tests/automake.mk b/tests/automake.mk index bf673400..fa5c5365 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -10,7 +10,6 @@ TESTS_ENVIRONMENT += LC_ALL=C TESTS_ENVIRONMENT += EXEEXT=$(EXEEXT) dist_TESTS = \ - tests/command/sort.sh \ tests/command/sysfiles.sh \ tests/command/sysfiles-old.sh \ tests/command/sysfile-info.sh \ @@ -376,6 +375,7 @@ TESTSUITE_AT = \ tests/language/stats/regression.at \ tests/language/stats/reliability.at \ tests/language/stats/roc.at \ + tests/language/stats/sort-cases.at \ tests/language/utilities/insert.at \ tests/language/utilities/permissions.at \ tests/language/utilities/set.at \ diff --git a/tests/command/sort.sh b/tests/command/sort.sh deleted file mode 100755 index ffc55c21..00000000 --- a/tests/command/sort.sh +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/sh - -# This program tests the sort command - -TEMPDIR=/tmp/pspp-tst-$$ -TESTFILE=$TEMPDIR/`basename $0`.sps -: ${PERL:=perl} - -# ensure that top_builddir are absolute -if [ -z "$top_builddir" ] ; then top_builddir=. ; fi -if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi -top_builddir=`cd $top_builddir; pwd` -PSPP=$top_builddir/src/ui/terminal/pspp$EXEEXT - -# ensure that top_srcdir is absolute -top_srcdir=`cd $top_srcdir; pwd` - -STAT_CONFIG_PATH=$top_srcdir/config -export STAT_CONFIG_PATH - - -cleanup() -{ - if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then - echo "NOT cleaning $TEMPDIR" - return ; - fi - cd / - rm -rf $TEMPDIR -} - - -fail() -{ - echo $activity - echo FAILED - cleanup; - exit 1; -} - - -no_result() -{ - echo $activity - echo NO RESULT; - cleanup; - exit 2; -} - -pass() -{ - cleanup; - exit 0; -} - -mkdir -p $TEMPDIR - -cd $TEMPDIR - -activity="write perl program for generating data" -cat > gen-data.pl <<'EOF' -use strict; -use warnings; - -# Generate shuffled data. -my (@data); -for my $i (0...$ARGV[0] - 1) { - push (@data, $i) foreach 1...$ARGV[1]; -} -fisher_yates_shuffle (\@data); - -# Output shuffled data. -my (@shuffled) = map ([$data[$_], $_], 0...$#data); -open (SHUFFLED, ">sort.in"); -print SHUFFLED "$data[$_] $_\n" foreach 0...$#data; - -# Output sorted data. -my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled; -open (SORTED, ">sort.exp"); -print SORTED "$_->[0] $_->[1]\n" foreach @sorted; - -# From perlfaq4. -sub fisher_yates_shuffle { - my $deck = shift; # $deck is a reference to an array - my $i = @$deck; - while ($i--) { - my $j = int rand ($i+1); - @$deck[$i,$j] = @$deck[$j,$i]; - } -} -EOF - -for count_repeat_buffers in \ - "100 5 2" "100 5 3" "100 5 4" "100 5 5" "100 5 10" "100 5 50" "100 5 100" "100 5" \ - "100 10 2" "100 10 3" "100 10 5" "100 10" \ - "1000 5 5" "1000 5 50" "1000 5" \ - "100 100 3" "100 100 5" "100 100" \ - "10000 5 500" \ - "50000 1"; do - set $count_repeat_buffers - count=$1 - repeat=$2 - buffers=$3 - - printf . - - activity="generate data for $count_repeat_buffers run" - $PERL gen-data.pl $count $repeat > sort.data - if [ $? -ne 0 ] ; then no_result ; fi - - activity="generate test program for $count_repeat_buffers run" - { - echo "data list list file='sort.in'/x y (f8)." - if test "$buffers" != ""; then - echo "sort by x/buffers=$buffers." - else - echo "sort by x." - fi - echo "print outfile='sort.out'/x y." - echo "execute." - } > sort.pspp || no_result - - activity="run program" - $SUPERVISOR $PSPP --testing-mode -o pspp.csv sort.pspp - if [ $? -ne 0 ] ; then no_result ; fi - - perl -pi -e 's/^\s*$//g' sort.exp sort.out - diff -w sort.exp sort.out - if [ $? -ne 0 ] ; then fail ; fi -done -echo -pass; diff --git a/tests/language/stats/sort-cases.at b/tests/language/stats/sort-cases.at new file mode 100644 index 00000000..d06f2b29 --- /dev/null +++ b/tests/language/stats/sort-cases.at @@ -0,0 +1,82 @@ +AT_BANNER([SORT CASES]) + +m4_divert_push([PREPARE_TESTS]) +[sort_cases_gen_data () { + cat > gen-data.pl <<'EOF' +use strict; +use warnings; + +# Generate shuffled data. +my (@data); +for my $i (0...$ARGV[0] - 1) { + push (@data, ($i) x $ARGV[1]); +} +fisher_yates_shuffle (\@data); + +# Output shuffled data. +my (@shuffled) = map ([$data[$_], $_], 0...$#data); +open (SHUFFLED, ">data.txt"); +print SHUFFLED "$data[$_] $_\n" foreach 0...$#data; + +# Output sorted data. +my (@sorted) = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @shuffled; +open (SORTED, ">expout"); +printf SORTED " %8d %8d \n", $_->[0], $_->[1] foreach @sorted; + +# From perlfaq4. +sub fisher_yates_shuffle { + my $deck = shift; # $deck is a reference to an array + my $i = @$deck; + while ($i--) { + my $j = int rand ($i+1); + @$deck[$i,$j] = @$deck[$j,$i]; + } +} +EOF + $PERL gen-data.pl "$@"] +} +m4_divert_pop([PREPARE_TESTS]) + +m4_define([SORT_CASES_TEST], + [AT_SETUP([sort m4_eval([$1 * $2]) cases[]m4_if([$2], [1], [], [ ($1 unique)])[]m4_if([$3], [], [], [ with $3 buffers])]) + AT_KEYWORDS([SORT CASES]) + AT_CHECK([sort_cases_gen_data $1 $2 $3]) + AT_CAPTURE_FILE([data.txt]) + AT_CAPTURE_FILE([output.txt]) + AT_CAPTURE_FILE([sort-cases.sps]) + AT_DATA([sort-cases.sps], [dnl +DATA LIST LIST NOTABLE FILE='data.txt'/x y (F8). +SORT BY x[]m4_if([$3], [], [], [/BUFFERS=$3]). +PRINT OUTFILE='output.txt'/x y. +EXECUTE. +]) + AT_CHECK([pspp --testing-mode -o pspp.csv sort-cases.sps]) + AT_CHECK([cat output.txt], [0], [expout]) + AT_CLEANUP]) + +SORT_CASES_TEST(100, 5, 2) +SORT_CASES_TEST(100, 5, 3) +SORT_CASES_TEST(100, 5, 4) +SORT_CASES_TEST(100, 5, 5) +SORT_CASES_TEST(100, 5, 10) +SORT_CASES_TEST(100, 5, 50) +SORT_CASES_TEST(100, 5, 100) +SORT_CASES_TEST(100, 5) + +SORT_CASES_TEST(100, 10, 2) +SORT_CASES_TEST(100, 10, 3) +SORT_CASES_TEST(100, 10, 5) +SORT_CASES_TEST(100, 10) + +SORT_CASES_TEST(1000, 5, 5) +SORT_CASES_TEST(1000, 5, 50) +SORT_CASES_TEST(1000, 5) + +SORT_CASES_TEST(100, 100, 3) +SORT_CASES_TEST(100, 100, 5) +SORT_CASES_TEST(100, 100) + +SORT_CASES_TEST(10000, 5, 500) + +SORT_CASES_TEST(50000, 1) + -- 2.30.2