1 // Copyright 2019 Hans Dembinski
2 //
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)
6
7 #include <boost/assert.hpp>
8 #include <boost/core/lightweight_test.hpp>
9 #include <boost/histogram/accumulators.hpp>
10 #include <boost/histogram/serialization.hpp>
11 #include <boost/histogram/weight.hpp>
12 #include "throw_exception.hpp"
13 #include "utility_serialization.hpp"
14
15 using namespace boost::histogram;
16
main(int argc,char ** argv)17 int main(int argc, char** argv) {
18 BOOST_ASSERT(argc == 2);
19
20 // mean v0
21 {
22 const auto filename = join(argv[1], "accumulators_serialization_test_mean_v0.xml");
23 accumulators::mean<> a;
24 load_xml(filename, a);
25 BOOST_TEST_EQ(a.count(), 3);
26 BOOST_TEST_EQ(a.value(), 2);
27 BOOST_TEST_EQ(a.variance(), 0.5);
28 }
29
30 // mean
31 {
32 const auto filename = join(argv[1], "accumulators_serialization_test_mean.xml");
33 accumulators::mean<> a;
34 a(1);
35 a(weight(0.5), 2);
36 a(3);
37 print_xml(filename, a);
38
39 accumulators::mean<> b;
40 BOOST_TEST_NOT(a == b);
41 load_xml(filename, b);
42 BOOST_TEST(a == b);
43 }
44
45 // sum
46 {
47 const auto filename = join(argv[1], "accumulators_serialization_test_sum.xml");
48 accumulators::sum<> a;
49 a += 1e100;
50 a += 1;
51 print_xml(filename, a);
52
53 accumulators::sum<> b;
54 BOOST_TEST_NOT(a == b);
55 load_xml(filename, b);
56 BOOST_TEST(a == b);
57 }
58
59 // weighted_mean
60 {
61 const auto filename =
62 join(argv[1], "accumulators_serialization_test_weighted_mean.xml");
63 accumulators::weighted_mean<> a;
64 a(1);
65 a(weight(0.5), 2);
66 a(3);
67 print_xml(filename, a);
68
69 accumulators::weighted_mean<> b;
70 BOOST_TEST_NOT(a == b);
71 load_xml(filename, b);
72 BOOST_TEST(a == b);
73 }
74
75 // weighted_sum
76 {
77 const auto filename =
78 join(argv[1], "accumulators_serialization_test_weighted_sum.xml");
79 accumulators::weighted_sum<> a;
80 a += 1;
81 a += 10;
82 print_xml(filename, a);
83
84 accumulators::weighted_sum<> b;
85 BOOST_TEST_NOT(a == b);
86 load_xml(filename, b);
87 BOOST_TEST(a == b);
88 }
89
90 return boost::report_errors();
91 }
92