From 5156fa5a8323a16f6b4bbc8950221cdc1d0e023d Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 24 Dec 2004 07:22:14 +0000 Subject: [PATCH] Fixed bug #11227 (T-Test not working with alpha independent variable ) --- src/ChangeLog | 5 ++ src/t-test.q | 44 ++++++++------ tests/Makefile.am | 2 + tests/bugs/t-test-alpha.sh | 116 ++++++++++++++++++++++++++++++++++++ tests/bugs/t-test-alpha2.sh | 78 ++++++++++++++++++++++++ 5 files changed, 227 insertions(+), 18 deletions(-) create mode 100755 tests/bugs/t-test-alpha.sh create mode 100755 tests/bugs/t-test-alpha2.sh diff --git a/src/ChangeLog b/src/ChangeLog index 00f4978061..ad2e7b248e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +Fri Dec 24 15:09:11 WST 2004 John Darrington + + * t-test.q Fixed bug #11227 Made t-test work when the independent + variable is alpha + Sat Dec 11 11:43:45 WST 2004 John Darrington * factor_stats.c Fixed calculation of trimmed mean under various diff --git a/src/t-test.q b/src/t-test.q index d5349dddf6..a5bee8b066 100644 --- a/src/t-test.q +++ b/src/t-test.q @@ -238,11 +238,11 @@ static int bad_weight_warn; static int compare_group_binary(const struct group_statistics *a, const struct group_statistics *b, - struct group_properties *p); + const struct group_properties *p); static unsigned hash_group_binary(const struct group_statistics *g, - struct group_properties *p); + const struct group_properties *p); @@ -396,18 +396,25 @@ tts_custom_groups (struct cmd_t_test *cmd UNUSED) } else { - msg (SE, _("When applying GROUPS to a string variable, at " - "least one value must be specified.")); + msg (SE, _("When applying GROUPS to a string variable, two " + "values must be specified.")); return 0; } } - if (!parse_value (&gp.v.g_value[0],indep_var->type)) + if (!parse_value (&gp.v.g_value[0], indep_var->type)) return 0; lex_match (','); if (lex_match (')')) { + if (indep_var->type != NUMERIC) + { + + msg (SE, _("When applying GROUPS to a string variable, two " + "values must be specified.")); + return 0; + } gp.criterion = CMP_LE; gp.v.critical_value = gp.v.g_value[0].f; @@ -415,7 +422,7 @@ tts_custom_groups (struct cmd_t_test *cmd UNUSED) return 1; } - if (!parse_value (&gp.v.g_value[1],indep_var->type)) + if (!parse_value (&gp.v.g_value[1], indep_var->type)) return 0; n_group_values = 2; @@ -1934,16 +1941,15 @@ calculate(const struct casefile *cf, void *cmd_) static int compare_group_binary(const struct group_statistics *a, const struct group_statistics *b, - struct group_properties *p) + const struct group_properties *p) { short flag_a; short flag_b; - assert(p->indep_width == 0 ) ; - if ( p->criterion == CMP_LE ) { + assert(p->indep_width == 0 ) ; flag_a = ( a->id.f < p->v.critical_value ) ; flag_b = ( b->id.f < p->v.critical_value ) ; } @@ -1952,7 +1958,6 @@ compare_group_binary(const struct group_statistics *a, flag_a = ( a->id.f == p->v.critical_value ) ; flag_b = ( b->id.f == p->v.critical_value ) ; } - if ( flag_a == flag_b) return 0 ; @@ -1960,26 +1965,29 @@ compare_group_binary(const struct group_statistics *a, return ( flag_a < flag_b); } +/* This is a degenerate case of a hash, since it can only return three possible + values. It's really a comparison, being used as a hash function */ + static unsigned -hash_group_binary(const struct group_statistics *g, struct group_properties *p) +hash_group_binary(const struct group_statistics *g, + const struct group_properties *p) { short flag = -1; - assert(p->indep_width == 0 ) ; - - /* FIXME: should compare union values */ if ( p->criterion == CMP_LE ) { + /* Not meaningfull to do a less than compare for alpha values ? */ + assert(p->indep_width == 0 ) ; flag = ( g->id.f < p->v.critical_value ) ; } else if ( p->criterion == CMP_EQ) { - if ( g->id.f == p->v.g_value[0].f ) + if ( 0 == compare_values (&g->id, &p->v.g_value[0], p->indep_width )) flag = 0 ; - else if ( g->id.f == p->v.g_value[1].f ) - flag = 1; + else if ( 0 == compare_values (&g->id, &p->v.g_value[1], p->indep_width )) + flag = 1 ; else - flag = 2; + flag = 2 ; } else assert(0); diff --git a/tests/Makefile.am b/tests/Makefile.am index 696af98ace..3b4de758d8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -52,6 +52,8 @@ TESTS = \ bugs/random.sh \ bugs/t-test-with-temp.sh \ bugs/t-test.sh \ + bugs/t-test-alpha.sh \ + bugs/t-test-alpha2.sh \ bugs/temporary.sh \ bugs/val-labs.sh \ bugs/recode-copy-bug.sh \ diff --git a/tests/bugs/t-test-alpha.sh b/tests/bugs/t-test-alpha.sh new file mode 100755 index 0000000000..23771c497b --- /dev/null +++ b/tests/bugs/t-test-alpha.sh @@ -0,0 +1,116 @@ +#!/bin/sh + +# This program tests that the T-TEST works when the independent +# variable is alpha +# BUG #11227 + +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/out.stat < $TEMPDIR/out.stat < /dev/null +#invert v +if [ $? -eq 0 ] ; then fail ; fi + + +pass -- 2.30.2