Fix assert failure when only MOMENT_MEAN is needed on DESCRIPTIVES.
authorBen Pfaff <blp@gnu.org>
Sat, 10 Apr 2004 03:06:45 +0000 (03:06 +0000)
committerBen Pfaff <blp@gnu.org>
Sat, 10 Apr 2004 03:06:45 +0000 (03:06 +0000)
src/ChangeLog
src/descript.c
tests/ChangeLog
tests/Makefile.am
tests/stats/descript-mean-bug.sh [new file with mode: 0755]

index 179a761bfb097d69124be6d0fd92a0f3dab02c4f..9a4c4971f2e8c7ae6a58f3cec00e1a8966acb6dd 100644 (file)
@@ -1,3 +1,8 @@
+Fri Apr  9 20:04:49 2004  Ben Pfaff  <blp@gnu.org>
+
+       * descript.c (calc_descriptives): Fix assert failure when only
+       MOMENT_MEAN is needed.
+
 2004-04-09  Michael Kiefte  <mkiefte@dal.ca>
 
        * descript.c: 
index 3aafb94e611c2cb6d44af8e1ab99269ea769cdb5..0492b33ed2378a232418f368326974eab88eaf00 100644 (file)
@@ -742,8 +742,14 @@ calc_descriptives (const struct casefile *cf, void *dsc_)
               continue;
             }
 
-          if (dv->moments != NULL)
-            moments_pass_one (dv->moments, x, weight);
+          if (dv->moments != NULL) 
+            {
+              if (dsc->max_moment > MOMENT_MEAN)
+                moments_pass_one (dv->moments, x, weight);
+              else
+                moments_pass_two (dv->moments, x, weight);
+            }
+
           if (x < dv->min)
             dv->min = x;
           if (x > dv->max)
index 1e52c8f85c6fbcdb33928ad75552c41ee20fc304..83881f0b763e04aa1fdd9a783b164703cbe5e53a 100644 (file)
@@ -1,3 +1,10 @@
+Fri Apr  9 20:03:33 2004  Ben Pfaff  <blp@gnu.org>
+
+       * Makefile.am: (TESTS) Add stats/descript-mean-bug.sh.
+
+       * stats/descript-mean-bug.sh: Add test for a bug where
+       DESCRIPTIVES asking only for the mean assert-failed.
+
 Sat Apr  3 11:42:31 2004  Ben Pfaff  <blp@gnu.org>
 
        * Makefile.am: (TESTS) Add bugs/comment-at-eof.sh.  Alphabetize
index 6434ab0258388ae4748233842662b6a051b02fdd..9238ee691c1f06c60855c2a2d4a568f32fc1cbbc 100644 (file)
@@ -49,6 +49,7 @@ TESTS = \
        xforms/expressions.sh \
        stats/descript-basic.sh \
        stats/descript-missing.sh \
+       stats/descript-mean-bug.sh \
        stats/moments.sh \
        stats/percentiles-compatible.sh \
        stats/percentiles-enhanced.sh
diff --git a/tests/stats/descript-mean-bug.sh b/tests/stats/descript-mean-bug.sh
new file mode 100755 (executable)
index 0000000..d1ebd64
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/sh
+
+# This program tests that DESCRIPTIVES asking for a mean only works,
+# which didn't at one point.
+
+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/descript.stat <<EOF
+data list notable / x 1.
+begin data.
+0
+1
+2
+3
+4
+5
+end data.
+
+descript all/stat=mean.
+
+EOF
+if [ $? -ne 0 ] ; then no_result ; fi
+
+
+activity="run program"
+$SUPERVISOR $here/../src/pspp -o raw-ascii $TEMPDIR/descript.stat
+if [ $? -ne 0 ] ; then no_result ; fi
+
+activity="compare output"
+diff -B -b $TEMPDIR/pspp.list - <<EOF
+1.1 DESCRIPTIVES.  Valid cases = 6; cases with missing value(s) = 0.
++--------#-+-----+
+|Variable#N| Mean|
+#========#=#=====#
+|X       #6|2.500|
++--------#-+-----+
+EOF
+if [ $? -ne 0 ] ; then fail ; fi
+
+
+pass