Commit 8efdb805 authored by Morten Welinder's avatar Morten Welinder

Tests: add anova test.

parent d1dd5694
...@@ -571,6 +571,7 @@ run_solver (Sheet *sheet, WorkbookView *wbv) ...@@ -571,6 +571,7 @@ run_solver (Sheet *sheet, WorkbookView *wbv)
#define GET_ARG(conv_,name_,def_) (g_hash_table_lookup_extended(args,(name_),NULL,&arg) ? conv_((const char *)arg) : (def_)) #define GET_ARG(conv_,name_,def_) (g_hash_table_lookup_extended(args,(name_),NULL,&arg) ? conv_((const char *)arg) : (def_))
#define RANGE_ARG(s_) value_new_cellrange_str(sheet,(s_)) #define RANGE_ARG(s_) value_new_cellrange_str(sheet,(s_))
#define RANGE_LIST_ARG(s_) g_slist_prepend (NULL, value_new_cellrange_str(sheet,(s_)))
#define SHEET_ARG(s_) workbook_sheet_by_name(wb,(s_)) #define SHEET_ARG(s_) workbook_sheet_by_name(wb,(s_))
static void static void
...@@ -627,6 +628,17 @@ run_tool_test (const char *tool, char **argv, WorkbookView *wbv) ...@@ -627,6 +628,17 @@ run_tool_test (const char *tool, char **argv, WorkbookView *wbv)
engine = analysis_tool_regression_engine; engine = analysis_tool_regression_engine;
specs = data; specs = data;
} else if (g_str_equal (tool, "anova")) {
analysis_tools_data_anova_single_t *data =
g_new0 (analysis_tools_data_anova_single_t, 1);
data->base.input = GET_ARG (RANGE_LIST_ARG, "data", NULL);
data->base.labels = GET_ARG (atoi, "labels", FALSE);
data->base.group_by = GET_ARG ((group_by_t), "grouped-by", GROUPED_BY_COL);
data->alpha = GET_ARG (atof, "alpha", 0.05);
engine = analysis_tool_anova_single_engine;
specs = data;
} else { } else {
g_printerr ("no test for tool \"%s\"\n", tool); g_printerr ("no test for tool \"%s\"\n", tool);
return; return;
...@@ -641,6 +653,7 @@ run_tool_test (const char *tool, char **argv, WorkbookView *wbv) ...@@ -641,6 +653,7 @@ run_tool_test (const char *tool, char **argv, WorkbookView *wbv)
#undef GET_ARG #undef GET_ARG
#undef RANGE_ARG #undef RANGE_ARG
#undef RANGE_LISTARG
#undef SHEET_ARG #undef SHEET_ARG
static int static int
......
...@@ -12,6 +12,7 @@ $| = 1; ...@@ -12,6 +12,7 @@ $| = 1;
test_importer test_exporter test_roundtrip test_importer test_exporter test_roundtrip
test_csv_format_guessing test_csv_format_guessing
test_ssindex sstest test_command message subtest test_ssindex sstest test_command message subtest
test_tool
$ssconvert $sstest $ssdiff $topsrc $top_builddir $ssconvert $sstest $ssdiff $topsrc $top_builddir
$subtests $samples corpus $PERL); $subtests $samples corpus $PERL);
@GnumericTest::EXPORT_OK = qw(junkfile); @GnumericTest::EXPORT_OK = qw(junkfile);
...@@ -829,6 +830,39 @@ sub test_ssindex { ...@@ -829,6 +830,39 @@ sub test_ssindex {
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
sub test_tool {
my ($file,$tool,$tool_args,$range,$test) = @_;
&report_skip ("file $file does not exist") unless -r $file;
my @args;
push @args, "--export-range=$range" if defined $range;
push @args, "--tool-test=$tool";
for (my $i = 0; $i + 1 < @$tool_args; $i += 2) {
my $k = $tool_args->[$i];
my $v = $tool_args->[$i + 1];
push @args, "--tool-test=$k:$v";
}
my $tmp = "tool.csv";
&junkfile ($tmp);
my $cmd = &quotearg ($ssconvert, @args, $file, $tmp);
print STDERR "# $cmd\n" if $GnumericTest::verbose;
my $code = system ($cmd);
&system_failure ($ssconvert, $code) if $code;
my $actual = &read_file ($tmp);
&removejunk ($tmp);
if (&$test ($actual)) {
print STDERR "Pass\n";
} else {
&GnumericTest::dump_indented ($actual);
die "Fail\n";
}
}
sub quotearg { sub quotearg {
return join (' ', map { &quotearg1 ($_) } @_); return join (' ', map { &quotearg1 ($_) } @_);
} }
......
...@@ -141,6 +141,7 @@ TESTS = t1000-statfuns.pl \ ...@@ -141,6 +141,7 @@ TESTS = t1000-statfuns.pl \
t7146-solver-Rat43.pl \ t7146-solver-Rat43.pl \
t7147-solver-Bennett5.pl \ t7147-solver-Bennett5.pl \
t7200-regression.pl \ t7200-regression.pl \
t7201-anova.pl \
t8000-valgrind.pl \ t8000-valgrind.pl \
t8001-valgrind-xls.pl \ t8001-valgrind-xls.pl \
t8002-valgrind-gnumeric.pl \ t8002-valgrind-gnumeric.pl \
......
...@@ -10,34 +10,11 @@ my $expected; ...@@ -10,34 +10,11 @@ my $expected;
&message ("Check regression tool."); &message ("Check regression tool.");
my $file = "$samples/tool-tests.gnumeric"; my $file = "$samples/tool-tests.gnumeric";
&GnumericTest::report_skip ("file $file does not exist") unless -r $file;
my %args =
('x' => 'Data!A1:A30',
'y' => 'Data!B1:B30',
);
my @args = ('--export-range=A1:G18', '--tool-test=regression');
foreach my $k (sort keys %args) {
my $v = $args{$k};
push @args, "--tool-test=$k:$v";
}
my $tmp = "tool.txt";
&GnumericTest::junkfile ($tmp);
my $cmd = &GnumericTest::quotearg ($ssconvert, @args, $file, $tmp);
print STDERR "# $cmd\n" if $GnumericTest::verbose;
system ($cmd);
my $actual = &GnumericTest::read_file ($tmp);
if ($actual ne $expected) {
&GnumericTest::dump_indented ($actual);
die "Fail\n";
} else {
print STDERR "Pass\n";
}
&GnumericTest::test_tool ($file, 'regression',
['x' => 'Data!A1:A30', 'y' => 'Data!B1:B30'],
'A1:G18',
sub { $_[0] eq $expected; });
__DATA__ __DATA__
"SUMMARY OUTPUT",,"Response Variable","Column 2",,, "SUMMARY OUTPUT",,"Response Variable","Column 2",,,
......
#!/usr/bin/perl -w
# -----------------------------------------------------------------------------
use strict;
use lib ($0 =~ m|^(.*/)| ? $1 : ".");
use GnumericTest;
my $expected;
{ local $/; $expected = <DATA>; }
&message ("Check anova tool.");
my $file = "$samples/nist/gear.gnumeric";
&GnumericTest::test_tool ($file, 'anova',
['data' => 'Data!A1:j10'],
undef,
sub { $_[0] eq $expected; });
# FIXME: We really ought to compare with tolerance
__DATA__
"Anova: Single Factor",,,,,,
,,,,,,
SUMMARY,,,,,,
Groups,Count,Sum,Average,Variance,,
"Column 1",10,9.98,0.998,1.8888888888888923E-05,,
"Column 2",10,9.991,0.9991,2.7211111111111157E-05,,
"Column 3",10,9.954,0.9954000000000001,1.582222222222225E-05,,
"Column 4",10,9.982,0.9982,1.4844444444444303E-05,,
"Column 5",10,9.919,0.9919,5.743333333333343E-05,,
"Column 6",10,9.988,0.9987999999999999,9.773333333333265E-05,,
"Column 7",10,10.015,1.0015,6.205555555555568E-05,,
"Column 8",10,10.004,1.0004,1.3155555555555578E-05,,
"Column 9",10,9.983,0.9983000000000001,1.7122222222222252E-05,,
"Column 10",10,9.948,0.9948,2.8400000000000053E-05,,
,,,,,,
,,,,,,
ANOVA,,,,,,
"Source of Variation",SS,df,MS,F,P-value,"F critical"
"Between Groups",0.0007290399999999998,9,8.100444444444442E-05,2.29691241335854,0.022660819278641282,1.985594963730501
"Within Groups",0.0031739999999999963,90,3.5266666666666625E-05,,,
Total,0.003903039999999996,99,,,,
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