crosstabs: Fix chi-square display and add regression test.
authorBen Pfaff <blp@gnu.org>
Sun, 7 Jun 2009 04:04:21 +0000 (21:04 -0700)
committerBen Pfaff <blp@gnu.org>
Sun, 7 Jun 2009 04:11:21 +0000 (21:11 -0700)
Bug #26739.

src/language/stats/crosstabs.q
tests/automake.mk
tests/bugs/crosstabs2.sh [new file with mode: 0755]

index e732c4a023a45d1d131d9d74e9209619030c3ce4..70bbe5cc95b31857214fa50f21e3070466b9a80f 100644 (file)
@@ -993,22 +993,22 @@ output_pivot_table (struct crosstabs_proc *proc, struct pivot_table *pt)
       if (chisq)
         {
           display_dimensions (proc, &x, chisq, first_difference);
-          display_chisq (pt, chisq, &showed_fisher);
+          display_chisq (&x, chisq, &showed_fisher);
         }
       if (sym)
         {
           display_dimensions (proc, &x, sym, first_difference);
-          display_symmetric (proc, pt, sym);
+          display_symmetric (proc, &x, sym);
         }
       if (risk)
         {
           display_dimensions (proc, &x, risk, first_difference);
-          display_risk (pt, risk);
+          display_risk (&x, risk);
         }
       if (direct)
         {
           display_dimensions (proc, &x, direct, first_difference);
-          display_directional (proc, pt, direct);
+          display_directional (proc, &x, direct);
         }
 
       /* Free the parts of x that are not owned by pt.  In
index 7dda26df8d53ebd60623bcf35aa6e49b4d487b6e..0fa61752bfe5c9ca68de6651c0c2c88622176bbb 100644 (file)
@@ -107,6 +107,7 @@ dist_TESTS = \
        tests/bugs/compute-fmt.sh \
        tests/bugs/compression.sh \
        tests/bugs/crosstabs.sh \
+       tests/bugs/crosstabs2.sh \
        tests/bugs/crosstabs-crash.sh \
        tests/bugs/crosstabs-crash2.sh \
        tests/bugs/curtailed.sh \
diff --git a/tests/bugs/crosstabs2.sh b/tests/bugs/crosstabs2.sh
new file mode 100755 (executable)
index 0000000..3e66299
--- /dev/null
@@ -0,0 +1,132 @@
+#!/bin/sh
+
+# This program tests for bug #26739, which caused CROSSTABS to crash
+# or to fail to output chi-square results.
+
+TEMPDIR=/tmp/pspp-tst-$$
+TESTFILE=$TEMPDIR/`basename $0`.sps
+
+# 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
+
+# ensure that top_srcdir is absolute
+top_srcdir=`cd $top_srcdir; pwd`
+
+STAT_CONFIG_PATH=$top_srcdir/config
+export STAT_CONFIG_PATH
+
+LANG=C
+export LANG
+
+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="create program"
+cat > $TESTFILE <<EOF
+DATA LIST LIST /x * y *.
+BEGIN DATA.
+2 2
+3 1
+4 2
+4 1
+END DATA.
+
+CROSSTABS
+        /TABLES= x BY y
+        /STATISTICS=CHISQ
+       .
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+$SUPERVISOR $PSPP --testing-mode $TESTFILE
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
+diff -b  -w $TEMPDIR/pspp.list - << EOF
+1.1 DATA LIST.  Reading free-form data from INLINE.
++--------+------+
+|Variable|Format|
+#========#======#
+|x       |F8.0  |
+|y       |F8.0  |
++--------+------+
+2.1 CROSSTABS.  Summary.
+#===============#=====================================================#
+#               #                        Cases                        #
+#               #-----------------+-----------------+-----------------#
+#               #      Valid      |     Missing     |      Total      #
+#               #--------+--------+--------+--------+--------+--------#
+#               #       N| Percent|       N| Percent|       N| Percent#
+#---------------#--------+--------+--------+--------+--------+--------#
+#x * y          #       4|  100.0%|       0|    0.0%|       4|  100.0%#
+#===============#========#========#========#========#========#========#
+2.2 CROSSTABS.  x * y [count].
+#===============#=================#========#
+#               #        y        |        #
+#               #--------+--------+        #
+#              x#    1.00|    2.00|  Total #
+#---------------#--------+--------+--------#
+#           2.00#      .0|     1.0|     1.0#
+#           3.00#     1.0|      .0|     1.0#
+#           4.00#     1.0|     1.0|     2.0#
+#Total          #     2.0|     2.0|     4.0#
+#===============#========#========#========#
+2.3 CROSSTABS.  Chi-square tests.
+#===============#========#========#========#
+#Statistic      #   Value|      df|  Asymp.#
+#               #        |        |    Sig.#
+#               #        |        |(2-sided#
+#               #        |        |       )#
+#---------------#--------+--------+--------#
+#Pearson        #    2.00|       2|     .37#
+#Chi-Square     #        |        |        #
+#Likelihood     #    2.77|       2|     .25#
+#Ratio          #        |        |        #
+#Linear-by-Linea#     .27|       1|     .60#
+#r Association  #        |        |        #
+#N of Valid     #       4|        |        #
+#Cases          #        |        |        #
+#===============#========#========#========#
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+pass;