From 3bd4593ef9a57f23062c61ec465389f749ba3089 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 7 Mar 2005 03:34:47 +0000 Subject: [PATCH] Add yet another expression test and fix the bugs it found. --- src/expressions/ChangeLog | 8 +++ src/expressions/TODO | 2 - src/expressions/operations.def | 8 ++- src/expressions/parse.c | 2 +- tests/ChangeLog | 6 +++ tests/Makefile.am | 3 +- tests/expressions/vectors.sh | 99 ++++++++++++++++++++++++++++++++++ 7 files changed, 122 insertions(+), 6 deletions(-) create mode 100755 tests/expressions/vectors.sh diff --git a/src/expressions/ChangeLog b/src/expressions/ChangeLog index 94063e7a..9de71daf 100644 --- a/src/expressions/ChangeLog +++ b/src/expressions/ChangeLog @@ -1,3 +1,11 @@ +Sun Mar 6 19:33:24 2005 Ben Pfaff + + * operations.def: (VEC_ELEM_NUM) Treat user-missing values as + system-missing. + + * parse.c: (parse_vector_element) Fix order of arguments in call + to expr_allocate_binary(). + Sun Mar 6 17:51:05 2005 Ben Pfaff * optimize.c: (optimize_tree) Fix optimization bug for x**2. diff --git a/src/expressions/TODO b/src/expressions/TODO index ba378e8c..2bcbb8c6 100644 --- a/src/expressions/TODO +++ b/src/expressions/TODO @@ -1,7 +1,5 @@ Needed: - - Must test vectors on expressions. - - Warnings on domain errors (see "Domain Errors" in SPSS manual) and documentation of such. diff --git a/src/expressions/operations.def b/src/expressions/operations.def index 8338e18f..8165b740 100644 --- a/src/expressions/operations.def +++ b/src/expressions/operations.def @@ -888,8 +888,12 @@ no_opt operator VEC_ELEM_NUM (idx) vector v; case c; { - if (idx >= 1 && idx <= v->cnt) - return case_num (c, v->var[(int) idx - 1]->fv); + if (idx >= 1 && idx <= v->cnt) + { + const struct variable *var = v->var[(int) idx - 1]; + double value = case_num (c, var->fv); + return !is_num_user_missing (value, var) ? value : SYSMIS; + } else { if (idx == SYSMIS) diff --git a/src/expressions/parse.c b/src/expressions/parse.c index 5e917a0e..be0b9d79 100644 --- a/src/expressions/parse.c +++ b/src/expressions/parse.c @@ -863,7 +863,7 @@ parse_vector_element (struct expression *e) return expr_allocate_binary (e, (vector->var[0]->type == NUMERIC ? OP_VEC_ELEM_NUM : OP_VEC_ELEM_STR), - expr_allocate_vector (e, vector), element); + element, expr_allocate_vector (e, vector)); } /* Individual function parsing. */ diff --git a/tests/ChangeLog b/tests/ChangeLog index 3e97048a..0a8ef20b 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +Sun Mar 6 19:30:14 2005 Ben Pfaff + + * expressions/vectors.sh: New test. + + * Makefile.am: Add expressions/vectors.sh. + Sun Mar 6 17:56:27 2005 Ben Pfaff * expressions/expressions.sh: Add tests for generic optimizations. diff --git a/tests/Makefile.am b/tests/Makefile.am index 5ee230c3..62b80609 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -81,7 +81,8 @@ TESTS = \ expressions/expressions.sh \ expressions/epoch.sh \ expressions/randist.sh \ - expressions/variables.sh + expressions/variables.sh \ + expressions/vectors.sh noinst_PROGRAMS = gengarbage diff --git a/tests/expressions/vectors.sh b/tests/expressions/vectors.sh new file mode 100755 index 00000000..604920ed --- /dev/null +++ b/tests/expressions/vectors.sh @@ -0,0 +1,99 @@ +#!/bin/sh + +# This program tests use of vectors in expressions. + +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/vectors.stat < $TEMPDIR/vectors.err 2> $TEMPDIR/vectors.out +if [ $? -ne 0 ] ; then fail ; fi + +activity="compare results" +diff -b -B $TEMPDIR/pspp.list - <