]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/test/kurtosis.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / accumulators / test / kurtosis.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)
5
6 // Test case for kurtosis.hpp
7
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/kurtosis.hpp>
17
18 using namespace boost;
19 using namespace unit_test;
20 using namespace boost::accumulators;
21
22 ///////////////////////////////////////////////////////////////////////////////
23 // test_stat
24 //
25 void test_stat()
26 {
27 // tolerance in %
28 // double epsilon = 1;
29
30 accumulator_set<double, stats<tag::kurtosis > > acc1;
31 accumulator_set<int, stats<tag::kurtosis > > acc2;
32
33 // two random number generators
34 boost::lagged_fibonacci607 rng;
35 boost::normal_distribution<> mean_sigma(0,1);
36 boost::variate_generator<boost::lagged_fibonacci607&, boost::normal_distribution<> > normal(rng, mean_sigma);
37
38 for (std::size_t i=0; i<100000; ++i)
39 {
40 acc1(normal());
41 }
42
43 // This check fails because epsilon is relative and not absolute
44 // BOOST_CHECK_CLOSE( kurtosis(acc1), 0., epsilon );
45
46 acc2(2);
47 acc2(7);
48 acc2(4);
49 acc2(9);
50 acc2(3);
51
52 BOOST_CHECK_EQUAL( mean(acc2), 5 );
53 BOOST_CHECK_EQUAL( accumulators::moment<2>(acc2), 159./5. );
54 BOOST_CHECK_EQUAL( accumulators::moment<3>(acc2), 1171./5. );
55 BOOST_CHECK_EQUAL( accumulators::moment<4>(acc2), 1863 );
56 BOOST_CHECK_CLOSE( kurtosis(acc2), -1.39965397924, 1e-6 );
57 }
58
59 ///////////////////////////////////////////////////////////////////////////////
60 // init_unit_test_suite
61 //
62 test_suite* init_unit_test_suite( int argc, char* argv[] )
63 {
64 test_suite *test = BOOST_TEST_SUITE("kurtosis test");
65
66 test->add(BOOST_TEST_CASE(&test_stat));
67
68 return test;
69 }
70