Added new tests
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 16 Dec 2003 08:59:04 +0000 (08:59 +0000)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 16 Dec 2003 08:59:04 +0000 (08:59 +0000)
tests/command/lag.sh [new file with mode: 0755]
tests/command/print.sh [new file with mode: 0755]
tests/command/sample.sh [new file with mode: 0755]
tests/command/split-file.sh [new file with mode: 0755]
tests/command/tabs.sh [new file with mode: 0755]

diff --git a/tests/command/lag.sh b/tests/command/lag.sh
new file mode 100755 (executable)
index 0000000..db7c296
--- /dev/null
@@ -0,0 +1,90 @@
+#!/bin/sh
+
+# This program tests the LAG function
+
+TEMPDIR=/tmp/pspp-tst-$$
+
+here=`pwd`;
+
+# ensure that top_srcdir is absolute
+cd $top_srcdir; top_srcdir=`pwd`
+
+export STAT_CONFIG_PATH=$top_srcdir/config
+
+
+cleanup()
+{
+     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="create program"
+cat > $TEMPDIR/lag.stat <<EOF
+data list /w 1.
+begin data.
+1
+2
+3
+4
+5
+end data.
+
+compute x=lag(w,1).
+compute y=lag(x).
+compute z=lag(w,2).
+list.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+activity="run program"
+$here/../src/pspp -o raw-ascii $TEMPDIR/lag.stat
+if [ $? -ne 0 ] ; then no_result ; fi
+
+activity="compare result"
+diff -b -B $TEMPDIR/pspp.list - <<EOF
+1.1 DATA LIST.  Reading 1 record from the command file.
++--------+------+-------+------+
+|Variable|Record|Columns|Format|
+#========#======#=======#======#
+|W       |     1|  1-  1|F1.0  |
++--------+------+-------+------+
+
+W        X        Y        Z
+- -------- -------- --------
+1      .        .        .   
+2     1.00      .        .   
+3     2.00     1.00     1.00 
+4     3.00     2.00     2.00 
+5     4.00     3.00     3.00 
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+
+pass;
diff --git a/tests/command/print.sh b/tests/command/print.sh
new file mode 100755 (executable)
index 0000000..538f5db
--- /dev/null
@@ -0,0 +1,232 @@
+#!/bin/sh
+
+# This program tests the PRINT transformation
+
+TEMPDIR=/tmp/pspp-tst-$$
+
+here=`pwd`;
+
+# ensure that top_srcdir is absolute
+cd $top_srcdir; top_srcdir=`pwd`
+
+export STAT_CONFIG_PATH=$top_srcdir/config
+
+
+cleanup()
+{
+     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
+
+# Copy this file --- it's shared with another test
+activity="create data"
+cp $here/data-list.data $TEMPDIR
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+activity="create program"
+cat > $TEMPFILE/print.stat <<EOF_print
+title 'Test PRINT transformation'.
+
+remark EOF
+----------------------------------------------------------------------
+There is no test for DATA LIST FIXED since it is imagined that the
+rest of the tests give it a pretty good workout.
+----------------------------------------------------------------------
+EOF
+remark EOF
+----------------------------------------------------------------------
+Testing use of DATA LIST FREE.
+----------------------------------------------------------------------
+EOF
+data list free table file='$TEMPDIR/data-list.data'/A B C D.
+print outfile="foo" table/A(f8.2) '/' B(e8.2) '/' C(n10) '/' D(rbhex16) '/'.
+print space a.
+print outfile="foo" /a b c d.
+list.
+
+remark EOF
+----------------------------------------------------------------------
+Testing use of DATA LIST LIST.
+----------------------------------------------------------------------
+EOF
+data list list table file='$TEMPDIR/data-list.data'/A B C D.
+print table/A B C D.
+list.
+
+EOF_print
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+activity="run program"
+$here/../src/pspp -o raw-ascii $TEMPFILE/print.stat > $TEMPDIR/errs
+# Note   vv   --- there are errors in input.  Therefore, the  command must FAIL
+if [ $? -eq 0 ] ; then fail ; fi
+
+activity="compare error messages"
+diff -w $TEMPDIR/errs - <<EOF
+$TEMPDIR/data-list.data:1: error: (columns 1-5, field type F8.0)
+        Field does not form a valid floating-point constant.
+$TEMPDIR/data-list.data:1: warning: LIST: The expression on PRINT
+        SPACE evaluated to -2147483648.  It's not possible to PRINT SPACE a
+        negative number of lines.
+$TEMPDIR/data-list.data:2: error: (columns 1-8, field type F8.0)
+        Field does not form a valid floating-point constant.
+$TEMPDIR/data-list.data:4: warning: LIST: The expression on PRINT
+        SPACE evaluated to -2147483648.  It's not possible to PRINT SPACE a
+        negative number of lines.
+$TEMPDIR/data-list.data:4: error: (columns 3-12, field type F8.0)
+        Field does not form a valid floating-point constant.
+$TEMPDIR/data-list.data:6: warning: LIST: The expression on PRINT
+        SPACE evaluated to -2147483648.  It's not possible to PRINT SPACE a
+        negative number of lines.
+$TEMPDIR/data-list.data:1: error: (columns 1-5, field type F8.0)
+        Field does not form a valid floating-point constant.
+$TEMPDIR/data-list.data:2: error: (columns 1-8, field type F8.0)
+        Field does not form a valid floating-point constant.
+$TEMPDIR/data-list.data:2: warning: LIST: Missing value(s) for all
+        variables from C onward.  These will be filled with the system-missing
+        value or blanks, as appropriate.
+$TEMPDIR/data-list.data:3: warning: LIST: Missing value(s) for all
+        variables from B onward.  These will be filled with the system-missing
+        value or blanks, as appropriate.
+$TEMPDIR/data-list.data:4: error: (columns 3-12, field type F8.0)
+        Field does not form a valid floating-point constant.
+$TEMPDIR/data-list.data:4: warning: LIST: Missing value(s) for all
+        variables from C onward.  These will be filled with the system-missing
+        value or blanks, as appropriate.
+$TEMPDIR/data-list.data:5: warning: LIST: Missing value(s) for all
+        variables from C onward.  These will be filled with the system-missing
+        value or blanks, as appropriate.
+$TEMPDIR/data-list.data:6: warning: LIST: Missing value(s) for all
+        variables from B onward.  These will be filled with the system-missing
+        value or blanks, as appropriate.
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+cp $TEMPDIR/pspp.list /tmp/out
+activity="compare output"
+diff -b -B $TEMPDIR/pspp.list - << EOF
+----------------------------------------------------------------------
+There is no test for DATA LIST FIXED since it is imagined that the
+rest of the tests give it a pretty good workout.
+----------------------------------------------------------------------
+
+----------------------------------------------------------------------
+Testing use of DATA LIST FREE.
+----------------------------------------------------------------------
+
+1.1 DATA LIST.  Reading free-form data from file 
++--------+------+
+|Variable|Format|
+#========#======#
+|A       |F8.0  |
+|B       |F8.0  |
+|C       |F8.0  |
+|D       |F8.0  |
++--------+------+
+
+2.1 PRINT.  Writing   1 records to file "foo".
++--------+------+-------+-------+
+|Variable|Record|Columns| Format|
+#========#======#=======#=======#
+|A       |     1|  1-  8|F8.2   |
+|"/"     |     1|  9-  9|A1     |
+|B       |     1| 10- 17|E8.2   |
+|"/"     |     1| 18- 18|A1     |
+|C       |     1| 19- 28|N10.0  |
+|"/"     |     1| 29- 29|A1     |
+|D       |     1| 30- 45|RBHEX16|
+|"/"     |     1| 46- 46|A1     |
++--------+------+-------+-------+
+
+
+       A        B        C        D
+-------- -------- -------- --------
+     .       2.00     3.00     4.00 
+
+     .       6.00     7.00     8.00 
+
+     .      10.00    11.00    12.00 
+
+----------------------------------------------------------------------
+Testing use of DATA LIST LIST.
+----------------------------------------------------------------------
+
+3.1 DATA LIST.  Reading free-form data from file 
++--------+------+
+|Variable|Format|
+#========#======#
+|A       |F8.0  |
+|B       |F8.0  |
+|C       |F8.0  |
+|D       |F8.0  |
++--------+------+
+
+4.1 PRINT.  Writing   1 records to the listing file.
++--------+------+-------+------+
+|Variable|Record|Columns|Format|
+#========#======#=======#======#
+|A       |     1|  1-  8|F8.2  |
+|B       |     1| 10- 17|F8.2  |
+|C       |     1| 19- 26|F8.2  |
+|D       |     1| 28- 35|F8.2  |
++--------+------+-------+------+
+     .       2.00     3.00     4.00 
+
+       A        B        C        D
+-------- -------- -------- --------
+     .       2.00     3.00     4.00 
+     .       6.00      .        .   
+     .       6.00      .        .   
+    7.00      .        .        .   
+    7.00      .        .        .   
+    8.00      .        .        .   
+    8.00      .        .        .   
+   10.00    11.00      .        .   
+   10.00    11.00      .        .   
+   12.00      .        .        .   
+   12.00      .        .        .   
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+
+activity="compare print out"
+diff $TEMPDIR/foo - << EOF
+     .  /2.00E+00/0000000003/0000000000001040/
+     .       2.00     3.00     4.00 
+     .  /6.00E+00/0000000007/0000000000002040/
+     .       6.00     7.00     8.00 
+     .  /1.00E+01/0000000011/0000000000002840/
+     .      10.00    11.00    12.00 
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+pass;
diff --git a/tests/command/sample.sh b/tests/command/sample.sh
new file mode 100755 (executable)
index 0000000..5998927
--- /dev/null
@@ -0,0 +1,79 @@
+#!/bin/sh
+
+# This program tests the SAMPLE function
+
+TEMPDIR=/tmp/pspp-tst-$$
+
+here=`pwd`;
+
+# ensure that top_srcdir is absolute
+cd $top_srcdir; top_srcdir=`pwd`
+
+export STAT_CONFIG_PATH=$top_srcdir/config
+
+
+cleanup()
+{
+     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="create program"
+cat > $TEMPDIR/sample.stat <<EOF
+set seed=2
+
+data list /a 1-2.
+begin data.
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+end data.
+sample .5.
+n 5.
+list.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+$here/../src/pspp -o raw-ascii $TEMPDIR/sample.stat
+if [ $? -ne 0 ] ; then fail ; fi
+
+fail
+
+
+pass;
diff --git a/tests/command/split-file.sh b/tests/command/split-file.sh
new file mode 100755 (executable)
index 0000000..666f39d
--- /dev/null
@@ -0,0 +1,106 @@
+#!/bin/sh
+
+# This program tests the split file command
+
+TEMPDIR=/tmp/pspp-tst-$$
+
+here=`pwd`;
+
+# ensure that top_srcdir is absolute
+cd $top_srcdir; top_srcdir=`pwd`
+
+export STAT_CONFIG_PATH=$top_srcdir/config
+
+
+cleanup()
+{
+     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="create program"
+cat > $TEMPDIR/split.stat <<EOF
+title 'Test SPLIT FILE utility'.
+
+data list notable /x 1 y 2.
+begin data.
+12
+16
+17
+19
+15
+14
+27
+20
+26
+25
+28
+29
+24
+end data.
+split file by x.
+list.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+activity="run program"
+$here/../src/pspp -o raw-ascii $TEMPDIR/split.stat
+if [ $? -ne 0 ] ; then no_result ; fi
+
+activity="compare results"
+diff -B -b $TEMPDIR/pspp.list - <<EOF
+Variable Value Label
+X            1
+
+X Y
+- -
+1 2 
+1 6 
+1 7 
+1 9 
+1 5 
+1 4 
+
+Variable Value Label
+X            2
+
+X Y
+- -
+2 7 
+2 0 
+2 6 
+2 5 
+2 8 
+2 9 
+2 4
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+pass;
diff --git a/tests/command/tabs.sh b/tests/command/tabs.sh
new file mode 100755 (executable)
index 0000000..db0c688
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/sh
+
+# This program tests that tab characters can be used in string input
+
+TEMPDIR=/tmp/pspp-tst-$$
+
+here=`pwd`;
+
+# ensure that top_srcdir is absolute
+cd $top_srcdir; top_srcdir=`pwd`
+
+export STAT_CONFIG_PATH=$top_srcdir/config
+
+
+cleanup()
+{
+     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="create program 1"
+cat > $TEMPDIR/tabs.stat <<EOF
+data list /x 1-80 (a).
+begin data.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+activity="create program 2"
+printf  "\t1\t12\t123\t1234\t12345\t123456\t\t1234567\t12345678\tasdf\tjkl\n" >> $TEMPDIR/tabs.stat
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+activity="create program 3"
+cat >> $TEMPDIR/tabs.stat <<EOF
+end data.
+print /x.
+execute.
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+activity="run program"
+$here/../src/pspp -o raw-ascii $TEMPDIR/tabs.stat
+if [ $? -ne 0 ] ; then no_result ; fi
+
+diff -B -b $TEMPDIR/pspp.list - << EOF
+1.1 DATA LIST.  Reading 1 record from the command file.
++--------+------+-------+------+
+|Variable|Record|Columns|Format|
+#========#======#=======#======#
+|X       |     1|  1- 80|A80   |
++--------+------+-------+------+
+               1       12      123     1234    12345   123456          1234567 
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+pass;