]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/test/external_accumulator.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/mean.hpp>
12 using namespace boost
;
13 using namespace unit_test
;
14 using namespace accumulators
;
18 BOOST_PARAMETER_KEYWORD(tag
, sum_acc
)
21 ///////////////////////////////////////////////////////////////////////////////
26 accumulator_set
<int, stats
<tag::mean
, tag::external
<tag::sum
, my::tag::sum_acc
> > > acc
;
27 accumulator_set
<int, stats
<tag::sum
> > sum_acc
;
31 BOOST_CHECK_CLOSE(1., mean(acc
, my::sum_acc
= sum_acc
), 1e-5);
32 BOOST_CHECK_EQUAL(1u, count(acc
));
33 BOOST_CHECK_EQUAL(1, sum(sum_acc
));
37 BOOST_CHECK_CLOSE(0.5, mean(acc
, my::sum_acc
= sum_acc
), 1e-5);
38 BOOST_CHECK_EQUAL(2u, count(acc
));
39 BOOST_CHECK_EQUAL(1, sum(acc
, my::sum_acc
= sum_acc
));
43 BOOST_CHECK_CLOSE(1., mean(acc
, my::sum_acc
= sum_acc
), 1e-5);
44 BOOST_CHECK_EQUAL(3u, count(acc
));
45 BOOST_CHECK_EQUAL(3, sum(acc
, my::sum_acc
= sum_acc
));
48 ///////////////////////////////////////////////////////////////////////////////
53 typedef accumulator_set
<int, stats
<tag::sum
> > sum_acc_type
;
59 , tag::external
<tag::sum
, my::tag::sum_acc
>
60 , tag::reference
<sum_acc_type
, my::tag::sum_acc
>
62 > acc(my::sum_acc
= sum_acc
);
66 BOOST_CHECK_CLOSE(1., mean(acc
), 1e-5);
67 BOOST_CHECK_EQUAL(1u, count(acc
));
68 BOOST_CHECK_EQUAL(1, sum(sum_acc
));
72 BOOST_CHECK_CLOSE(0.5, mean(acc
), 1e-5);
73 BOOST_CHECK_EQUAL(2u, count(acc
));
74 BOOST_CHECK_EQUAL(1, sum(acc
));
78 BOOST_CHECK_CLOSE(1., mean(acc
), 1e-5);
79 BOOST_CHECK_EQUAL(3u, count(acc
));
80 BOOST_CHECK_EQUAL(3, sum(acc
));
83 ///////////////////////////////////////////////////////////////////////////////
86 void test_reference2()
88 typedef accumulator_set
<int, stats
<tag::sum
> > sum_acc_type
;
94 , tag::external
<tag::sum
, my::tag::sum_acc
, sum_acc_type
>
96 > acc(my::sum_acc
= sum_acc
);
100 BOOST_CHECK_CLOSE(1., mean(acc
), 1e-5);
101 BOOST_CHECK_EQUAL(1u, count(acc
));
102 BOOST_CHECK_EQUAL(1, sum(sum_acc
));
106 BOOST_CHECK_CLOSE(0.5, mean(acc
), 1e-5);
107 BOOST_CHECK_EQUAL(2u, count(acc
));
108 BOOST_CHECK_EQUAL(1, sum(acc
));
112 BOOST_CHECK_CLOSE(1., mean(acc
), 1e-5);
113 BOOST_CHECK_EQUAL(3u, count(acc
));
114 BOOST_CHECK_EQUAL(3, sum(acc
));
117 ///////////////////////////////////////////////////////////////////////////////
118 // init_unit_test_suite
120 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
122 test_suite
*test
= BOOST_TEST_SUITE("external_accumulator test");
124 test
->add(BOOST_TEST_CASE(&test_stat
));
125 test
->add(BOOST_TEST_CASE(&test_reference
));
126 test
->add(BOOST_TEST_CASE(&test_reference2
));