Commit 908f485c authored by Morten Welinder's avatar Morten Welinder

COUNTIF: Tests and fixes.

parent 05e51460
2016-06-21 Morten Welinder <terra@gnome.org>
* src/value.c (criteria_test_greater_or_equal): Use case-folding
comparisons for strings.
(parse_criteria, parse_criteria_range): Add argument controlling
whether to anchor matching at end of string.
(parse_database_criteria): Don't anchor here.
2016-06-17 Morten Welinder <terra@gnome.org>
* configure.ac: Post-release bump.
......
Gnumeric 1.12.31
Morten:
* Fix case issues for database functions.
* Anchor COUNTIF criteria at end too.
* Add tests for COUNTIF.
--------------------------------------------------------------------------
Gnumeric 1.12.30
......
2016-06-21 Morten Welinder <terra@gnome.org>
* functions.c (gnumeric_countif): Anchor string matching at end.
(gnumeric_sumif): Ditto.
(gnumeric_averageif): Ditto.
2016-06-17 Morten Welinder <terra@gnome.org>
* Release 1.12.30
......
......@@ -552,7 +552,7 @@ gnumeric_countif (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
return value_new_error_VALUE (ei->pos);
res.count = 0;
res.crit = parse_criteria (argv[1], date_conv);
res.crit = parse_criteria (argv[1], date_conv, TRUE);
problem = sheet_foreach_cell_in_range
(sheet, res.crit->iter_flags,
r->cell.a.col, r->cell.a.row, r->cell.b.col, r->cell.b.row,
......@@ -670,7 +670,7 @@ gnumeric_sumif (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
res.sum = 0;
res.count = 0;
res.crit = parse_criteria (argv[1], date_conv);
res.crit = parse_criteria (argv[1], date_conv, TRUE);
problem = sheet_foreach_cell_in_range
(start_sheet, res.crit->iter_flags,
rs.start.col, rs.start.row, rs.end.col, rs.end.row,
......@@ -735,7 +735,7 @@ gnumeric_averageif (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
res.sum = 0.;
res.count = 0;
res.crit = parse_criteria (argv[1], date_conv);
res.crit = parse_criteria (argv[1], date_conv, TRUE);
problem = sheet_foreach_cell_in_range
(start_sheet, res.crit->iter_flags,
rs.start.col, rs.start.row, rs.end.col, rs.end.row,
......
......@@ -1590,8 +1590,8 @@ criteria_test_less (GnmValue const *x, GnmCriteria *crit)
case CRIT_WRONGTYPE:
return FALSE;
case CRIT_STRING:
return g_utf8_collate (value_peek_string (x),
value_peek_string (y)) < 0;
return go_utf8_collate_casefold (value_peek_string (x),
value_peek_string (y)) < 0;
case CRIT_FLOAT:
return xf < yf;
}
......@@ -1610,8 +1610,8 @@ criteria_test_greater (GnmValue const *x, GnmCriteria *crit)
case CRIT_WRONGTYPE:
return FALSE;
case CRIT_STRING:
return g_utf8_collate (value_peek_string (x),
value_peek_string (y)) > 0;
return go_utf8_collate_casefold (value_peek_string (x),
value_peek_string (y)) > 0;
case CRIT_FLOAT:
return xf > yf;
}
......@@ -1630,8 +1630,8 @@ criteria_test_less_or_equal (GnmValue const *x, GnmCriteria *crit)
case CRIT_WRONGTYPE:
return FALSE;
case CRIT_STRING:
return g_utf8_collate (value_peek_string (x),
value_peek_string (y)) <= 0;
return go_utf8_collate_casefold (value_peek_string (x),
value_peek_string (y)) <= 0;
case CRIT_FLOAT:
return xf <= yf;
}
......@@ -1650,8 +1650,8 @@ criteria_test_greater_or_equal (GnmValue const *x, GnmCriteria *crit)
case CRIT_WRONGTYPE:
return FALSE;
case CRIT_STRING:
return g_utf8_collate (value_peek_string (x),
value_peek_string (y)) >= 0;
return go_utf8_collate_casefold (value_peek_string (x),
value_peek_string (y)) >= 0;
case CRIT_FLOAT:
return xf >= yf;
}
......@@ -1809,7 +1809,8 @@ free_criterias (GSList *criterias)
* "pattern"
**/
GnmCriteria *
parse_criteria (GnmValue const *crit_val, GODateConventions const *date_conv)
parse_criteria (GnmValue const *crit_val, GODateConventions const *date_conv,
gboolean anchor_end)
{
int len;
char const *criteria;
......@@ -1848,7 +1849,7 @@ parse_criteria (GnmValue const *crit_val, GODateConventions const *date_conv)
len = 1;
} else {
res->fun = criteria_test_match;
res->has_rx = (gnm_regcomp_XL (&res->rx, criteria, GO_REG_ICASE, TRUE, FALSE) == GO_REG_OK);
res->has_rx = (gnm_regcomp_XL (&res->rx, criteria, GO_REG_ICASE, TRUE, anchor_end) == GO_REG_OK);
len = 0;
}
......@@ -1870,7 +1871,7 @@ parse_criteria (GnmValue const *crit_val, GODateConventions const *date_conv)
static GSList *
parse_criteria_range (Sheet *sheet, int b_col, int b_row, int e_col, int e_row,
int *field_ind)
int *field_ind, gboolean anchor_end)
{
GSList *criterias = NULL;
GODateConventions const *date_conv =
......@@ -1889,7 +1890,8 @@ parse_criteria_range (Sheet *sheet, int b_col, int b_row, int e_col, int e_row,
if (gnm_cell_is_empty (cell))
continue;
cond = parse_criteria (cell->value, date_conv);
cond = parse_criteria (cell->value, date_conv,
anchor_end);
cond->column = (field_ind != NULL)
? field_ind[j - b_col]
: j - b_col;
......@@ -1951,7 +1953,8 @@ parse_database_criteria (GnmEvalPos const *ep, GnmValue const *database, GnmValu
}
return parse_criteria_range (sheet, b_col, b_row + 1,
e_col, e_row, field_ind);
e_col, e_row, field_ind,
FALSE);
}
/**
......
......@@ -213,7 +213,8 @@ typedef struct {
} GnmDBCriteria;
GnmCriteria *parse_criteria (GnmValue const *crit_val,
GODateConventions const *date_conv);
GODateConventions const *date_conv,
gboolean anchor_end);
void free_criteria (GnmCriteria *criteria);
void free_criterias (GSList *criterias);
GSList *find_rows_that_match (Sheet *sheet, int first_col,
......
2016-06-21 Morten Welinder <terra@gnome.org>
* t1017-countif.pl: New test.
2016-06-17 Morten Welinder <terra@gnome.org>
* Release 1.12.30
......
......@@ -44,6 +44,7 @@ TESTS = t1000-statfuns.pl \
t1014-gsl.pl \
t1015-complex.pl \
t1016-database.pl \
t1017-countif.pl \
t1100-chitest.pl \
t1101-ftest.pl \
t1102-ttest.pl \
......
#!/usr/bin/perl -w
# -----------------------------------------------------------------------------
use strict;
use lib ($0 =~ m|^(.*/)| ? $1 : ".");
use GnumericTest;
my $file = "excel12/countif.xlsx";
&message ("Check that $file evaluates correctly.");
&test_sheet_calc ("$samples/$file", "Overview!C2:C99", sub { /(\s*0)+\s*/i });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment