weighted_moment.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // (C) Copyright Eric Niebler, Olivier Gygi 2006.
  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/weighted_moment.hpp>
  10. using namespace boost;
  11. using namespace unit_test;
  12. using namespace accumulators;
  13. ///////////////////////////////////////////////////////////////////////////////
  14. // test_stat
  15. //
  16. void test_stat()
  17. {
  18. accumulator_set<double, stats<tag::weighted_moment<2> >, double> acc2;
  19. accumulator_set<double, stats<tag::weighted_moment<7> >, double> acc7;
  20. acc2(2.1, weight = 0.7);
  21. acc2(2.7, weight = 1.4);
  22. acc2(1.8, weight = 0.9);
  23. acc7(2.1, weight = 0.7);
  24. acc7(2.7, weight = 1.4);
  25. acc7(1.8, weight = 0.9);
  26. BOOST_CHECK_CLOSE(5.403, accumulators::weighted_moment<2>(acc2), 1e-5);
  27. BOOST_CHECK_CLOSE(548.54182, accumulators::weighted_moment<7>(acc7), 1e-5);
  28. }
  29. ///////////////////////////////////////////////////////////////////////////////
  30. // init_unit_test_suite
  31. //
  32. test_suite* init_unit_test_suite( int argc, char* argv[] )
  33. {
  34. test_suite *test = BOOST_TEST_SUITE("weighted_moment test");
  35. test->add(BOOST_TEST_CASE(&test_stat));
  36. return test;
  37. }