]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/test/skewness.cpp
1 // (C) Copyright 2006 Eric Niebler, Olivier Gygi.
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)
6 // Test case for skewness.hpp
8 #include <boost/random.hpp>
9 #include <boost/test/unit_test.hpp>
10 #include <boost/test/floating_point_comparison.hpp>
11 #include <boost/accumulators/numeric/functional/vector.hpp>
12 #include <boost/accumulators/numeric/functional/complex.hpp>
13 #include <boost/accumulators/numeric/functional/valarray.hpp>
14 #include <boost/accumulators/accumulators.hpp>
15 #include <boost/accumulators/statistics/stats.hpp>
16 #include <boost/accumulators/statistics/skewness.hpp>
18 #include <boost/archive/text_oarchive.hpp>
19 #include <boost/archive/text_iarchive.hpp>
21 using namespace boost
;
22 using namespace unit_test
;
23 using namespace boost::accumulators
;
25 ///////////////////////////////////////////////////////////////////////////////
31 // double epsilon = 1;
33 accumulator_set
<double, stats
<tag::skewness
> > acc1
;
34 accumulator_set
<int, stats
<tag::skewness
> > acc2
;
36 // two random number generators
37 boost::lagged_fibonacci607 rng
;
38 boost::normal_distribution
<> mean_sigma(0,1);
39 boost::variate_generator
<boost::lagged_fibonacci607
&, boost::normal_distribution
<> > normal(rng
, mean_sigma
);
41 for (std::size_t i
=0; i
<100000; ++i
)
46 // This check fails because epsilon is relative and not absolute
47 // BOOST_CHECK_CLOSE( skewness(acc1), 0., epsilon );
55 BOOST_CHECK_EQUAL( mean(acc2
), 5 );
56 BOOST_CHECK_EQUAL( accumulators::moment
<2>(acc2
), 159./5. );
57 BOOST_CHECK_EQUAL( accumulators::moment
<3>(acc2
), 1171./5. );
58 BOOST_CHECK_CLOSE( skewness(acc2
), 0.406040288214, 1e-6 );
61 ///////////////////////////////////////////////////////////////////////////////
64 void test_persistency()
66 double epsilon
= 1e-6;
69 accumulator_set
<int, stats
<tag::skewness
> > acc
;
76 BOOST_CHECK_EQUAL(accumulators::moment
<3>(acc
), 1171./5.);
77 BOOST_CHECK_CLOSE(skewness(acc
), 0.406040288214, epsilon
);
78 boost::archive::text_oarchive
oa(ss
);
81 accumulator_set
<int, stats
<tag::skewness
> > acc
;
82 boost::archive::text_iarchive
ia(ss
);
84 BOOST_CHECK_EQUAL(accumulators::moment
<3>(acc
), 1171./5.);
85 BOOST_CHECK_CLOSE(skewness(acc
), 0.406040288214, epsilon
);
88 ///////////////////////////////////////////////////////////////////////////////
89 // init_unit_test_suite
91 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
93 test_suite
*test
= BOOST_TEST_SUITE("skewness test");
95 test
->add(BOOST_TEST_CASE(&test_stat
));
96 test
->add(BOOST_TEST_CASE(&test_persistency
));