| 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/max.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::max> > acc; |
| 24 | |
| 25 | acc(1); |
| 26 | BOOST_CHECK_EQUAL(1, (max)(acc)); |
| 27 | |
| 28 | acc(0); |
| 29 | BOOST_CHECK_EQUAL(1, (max)(acc)); |
| 30 | |
| 31 | acc(2); |
| 32 | BOOST_CHECK_EQUAL(2, (max)(acc)); |
| 33 | } |
| 34 | |
| 35 | /////////////////////////////////////////////////////////////////////////////// |
| 36 | // test_persistency |
| 37 | // |
| 38 | void test_persistency() |
| 39 | { |
| 40 | std::stringstream ss; |
| 41 | { |
| 42 | accumulator_set<int, stats<tag::max> > acc; |
| 43 | acc(1); |
| 44 | acc(0); |
| 45 | acc(2); |
| 46 | BOOST_CHECK_EQUAL(2, max(acc)); |
| 47 | boost::archive::text_oarchive oa(ss); |
| 48 | acc.serialize(ar&: oa, file_version: 0); |
| 49 | } |
| 50 | accumulator_set<int, stats<tag::max> > acc; |
| 51 | boost::archive::text_iarchive ia(ss); |
| 52 | acc.serialize(ar&: ia, file_version: 0); |
| 53 | BOOST_CHECK_EQUAL(2, max(acc)); |
| 54 | } |
| 55 | |
| 56 | /////////////////////////////////////////////////////////////////////////////// |
| 57 | // init_unit_test_suite |
| 58 | // |
| 59 | test_suite* init_unit_test_suite( int argc, char* argv[] ) |
| 60 | { |
| 61 | test_suite *test = BOOST_TEST_SUITE("max test" ); |
| 62 | |
| 63 | test->add(BOOST_TEST_CASE(&test_stat)); |
| 64 | test->add(BOOST_TEST_CASE(&test_persistency)); |
| 65 | |
| 66 | return test; |
| 67 | } |
| 68 | |