]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/histogram/test/accumulators_weighted_sum_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / histogram / test / accumulators_weighted_sum_test.cpp
index 25739f5a9815561497055497637e8909bc494349..ff051aa1b3e254a553259d4bacf33c6835b8d808 100644 (file)
@@ -8,6 +8,7 @@
 #include <boost/histogram/accumulators/ostream.hpp>
 #include <boost/histogram/accumulators/sum.hpp>
 #include <boost/histogram/accumulators/weighted_sum.hpp>
+#include <boost/histogram/detail/square.hpp>
 #include <boost/histogram/weight.hpp>
 #include <sstream>
 #include "throw_exception.hpp"
 using namespace boost::histogram;
 using namespace std::literals;
 
+using w_t = accumulators::weighted_sum<double>;
+
 int main() {
   {
-    using w_t = accumulators::weighted_sum<double>;
     w_t w;
     BOOST_TEST_EQ(str(w), "weighted_sum(0, 0)"s);
     BOOST_TEST_EQ(str(w, 20, false), "  weighted_sum(0, 0)"s);
@@ -78,5 +80,35 @@ int main() {
     BOOST_TEST_EQ(s_t() += s_t(), s_t());
   }
 
+  // division 1
+  {
+    w_t a{1, 2};
+    w_t b{2, 3};
+
+    auto c = a;
+    c /= b;
+
+    BOOST_TEST_EQ(c.value(), 0.5);
+    // error propagation for independent a and b:
+    // var(c)/c^2 = var(a)/a^2 + var(b)/b^2
+    BOOST_TEST_EQ(c.variance() / detail::square(c.value()),
+                  a.variance() / detail::square(a.value()) +
+                      b.variance() / detail::square(b.value()));
+  }
+
+  // division with implicit conversion
+  {
+    w_t a{1, 2};
+    double b = 2;
+
+    auto c = a;
+    c /= b;
+
+    BOOST_TEST_EQ(c.value(), 0.5);
+    // var(b) = b
+    BOOST_TEST_EQ(c.variance() / detail::square(c.value()),
+                  a.variance() / detail::square(a.value()) + 1.0 / b);
+  }
+
   return boost::report_errors();
 }