1 // Copyright (C) Eric Niebler 2005.
2 // Copyright (C) Pieter Bastiaan Ober 2014.
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/test/unit_test.hpp>
8 #include <boost/test/floating_point_comparison.hpp>
9 #include <boost/mpl/assert.hpp>
10 #include <boost/accumulators/accumulators.hpp>
11 #include <boost/accumulators/statistics/stats.hpp>
12 #include <boost/accumulators/statistics/rolling_moment.hpp>
14 using namespace boost
;
15 using namespace unit_test
;
16 using namespace accumulators
;
19 void assert_is_double(T
const &)
21 BOOST_MPL_ASSERT((is_same
<T
, double>));
24 ///////////////////////////////////////////////////////////////////////////////
25 // test_rolling_moment
28 void test_rolling_second_moment()
30 accumulator_set
<int, stats
<tag::rolling_moment
<2> > > acc(tag::rolling_moment
<2>::window_size
= 3);
34 BOOST_CHECK_CLOSE(rolling_moment
<2>(acc
), 4.0/1 ,1e-5);
38 BOOST_CHECK_CLOSE(rolling_moment
<2>(acc
), (4.0 + 16.0)/2, 1e-5);
42 BOOST_CHECK_CLOSE(rolling_moment
<2>(acc
), (4.0 + 16.0 + 25.0)/3, 1e-5);
46 BOOST_CHECK_CLOSE(rolling_moment
<2>(acc
), (16.0 + 25.0 + 36.0)/3, 1e-5);
48 assert_is_double(rolling_moment
<2>(acc
));
51 void test_rolling_fifth_moment()
53 accumulator_set
<int, stats
<tag::rolling_moment
<5> > > acc(tag::rolling_moment
<2>::window_size
= 3);
57 BOOST_CHECK_CLOSE(rolling_moment
<5>(acc
), 32.0/1, 1e-5);
61 BOOST_CHECK_CLOSE(rolling_moment
<5>(acc
), (32.0 + 243.0)/2, 1e-5);
65 BOOST_CHECK_CLOSE(rolling_moment
<5>(acc
), (32.0 + 243.0 + 1024.0)/3, 1e-5);
69 BOOST_CHECK_CLOSE(rolling_moment
<5>(acc
), (243.0 + 1024.0 + 3125.0)/3, 1e-5);
71 assert_is_double(rolling_moment
<5>(acc
));
74 ///////////////////////////////////////////////////////////////////////////////
75 // init_unit_test_suite
77 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
79 test_suite
*test
= BOOST_TEST_SUITE("rolling moment test");
81 test
->add(BOOST_TEST_CASE(&test_rolling_second_moment
));
82 test
->add(BOOST_TEST_CASE(&test_rolling_fifth_moment
));