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