]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/accumulators/test/moment.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / accumulators / test / moment.cpp
index b91d0af7bcb209d3cd6ee21dc769c5f2479ed279..44fa2a53182480ce4de0a79bf724f088f5bafcb6 100644 (file)
@@ -8,6 +8,9 @@
 #include <boost/accumulators/accumulators.hpp>
 #include <boost/accumulators/statistics/stats.hpp>
 #include <boost/accumulators/statistics/moment.hpp>
+#include <sstream>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
 
 using namespace boost;
 using namespace unit_test;
@@ -38,6 +41,29 @@ void test_stat()
     BOOST_CHECK_CLOSE(1106., accumulators::moment<5>(acc2), 1e-5);
 }
 
+///////////////////////////////////////////////////////////////////////////////
+// test_persistency
+//
+void test_persistency()
+{
+    double epsilon = 1e-5;
+    std::stringstream ss;
+    {
+        accumulator_set<int, stats<tag::moment<2> > > acc;
+        acc(2); //    4
+        acc(4); //   16
+        acc(5); // + 25
+                 // = 45 / 3 = 15
+        BOOST_CHECK_CLOSE(15., accumulators::moment<2>(acc), epsilon);
+        boost::archive::text_oarchive oa(ss);
+        acc.serialize(oa, 0);
+    }
+    accumulator_set<int, stats<tag::moment<2> > > acc;
+    boost::archive::text_iarchive ia(ss);
+    acc.serialize(ia, 0);
+    BOOST_CHECK_CLOSE(15., accumulators::moment<2>(acc), epsilon);
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 // init_unit_test_suite
 //
@@ -46,6 +72,7 @@ test_suite* init_unit_test_suite( int argc, char* argv[] )
     test_suite *test = BOOST_TEST_SUITE("moment test");
 
     test->add(BOOST_TEST_CASE(&test_stat));
+    test->add(BOOST_TEST_CASE(&test_persistency));
 
     return test;
 }