]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/test/accumulators_weighted_sum_test.cpp
1 // Copyright 2015-2018 Hans Dembinski
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/core/lightweight_test.hpp>
8 #include <boost/histogram/accumulators/ostream.hpp>
9 #include <boost/histogram/accumulators/sum.hpp>
10 #include <boost/histogram/accumulators/weighted_sum.hpp>
11 #include <boost/histogram/weight.hpp>
13 #include "throw_exception.hpp"
14 #include "utility_str.hpp"
16 using namespace boost::histogram
;
17 using namespace std::literals
;
21 using w_t
= accumulators::weighted_sum
<double>;
23 BOOST_TEST_EQ(str(w
), "weighted_sum(0, 0)"s
);
24 BOOST_TEST_EQ(str(w
, 20, false), " weighted_sum(0, 0)"s
);
25 BOOST_TEST_EQ(str(w
, 20, true), "weighted_sum(0, 0) "s
);
26 BOOST_TEST_EQ(w
, w_t
{});
28 BOOST_TEST_EQ(w
, w_t(0));
29 BOOST_TEST_NE(w
, w_t(1));
31 BOOST_TEST_EQ(w
.value(), 1);
32 BOOST_TEST_EQ(w
.variance(), 1);
37 BOOST_TEST_EQ(w
.value(), 3);
38 BOOST_TEST_EQ(w
.variance(), 5);
39 BOOST_TEST_EQ(w
, w_t(3, 5));
40 BOOST_TEST_NE(w
, w_t(3));
43 BOOST_TEST_EQ(w
.value(), 4);
44 BOOST_TEST_EQ(w
.variance(), 7);
46 // consistency: a weighted counter increased by weight 1 multiplied
47 // by 2 must be the same as a weighted counter increased by weight 2
51 BOOST_TEST_EQ(u
, w_t(2, 4));
57 // conversion to RealType
60 BOOST_TEST_EQ(static_cast<double>(y
), 1);
62 BOOST_TEST_EQ(w_t() += w_t(), w_t());
65 // sum nested in weighted_sum
67 using s_t
= accumulators::weighted_sum
<accumulators::sum
<double>>;
75 BOOST_TEST_EQ(w
.value(), 2);
76 BOOST_TEST_EQ(w
.variance(), 2e200
);
78 BOOST_TEST_EQ(s_t() += s_t(), s_t());
81 return boost::report_errors();