]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/accumulators/test/count.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / accumulators / test / count.cpp
CommitLineData
7c673cae
FG
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/count.hpp>
92f5a8d4
TL
10#include <sstream>
11#include <boost/archive/text_oarchive.hpp>
12#include <boost/archive/text_iarchive.hpp>
7c673cae
FG
13
14using namespace boost;
15using namespace unit_test;
16using namespace accumulators;
17
18///////////////////////////////////////////////////////////////////////////////
19// test_stat
20//
21void test_stat()
22{
23 accumulator_set<int, stats<tag::count> > acc;
24
25 acc(1);
26 BOOST_CHECK_EQUAL(1u, count(acc));
27
28 acc(1);
29 BOOST_CHECK_EQUAL(2u, count(acc));
30
31 acc(1);
32 BOOST_CHECK_EQUAL(3u, count(acc));
33
34 acc(1);
35 BOOST_CHECK_EQUAL(4u, count(acc));
36
37 acc(1);
38 BOOST_CHECK_EQUAL(5u, count(acc));
39}
40
92f5a8d4
TL
41///////////////////////////////////////////////////////////////////////////////
42// test_persistency
43//
44void test_persistency()
45{
46 // "persistent" storage
47 std::stringstream ss;
48 {
49 accumulator_set<int, stats<tag::count> > acc;
50 acc(1);
51 acc(1);
52 acc(1);
53 acc(1);
54 BOOST_CHECK_EQUAL(4u, count(acc));
55 boost::archive::text_oarchive oa(ss);
56 acc.serialize(oa, 0);
57 }
58 accumulator_set<int, stats<tag::count> > acc;
59 BOOST_CHECK_EQUAL(0u, count(acc));
60 boost::archive::text_iarchive ia(ss);
61 acc.serialize(ia, 0);
62 BOOST_CHECK_EQUAL(4u, count(acc));
63
64}
65
7c673cae
FG
66///////////////////////////////////////////////////////////////////////////////
67// init_unit_test_suite
68//
69test_suite* init_unit_test_suite( int argc, char* argv[] )
70{
71 test_suite *test = BOOST_TEST_SUITE("count test");
72
73 test->add(BOOST_TEST_CASE(&test_stat));
92f5a8d4 74 test->add(BOOST_TEST_CASE(&test_persistency));
7c673cae
FG
75
76 return test;
77}