]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/test/rolling_count.cpp
a1b6b6fe8cc948e4172e502f1d88813d66243839
[ceph.git] / ceph / src / boost / libs / accumulators / test / rolling_count.cpp
1 // (C) Copyright Eric Niebler 2005.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 #include <boost/test/unit_test.hpp>
7 #include <boost/accumulators/accumulators.hpp>
8 #include <boost/accumulators/statistics/stats.hpp>
9 #include <boost/accumulators/statistics/rolling_count.hpp>
10 #include <sstream>
11 #include <boost/archive/text_oarchive.hpp>
12 #include <boost/archive/text_iarchive.hpp>
13
14 using namespace boost;
15 using namespace unit_test;
16 using namespace accumulators;
17
18 ///////////////////////////////////////////////////////////////////////////////
19 // test_stat
20 //
21 void test_stat()
22 {
23 accumulator_set<int, stats<tag::rolling_count> > acc(tag::rolling_window::window_size = 3);
24
25 BOOST_CHECK_EQUAL(0u, rolling_count(acc));
26
27 acc(1);
28 BOOST_CHECK_EQUAL(1u, rolling_count(acc));
29
30 acc(1);
31 BOOST_CHECK_EQUAL(2u, rolling_count(acc));
32
33 acc(1);
34 BOOST_CHECK_EQUAL(3u, rolling_count(acc));
35
36 acc(1);
37 BOOST_CHECK_EQUAL(3u, rolling_count(acc));
38
39 acc(1);
40 BOOST_CHECK_EQUAL(3u, rolling_count(acc));
41 }
42
43 ///////////////////////////////////////////////////////////////////////////////
44 // test_persistency
45 //
46 void test_persistency()
47 {
48 std::stringstream ss;
49 {
50 accumulator_set<int, stats<tag::rolling_count> > acc(tag::rolling_window::window_size = 3);
51 acc(1);
52 acc(1);
53 acc(1);
54 acc(1);
55 acc(1);
56 acc(1);
57 BOOST_CHECK_EQUAL(3u, rolling_count(acc));
58 boost::archive::text_oarchive oa(ss);
59 acc.serialize(oa, 0);
60 }
61 accumulator_set<int, stats<tag::rolling_count> > acc(tag::rolling_window::window_size = 3);
62 boost::archive::text_iarchive ia(ss);
63 acc.serialize(ia, 0);
64 BOOST_CHECK_EQUAL(3u, rolling_count(acc));
65 }
66
67 ///////////////////////////////////////////////////////////////////////////////
68 // init_unit_test_suite
69 //
70 test_suite* init_unit_test_suite( int argc, char* argv[] )
71 {
72 test_suite *test = BOOST_TEST_SUITE("rolling count test");
73
74 test->add(BOOST_TEST_CASE(&test_stat));
75 test->add(BOOST_TEST_CASE(&test_persistency));
76
77 return test;
78 }