1 // (C) Copyright Eric Niebler, Olivier Gygi 2006.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/test/unit_test.hpp>
7 #include <boost/test/floating_point_comparison.hpp>
8 #include <boost/accumulators/accumulators.hpp>
9 #include <boost/accumulators/statistics/stats.hpp>
10 #include <boost/accumulators/statistics/weighted_moment.hpp>
11
12 using namespace boost;
13 using namespace unit_test;
14 using namespace accumulators;
15
16 ///////////////////////////////////////////////////////////////////////////////
17 // test_stat
18 //
test_stat()19 void test_stat()
20 {
21 accumulator_set<double, stats<tag::weighted_moment<2> >, double> acc2;
22 accumulator_set<double, stats<tag::weighted_moment<7> >, double> acc7;
23
24 acc2(2.1, weight = 0.7);
25 acc2(2.7, weight = 1.4);
26 acc2(1.8, weight = 0.9);
27
28 acc7(2.1, weight = 0.7);
29 acc7(2.7, weight = 1.4);
30 acc7(1.8, weight = 0.9);
31
32 BOOST_CHECK_CLOSE(5.403, accumulators::weighted_moment<2>(acc2), 1e-5);
33 BOOST_CHECK_CLOSE(548.54182, accumulators::weighted_moment<7>(acc7), 1e-5);
34 }
35
36 ///////////////////////////////////////////////////////////////////////////////
37 // init_unit_test_suite
38 //
init_unit_test_suite(int argc,char * argv[])39 test_suite* init_unit_test_suite( int argc, char* argv[] )
40 {
41 test_suite *test = BOOST_TEST_SUITE("weighted_moment test");
42
43 test->add(BOOST_TEST_CASE(&test_stat));
44
45 return test;
46 }
47
48