From 2133a4941da5c903fe08c0961959e89b7d5f7321 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sat, 10 Apr 2004 03:06:45 +0000 Subject: [PATCH] Fix assert failure when only MOMENT_MEAN is needed on DESCRIPTIVES. --- src/ChangeLog | 5 ++ src/descript.c | 10 +++- tests/ChangeLog | 7 +++ tests/Makefile.am | 1 + tests/stats/descript-mean-bug.sh | 83 ++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 2 deletions(-) create mode 100755 tests/stats/descript-mean-bug.sh diff --git a/src/ChangeLog b/src/ChangeLog index 179a761b..9a4c4971 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +Fri Apr 9 20:04:49 2004 Ben Pfaff + + * descript.c (calc_descriptives): Fix assert failure when only + MOMENT_MEAN is needed. + 2004-04-09 Michael Kiefte * descript.c: diff --git a/src/descript.c b/src/descript.c index 3aafb94e..0492b33e 100644 --- a/src/descript.c +++ b/src/descript.c @@ -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) diff --git a/tests/ChangeLog b/tests/ChangeLog index 1e52c8f8..83881f0b 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,10 @@ +Fri Apr 9 20:03:33 2004 Ben Pfaff + + * 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 * Makefile.am: (TESTS) Add bugs/comment-at-eof.sh. Alphabetize diff --git a/tests/Makefile.am b/tests/Makefile.am index 6434ab02..9238ee69 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 00000000..d1ebd648 --- /dev/null +++ b/tests/stats/descript-mean-bug.sh @@ -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 <