]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/accumulators/test/extended_p_square_quantile.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / accumulators / test / extended_p_square_quantile.cpp
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
6 // Test case for extended_p_square_quantile.hpp
7
8 #include <iostream>
9 #include <boost/random.hpp>
10 #include <boost/test/unit_test.hpp>
11 #include <boost/test/floating_point_comparison.hpp>
12 #include <boost/accumulators/numeric/functional/vector.hpp>
13 #include <boost/accumulators/numeric/functional/complex.hpp>
14 #include <boost/accumulators/numeric/functional/valarray.hpp>
15 #include <boost/accumulators/accumulators.hpp>
16 #include <boost/accumulators/statistics/stats.hpp>
17 #include <boost/accumulators/statistics/extended_p_square_quantile.hpp>
18
19 using namespace boost;
20 using namespace unit_test;
21 using namespace boost::accumulators;
22
23 ///////////////////////////////////////////////////////////////////////////////
24 // test_stat
25 //
26 void test_stat()
27 {
28 typedef accumulator_set<double, stats<tag::extended_p_square_quantile> > accumulator_t;
29 typedef accumulator_set<double, stats<tag::weighted_extended_p_square_quantile>, double > accumulator_t_weighted;
30 typedef accumulator_set<double, stats<tag::extended_p_square_quantile(quadratic)> > accumulator_t_quadratic;
31 typedef accumulator_set<double, stats<tag::weighted_extended_p_square_quantile(quadratic)>, double > accumulator_t_weighted_quadratic;
32
33 // tolerance
34 double epsilon = 1;
35
36 // a random number generator
37 boost::lagged_fibonacci607 rng;
38
39 std::vector<double> probs;
40
41 probs.push_back(0.990);
42 probs.push_back(0.991);
43 probs.push_back(0.992);
44 probs.push_back(0.993);
45 probs.push_back(0.994);
46 probs.push_back(0.995);
47 probs.push_back(0.996);
48 probs.push_back(0.997);
49 probs.push_back(0.998);
50 probs.push_back(0.999);
51
52 accumulator_t acc(extended_p_square_probabilities = probs);
53 accumulator_t_weighted acc_weighted(extended_p_square_probabilities = probs);
54 accumulator_t_quadratic acc2(extended_p_square_probabilities = probs);
55 accumulator_t_weighted_quadratic acc_weighted2(extended_p_square_probabilities = probs);
56
57 for (int i=0; i<10000; ++i)
58 {
59 double sample = rng();
60 acc(sample);
61 acc2(sample);
62 acc_weighted(sample, weight = 1.);
63 acc_weighted2(sample, weight = 1.);
64 }
65
66 for (std::size_t i = 0; i < probs.size() - 1; ++i)
67 {
68 BOOST_CHECK_CLOSE(
69 quantile(acc, quantile_probability = 0.99025 + i*0.001)
70 , 0.99025 + i*0.001
71 , epsilon
72 );
73 BOOST_CHECK_CLOSE(
74 quantile(acc2, quantile_probability = 0.99025 + i*0.001)
75 , 0.99025 + i*0.001
76 , epsilon
77 );
78 BOOST_CHECK_CLOSE(
79 quantile(acc_weighted, quantile_probability = 0.99025 + i*0.001)
80 , 0.99025 + i*0.001
81 , epsilon
82 );
83 BOOST_CHECK_CLOSE(
84 quantile(acc_weighted2, quantile_probability = 0.99025 + i*0.001)
85 , 0.99025 + i*0.001
86 , epsilon
87 );
88 }
89 }
90
91 ///////////////////////////////////////////////////////////////////////////////
92 // init_unit_test_suite
93 //
94 test_suite* init_unit_test_suite( int argc, char* argv[] )
95 {
96 test_suite *test = BOOST_TEST_SUITE("extended_p_square_quantile test");
97
98 test->add(BOOST_TEST_CASE(&test_stat));
99
100 return test;
101 }
102