]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/test/sum.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/accumulators/accumulators.hpp>
8 #include <boost/accumulators/statistics/stats.hpp>
9 #include <boost/accumulators/statistics/sum.hpp>
10 #include <boost/accumulators/statistics/weighted_sum.hpp>
11 #include <boost/accumulators/statistics/variates/covariate.hpp>
13 #include <boost/archive/text_oarchive.hpp>
14 #include <boost/archive/text_iarchive.hpp>
16 using namespace boost
;
17 using namespace unit_test
;
18 using namespace accumulators
;
20 ///////////////////////////////////////////////////////////////////////////////
25 accumulator_set
<int, stats
<tag::sum
, tag::sum_of_weights
, tag::sum_of_variates
<int, tag::covariate1
> >, int> acc
;
27 acc(1, weight
= 2, covariate1
= 3);
28 BOOST_CHECK_EQUAL(2, sum(acc
));
29 BOOST_CHECK_EQUAL(2, sum_of_weights(acc
));
30 BOOST_CHECK_EQUAL(3, sum_of_variates(acc
));
32 acc(2, weight
= 4, covariate1
= 6);
33 BOOST_CHECK_EQUAL(10, sum(acc
));
34 BOOST_CHECK_EQUAL(6, sum_of_weights(acc
));
35 BOOST_CHECK_EQUAL(9, sum_of_variates(acc
));
37 acc(3, weight
= 6, covariate1
= 9);
38 BOOST_CHECK_EQUAL(28, sum(acc
));
39 BOOST_CHECK_EQUAL(12, sum_of_weights(acc
));
40 BOOST_CHECK_EQUAL(18, sum_of_variates(acc
));
43 ///////////////////////////////////////////////////////////////////////////////
46 void test_persistency()
50 accumulator_set
<int, stats
<tag::sum
, tag::sum_of_weights
, tag::sum_of_variates
<int, tag::covariate1
> >, int> acc
;
51 acc(1, weight
= 2, covariate1
= 3);
52 acc(2, weight
= 4, covariate1
= 6);
53 acc(3, weight
= 6, covariate1
= 9);
54 BOOST_CHECK_EQUAL(28, sum(acc
));
55 BOOST_CHECK_EQUAL(12, sum_of_weights(acc
));
56 BOOST_CHECK_EQUAL(18, sum_of_variates(acc
));
58 boost::archive::text_oarchive
oa(ss
);
61 accumulator_set
<int, stats
<tag::sum
, tag::sum_of_weights
, tag::sum_of_variates
<int, tag::covariate1
> >, int> acc
;
62 boost::archive::text_iarchive
ia(ss
);
64 BOOST_CHECK_EQUAL(28, sum(acc
));
65 BOOST_CHECK_EQUAL(12, sum_of_weights(acc
));
66 BOOST_CHECK_EQUAL(18, sum_of_variates(acc
));
69 ///////////////////////////////////////////////////////////////////////////////
70 // init_unit_test_suite
72 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
74 test_suite
*test
= BOOST_TEST_SUITE("sum test");
76 test
->add(BOOST_TEST_CASE(&test_stat
));
77 test
->add(BOOST_TEST_CASE(&test_persistency
));