max.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include <boost/test/unit_test.hpp>
  6. #include <boost/accumulators/accumulators.hpp>
  7. #include <boost/accumulators/statistics/stats.hpp>
  8. #include <boost/accumulators/statistics/max.hpp>
  9. #include <sstream>
  10. #include <boost/archive/text_oarchive.hpp>
  11. #include <boost/archive/text_iarchive.hpp>
  12. using namespace boost;
  13. using namespace unit_test;
  14. using namespace accumulators;
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // test_stat
  17. //
  18. void test_stat()
  19. {
  20. accumulator_set<int, stats<tag::max> > acc;
  21. acc(1);
  22. BOOST_CHECK_EQUAL(1, (max)(acc));
  23. acc(0);
  24. BOOST_CHECK_EQUAL(1, (max)(acc));
  25. acc(2);
  26. BOOST_CHECK_EQUAL(2, (max)(acc));
  27. }
  28. ///////////////////////////////////////////////////////////////////////////////
  29. // test_persistency
  30. //
  31. void test_persistency()
  32. {
  33. std::stringstream ss;
  34. {
  35. accumulator_set<int, stats<tag::max> > acc;
  36. acc(1);
  37. acc(0);
  38. acc(2);
  39. BOOST_CHECK_EQUAL(2u, max(acc));
  40. boost::archive::text_oarchive oa(ss);
  41. acc.serialize(oa, 0);
  42. }
  43. accumulator_set<int, stats<tag::max> > acc;
  44. boost::archive::text_iarchive ia(ss);
  45. acc.serialize(ia, 0);
  46. BOOST_CHECK_EQUAL(2u, max(acc));
  47. }
  48. ///////////////////////////////////////////////////////////////////////////////
  49. // init_unit_test_suite
  50. //
  51. test_suite* init_unit_test_suite( int argc, char* argv[] )
  52. {
  53. test_suite *test = BOOST_TEST_SUITE("max test");
  54. test->add(BOOST_TEST_CASE(&test_stat));
  55. test->add(BOOST_TEST_CASE(&test_persistency));
  56. return test;
  57. }