]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/test/mean.cpp
1 // (C) Copyright Eric Niebler 2005.
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)
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_mean.hpp>
11 #include <boost/accumulators/statistics/variates/covariate.hpp>
13 using namespace boost
;
14 using namespace unit_test
;
15 using namespace accumulators
;
18 void assert_is_double(T
const &)
20 BOOST_MPL_ASSERT((is_same
<T
, double>));
23 ///////////////////////////////////////////////////////////////////////////////
32 , tag::mean_of_variates
<int, tag::covariate1
>
34 > acc
, test_acc(sample
= 0);
36 acc(1, covariate1
= 3);
37 BOOST_CHECK_CLOSE(1., mean(acc
), 1e-5);
38 BOOST_CHECK_EQUAL(1u, count(acc
));
39 BOOST_CHECK_EQUAL(1, sum(acc
));
40 BOOST_CHECK_CLOSE(3., (accumulators::mean_of_variates
<int, tag::covariate1
>(acc
)), 1e-5);
42 acc(0, covariate1
= 4);
43 BOOST_CHECK_CLOSE(0.5, mean(acc
), 1e-5);
44 BOOST_CHECK_EQUAL(2u, count(acc
));
45 BOOST_CHECK_EQUAL(1, sum(acc
));
46 BOOST_CHECK_CLOSE(3.5, (accumulators::mean_of_variates
<int, tag::covariate1
>(acc
)), 1e-5);
48 acc(2, covariate1
= 8);
49 BOOST_CHECK_CLOSE(1., mean(acc
), 1e-5);
50 BOOST_CHECK_EQUAL(3u, count(acc
));
51 BOOST_CHECK_EQUAL(3, sum(acc
));
52 BOOST_CHECK_CLOSE(5., (accumulators::mean_of_variates
<int, tag::covariate1
>(acc
)), 1e-5);
54 assert_is_double(mean(acc
));
60 , tag::mean_of_variates
<int, tag::covariate1
>(immediate
)
62 > acc2
, test_acc2(sample
= 0);
64 acc2(1, covariate1
= 3);
65 BOOST_CHECK_CLOSE(1., mean(acc2
), 1e-5);
66 BOOST_CHECK_EQUAL(1u, count(acc2
));
67 BOOST_CHECK_CLOSE(3., (accumulators::mean_of_variates
<int, tag::covariate1
>(acc2
)), 1e-5);
69 acc2(0, covariate1
= 4);
70 BOOST_CHECK_CLOSE(0.5, mean(acc2
), 1e-5);
71 BOOST_CHECK_EQUAL(2u, count(acc2
));
72 BOOST_CHECK_CLOSE(3.5, (accumulators::mean_of_variates
<int, tag::covariate1
>(acc2
)), 1e-5);
74 acc2(2, covariate1
= 8);
75 BOOST_CHECK_CLOSE(1., mean(acc2
), 1e-5);
76 BOOST_CHECK_EQUAL(3u, count(acc2
));
77 BOOST_CHECK_CLOSE(5., (accumulators::mean_of_variates
<int, tag::covariate1
>(acc2
)), 1e-5);
79 assert_is_double(mean(acc2
));
82 ///////////////////////////////////////////////////////////////////////////////
83 // init_unit_test_suite
85 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
87 test_suite
*test
= BOOST_TEST_SUITE("mean test");
89 test
->add(BOOST_TEST_CASE(&test_stat
));