From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/accumulators/test/median.cpp | 110 ++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/boost/libs/accumulators/test/median.cpp (limited to 'src/boost/libs/accumulators/test/median.cpp') diff --git a/src/boost/libs/accumulators/test/median.cpp b/src/boost/libs/accumulators/test/median.cpp new file mode 100644 index 00000000..e3483932 --- /dev/null +++ b/src/boost/libs/accumulators/test/median.cpp @@ -0,0 +1,110 @@ +// (C) Copyright 2006 Eric Niebler, Olivier Gygi +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace boost; +using namespace unit_test; +using namespace accumulators; + + +typedef accumulator_set > p_square_median_t; +typedef accumulator_set > dist_median_t; +typedef accumulator_set > p_square_dist_median_t; + +/////////////////////////////////////////////////////////////////////////////// +// test_stat +// +void test_stat() +{ + // two random number generators + double mu = 1.; + boost::lagged_fibonacci607 rng; + boost::normal_distribution<> mean_sigma(mu,1); + boost::variate_generator > normal(rng, mean_sigma); + + p_square_median_t acc; + dist_median_t acc_dens( density_cache_size = 10000, density_num_bins = 1000 ); + p_square_dist_median_t acc_cdist( p_square_cumulative_distribution_num_cells = 100 ); + + for (std::size_t i=0; i<100000; ++i) + { + double sample = normal(); + acc(sample); + acc_dens(sample); + acc_cdist(sample); + } + + BOOST_CHECK_CLOSE(1., median(acc), 1.); + BOOST_CHECK_CLOSE(1., median(acc_dens), 1.); + BOOST_CHECK_CLOSE(1., median(acc_cdist), 3.); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_persistency +// +void test_persistency() +{ + // two random number generators + double mu = 1.; + boost::lagged_fibonacci607 rng; + boost::normal_distribution<> mean_sigma(mu,1); + boost::variate_generator > normal(rng, mean_sigma); + std::stringstream ss; + { + p_square_median_t acc; + dist_median_t acc_dens( density_cache_size = 10000, density_num_bins = 1000 ); + p_square_dist_median_t acc_cdist( p_square_cumulative_distribution_num_cells = 100 ); + + for (std::size_t i=0; i<100000; ++i) + { + double sample = normal(); + acc(sample); + acc_dens(sample); + acc_cdist(sample); + } + + BOOST_CHECK_CLOSE(1., median(acc), 1.); + BOOST_CHECK_CLOSE(1., median(acc_dens), 1.); + BOOST_CHECK_CLOSE(1., median(acc_cdist), 3.); + + boost::archive::text_oarchive oa(ss); + acc.serialize(oa, 0); + acc_dens.serialize(oa, 0); + acc_cdist.serialize(oa, 0); + } + + p_square_median_t acc; + dist_median_t acc_dens( density_cache_size = 10000, density_num_bins = 1000 ); + p_square_dist_median_t acc_cdist( p_square_cumulative_distribution_num_cells = 100 ); + boost::archive::text_iarchive ia(ss); + acc.serialize(ia, 0); + acc_dens.serialize(ia, 0); + acc_cdist.serialize(ia, 0); + BOOST_CHECK_CLOSE(1., median(acc), 1.); + BOOST_CHECK_CLOSE(1., median(acc_dens), 1.); + BOOST_CHECK_CLOSE(1., median(acc_cdist), 3.); +} + +/////////////////////////////////////////////////////////////////////////////// +// init_unit_test_suite +// +test_suite* init_unit_test_suite( int argc, char* argv[] ) +{ + test_suite *test = BOOST_TEST_SUITE("median test"); + + test->add(BOOST_TEST_CASE(&test_stat)); + test->add(BOOST_TEST_CASE(&test_persistency)); + + return test; +} -- cgit v1.2.3