From e38a4e71587140f1217c886de32abf59928de7b8 Mon Sep 17 00:00:00 2001 From: Thierry Moisan Date: Sun, 19 Oct 2008 22:18:28 -0400 Subject: [PATCH] Adding an example taken from the GSL doc and adding a test for the Statistics module --- Statistics.i | 18 ++++++++++++++++++ t/Statistics.t | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/Statistics.i b/Statistics.i index 150155f..cbbddaf 100644 --- a/Statistics.i +++ b/Statistics.i @@ -401,6 +401,24 @@ documentation: L Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want +=head1 EXAMPLES + +Here is a very simple example on how to use some of the functions in this module : + + use Math::GSL qw/:all/; + use Math::GSL::Statistics qw/:all/; + + my $data = [17.2, 18.1, 16.5, 18.3, 12.6]; + my $mean = gsl_stats_mean($data, 1, 5); + my $variance = gsl_stats_variance($data, 1, 5); + my $largest = gsl_stats_max($data, 1, 5); + my $smallest = gsl_stats_min($data, 1, 5); + print "The dataset is $data->[0], $data->[1], $data->[2], $data->[3], $data->[4] \n"; + print "The sample mean is $mean \n"; + print "The estimated variance is $variance \n"; + print "The largest value is $largest \n"; + print "The smallest value is $smallest \n"; + =head1 AUTHORS Jonathan Leto and Thierry Moisan diff --git a/t/Statistics.t b/t/Statistics.t index 9046039..dbbbc13 100644 --- a/t/Statistics.t +++ b/t/Statistics.t @@ -182,4 +182,12 @@ sub GSL_STATS_LAG1_AUTOCORRELATION : Tests { ok_similar_relative($sd, $expected_sd); ok_similar_relative($lag1, $expected_lag1); } + +sub GSL_STATS_WMEAN : Tests { + my $w = [4, 4, 2, 2]; + my $data = [2, 3, 4, 5]; + my $mean = gsl_stats_wmean($w, 1, $data, 1, 4); + ok_similar ($mean, 19/6); +} + Test::Class->runtests; -- 2.11.4.GIT