]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/test/mean.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / 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)
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_mean.hpp>
11 #include <boost/accumulators/statistics/variates/covariate.hpp>
12
13 using namespace boost;
14 using namespace unit_test;
15 using namespace accumulators;
16
17 template<typename T>
18 void assert_is_double(T const &)
19 {
20 BOOST_MPL_ASSERT((is_same<T, double>));
21 }
22
23 ///////////////////////////////////////////////////////////////////////////////
24 // test_stat
25 //
26 void test_stat()
27 {
28 accumulator_set<
29 int
30 , stats<
31 tag::mean
32 , tag::mean_of_variates<int, tag::covariate1>
33 >
34 > acc, test_acc(sample = 0);
35
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);
41
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);
47
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);
53
54 assert_is_double(mean(acc));
55
56 accumulator_set<
57 int
58 , stats<
59 tag::mean(immediate)
60 , tag::mean_of_variates<int, tag::covariate1>(immediate)
61 >
62 > acc2, test_acc2(sample = 0);
63
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);
68
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);
73
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);
78
79 assert_is_double(mean(acc2));
80 }
81
82 ///////////////////////////////////////////////////////////////////////////////
83 // init_unit_test_suite
84 //
85 test_suite* init_unit_test_suite( int argc, char* argv[] )
86 {
87 test_suite *test = BOOST_TEST_SUITE("mean test");
88
89 test->add(BOOST_TEST_CASE(&test_stat));
90
91 return test;
92 }