From d0dc2e01dc5f60df296c657b7ceeaf0f3624cfb9 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 10 Feb 2012 13:40:06 +0100 Subject: [PATCH] Fixed bug #35494 - Levene test crash on no valid values. --- src/math/levene.c | 15 ++++++++++----- tests/language/stats/t-test.at | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/math/levene.c b/src/math/levene.c index fe04d294e1..5193c86a1a 100644 --- a/src/math/levene.c +++ b/src/math/levene.c @@ -22,6 +22,7 @@ #include "libpspp/misc.h" #include "libpspp/hmap.h" #include "data/value.h" +#include "data/val-type.h" #include #include @@ -223,12 +224,16 @@ levene_calculate (struct levene *nl) double numerator = 0.0; double nn = 0.0; - if ( nl->pass == 3 ) - { - nl->pass = 4; - } - assert (nl->pass == 4); + /* The Levene calculation requires three passes. + Normally this should have been done prior to calling this function. + However, in abnormal circumstances (eg. the dataset is empty) there + will have been no passes. + */ + assert (nl->pass == 0 || nl->pass == 3); + + if ( nl->pass == 0 ) + return SYSMIS; nl->denominator *= hmap_count (&nl->hmap) - 1; diff --git a/tests/language/stats/t-test.at b/tests/language/stats/t-test.at index d5b7aad3b2..d03a6ca9d5 100644 --- a/tests/language/stats/t-test.at +++ b/tests/language/stats/t-test.at @@ -744,3 +744,23 @@ x,Equal variances assumed,1.13,.33,-2.32,6.00,.06,-.90,.38,-1.83,.03 ]) AT_CLEANUP + + +dnl Tests for a bug assert failed when the group variables were not of either class +AT_SETUP([T-TEST wrong group]) +AT_DATA([t-test-crs.sps], [dnl +data list list /x * g *. +begin data. +1 2 +2 2 +3 2 +4 2 +5 2 +end data. + +t-test /variables = x group=g(1,3). +]) + +AT_CHECK([pspp t-test-crs.sps], [0],[ignore], [ignore]) + +AT_CLEANUP -- 2.30.2