[gnumeric] Tests: add anova test.



commit 8efdb8054f9b384b9cddca56327f33e3fbb09847
Author: Morten Welinder <terra gnome org>
Date:   Thu Aug 18 12:40:09 2016 -0400

    Tests: add anova test.

 samples/nist/gear.gnumeric |  Bin 0 -> 2300 bytes
 src/ssconvert.c            |   13 +++++++++++++
 test/GnumericTest.pm       |   34 ++++++++++++++++++++++++++++++++++
 test/Makefile.am           |    1 +
 test/t7200-regression.pl   |   31 ++++---------------------------
 test/t7201-anova.pl        |   42 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 94 insertions(+), 27 deletions(-)
---
diff --git a/samples/nist/gear.gnumeric b/samples/nist/gear.gnumeric
new file mode 100644
index 0000000..970c596
Binary files /dev/null and b/samples/nist/gear.gnumeric differ
diff --git a/src/ssconvert.c b/src/ssconvert.c
index acda3af..27f4e3b 100644
--- a/src/ssconvert.c
+++ b/src/ssconvert.c
@@ -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 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_))
 
 static void
@@ -627,6 +628,17 @@ run_tool_test (const char *tool, char **argv, WorkbookView *wbv)
 
                engine = analysis_tool_regression_engine;
                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 {
                g_printerr ("no test for tool \"%s\"\n", tool);
                return;
@@ -641,6 +653,7 @@ run_tool_test (const char *tool, char **argv, WorkbookView *wbv)
 
 #undef GET_ARG
 #undef RANGE_ARG
+#undef RANGE_LISTARG
 #undef SHEET_ARG
 
 static int
diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index fbe7f78..f9ad5d3 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -12,6 +12,7 @@ $| = 1;
                            test_importer test_exporter test_roundtrip
                            test_csv_format_guessing
                           test_ssindex sstest test_command message subtest
+                           test_tool
                           $ssconvert $sstest $ssdiff $topsrc $top_builddir
                           $subtests $samples corpus $PERL);
 @GnumericTest::EXPORT_OK = qw(junkfile);
@@ -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 {
     return join (' ', map { &quotearg1 ($_) } @_);
 }
diff --git a/test/Makefile.am b/test/Makefile.am
index a8038df..65e7f32 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -141,6 +141,7 @@ TESTS =     t1000-statfuns.pl                       \
        t7146-solver-Rat43.pl                   \
        t7147-solver-Bennett5.pl                \
        t7200-regression.pl                     \
+       t7201-anova.pl                          \
        t8000-valgrind.pl                       \
        t8001-valgrind-xls.pl                   \
        t8002-valgrind-gnumeric.pl              \
diff --git a/test/t7200-regression.pl b/test/t7200-regression.pl
index db6cd06..24a203f 100755
--- a/test/t7200-regression.pl
+++ b/test/t7200-regression.pl
@@ -10,34 +10,11 @@ my $expected;
 
 &message ("Check regression tool.");
 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__
 "SUMMARY OUTPUT",,"Response Variable","Column 2",,,
diff --git a/test/t7201-anova.pl b/test/t7201-anova.pl
new file mode 100755
index 0000000..be0ac5f
--- /dev/null
+++ b/test/t7201-anova.pl
@@ -0,0 +1,42 @@
+#!/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,,,,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]