error_of.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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/test/floating_point_comparison.hpp>
  7. #include <boost/accumulators/accumulators.hpp>
  8. #include <boost/accumulators/statistics/stats.hpp>
  9. #include <boost/accumulators/statistics/with_error.hpp>
  10. #include <boost/accumulators/statistics/error_of_mean.hpp>
  11. using namespace boost;
  12. using namespace unit_test;
  13. using namespace accumulators;
  14. ///////////////////////////////////////////////////////////////////////////////
  15. // test_stat
  16. //
  17. void test_stat()
  18. {
  19. accumulator_set<double, stats<tag::error_of<tag::mean(lazy)> > > acc;
  20. acc(1.1);
  21. acc(1.2);
  22. acc(1.3);
  23. BOOST_CHECK_CLOSE(0.057735, accumulators::error_of<tag::mean(lazy)>(acc), 1e-4);
  24. accumulator_set<double, stats<tag::error_of<tag::mean(immediate)> > > acc2;
  25. acc2(1.1);
  26. acc2(1.2);
  27. acc2(1.3);
  28. BOOST_CHECK_CLOSE(0.057735, accumulators::error_of<tag::mean(immediate)>(acc2), 1e-4);
  29. accumulator_set<double, stats<with_error<tag::mean(lazy)> > > acc3;
  30. acc3(1.1);
  31. acc3(1.2);
  32. acc3(1.3);
  33. BOOST_CHECK_CLOSE(0.057735, accumulators::error_of<tag::mean(lazy)>(acc3), 1e-4);
  34. accumulator_set<double, stats<with_error<tag::mean(immediate)> > > acc4;
  35. acc4(1.1);
  36. acc4(1.2);
  37. acc4(1.3);
  38. BOOST_CHECK_CLOSE(0.057735, accumulators::error_of<tag::mean(immediate)>(acc4), 1e-4);
  39. }
  40. ///////////////////////////////////////////////////////////////////////////////
  41. // init_unit_test_suite
  42. //
  43. test_suite* init_unit_test_suite( int argc, char* argv[] )
  44. {
  45. test_suite *test = BOOST_TEST_SUITE("mean test");
  46. test->add(BOOST_TEST_CASE(&test_stat));
  47. return test;
  48. }